OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MOJO_DART_EMBEDDER_DART_DEBUGGER_H_ | 5 #ifndef TONIC_DART_DEBUGGER_H_ |
6 #define MOJO_DART_EMBEDDER_DART_DEBUGGER_H_ | 6 #define TONIC_DART_DEBUGGER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
| 11 #include "base/synchronization/condition_variable.h" |
| 12 #include "base/synchronization/lock.h" |
11 #include "dart/runtime/include/dart_api.h" | 13 #include "dart/runtime/include/dart_api.h" |
12 #include "dart/runtime/include/dart_native_api.h" | 14 #include "dart/runtime/include/dart_native_api.h" |
13 #include "dart/runtime/include/dart_tools_api.h" | 15 #include "dart/runtime/include/dart_tools_api.h" |
14 #include "mojo/dart/embedder/monitor.h" | |
15 | 16 |
16 namespace base { | 17 namespace base { |
17 class Lock; | 18 class Lock; |
18 } | 19 } |
19 | 20 |
20 namespace mojo { | 21 namespace tonic { |
21 namespace dart { | 22 |
| 23 class Monitor { |
| 24 public: |
| 25 Monitor() { |
| 26 lock_ = new base::Lock(); |
| 27 condition_variable_ = new base::ConditionVariable(lock_); |
| 28 } |
| 29 |
| 30 ~Monitor() { |
| 31 delete condition_variable_; |
| 32 delete lock_; |
| 33 } |
| 34 |
| 35 void Enter() { |
| 36 lock_->Acquire(); |
| 37 } |
| 38 |
| 39 void Exit() { |
| 40 lock_->Release(); |
| 41 } |
| 42 |
| 43 void Notify() { |
| 44 condition_variable_->Signal(); |
| 45 } |
| 46 |
| 47 void Wait() { |
| 48 condition_variable_->Wait(); |
| 49 } |
| 50 |
| 51 private: |
| 52 base::Lock* lock_; |
| 53 base::ConditionVariable* condition_variable_; |
| 54 DISALLOW_COPY_AND_ASSIGN(Monitor); |
| 55 }; |
| 56 |
| 57 class MonitorLocker { |
| 58 public: |
| 59 explicit MonitorLocker(Monitor* monitor) : monitor_(monitor) { |
| 60 CHECK(monitor_); |
| 61 monitor_->Enter(); |
| 62 } |
| 63 |
| 64 virtual ~MonitorLocker(); |
| 65 |
| 66 void Wait() { |
| 67 return monitor_->Wait(); |
| 68 } |
| 69 |
| 70 void Notify() { |
| 71 monitor_->Notify(); |
| 72 } |
| 73 |
| 74 private: |
| 75 Monitor* const monitor_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(MonitorLocker); |
| 78 }; |
22 | 79 |
23 class DartDebuggerIsolate { | 80 class DartDebuggerIsolate { |
24 public: | 81 public: |
25 DartDebuggerIsolate(Dart_IsolateId id) | 82 DartDebuggerIsolate(Dart_IsolateId id) |
26 : id_(id) { | 83 : id_(id) { |
27 } | 84 } |
28 | 85 |
29 Dart_IsolateId id() const { | 86 Dart_IsolateId id() const { |
30 return id_; | 87 return id_; |
31 } | 88 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 static void AddIsolate(Dart_IsolateId id); | 127 static void AddIsolate(Dart_IsolateId id); |
71 | 128 |
72 static void RemoveIsolate(Dart_IsolateId id); | 129 static void RemoveIsolate(Dart_IsolateId id); |
73 | 130 |
74 static base::Lock* lock_; | 131 static base::Lock* lock_; |
75 static std::vector<std::unique_ptr<DartDebuggerIsolate>>* isolates_; | 132 static std::vector<std::unique_ptr<DartDebuggerIsolate>>* isolates_; |
76 | 133 |
77 friend class DartDebuggerIsolate; | 134 friend class DartDebuggerIsolate; |
78 }; | 135 }; |
79 | 136 |
80 } // namespace dart | 137 } // namespace tonic |
81 } // namespace mojo | |
82 | 138 |
83 #endif // MOJO_DART_EMBEDDER_DART_DEBUGGER_H_ | 139 #endif // TONIC_DART_DEBUGGER_H_ |
OLD | NEW |