| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef RUNTIME_VM_THREAD_H_ | 5 #ifndef VM_THREAD_H_ |
| 6 #define RUNTIME_VM_THREAD_H_ | 6 #define VM_THREAD_H_ |
| 7 | 7 |
| 8 #include "vm/assert.h" | 8 #include "vm/assert.h" |
| 9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
| 11 | 11 |
| 12 // Declare the OS-specific types ahead of defining the generic classes. | 12 // Declare the OS-specific types ahead of defining the generic classes. |
| 13 #if defined(TARGET_OS_LINUX) | 13 #if defined(TARGET_OS_LINUX) |
| 14 #include "vm/thread_linux.h" | 14 #include "vm/thread_linux.h" |
| 15 #elif defined(TARGET_OS_MACOS) | 15 #elif defined(TARGET_OS_MACOS) |
| 16 #include "vm/thread_macos.h" | 16 #include "vm/thread_macos.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 static const int64_t kNoTimeout = 0; | 64 static const int64_t kNoTimeout = 0; |
| 65 | 65 |
| 66 Monitor(); | 66 Monitor(); |
| 67 ~Monitor(); | 67 ~Monitor(); |
| 68 | 68 |
| 69 void Enter(); | 69 void Enter(); |
| 70 void Exit(); | 70 void Exit(); |
| 71 | 71 |
| 72 // Wait for notification or timeout. | 72 // Wait for notification or timeout. |
| 73 // May return too early due to spurious wakeups. Callers should test for this. | |
| 74 WaitResult Wait(int64_t millis); | 73 WaitResult Wait(int64_t millis); |
| 75 | 74 |
| 76 // Notify waiting threads. | 75 // Notify waiting threads. |
| 77 void Notify(); | 76 void Notify(); |
| 78 void NotifyAll(); | 77 void NotifyAll(); |
| 79 | 78 |
| 80 private: | 79 private: |
| 81 MonitorData data_; // OS-specific data. | 80 MonitorData data_; // OS-specific data. |
| 82 | 81 |
| 83 DISALLOW_COPY_AND_ASSIGN(Monitor); | 82 DISALLOW_COPY_AND_ASSIGN(Monitor); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 112 ASSERT(monitor != NULL); | 111 ASSERT(monitor != NULL); |
| 113 // TODO(iposva): Consider adding a no GC scope here. | 112 // TODO(iposva): Consider adding a no GC scope here. |
| 114 monitor_->Enter(); | 113 monitor_->Enter(); |
| 115 } | 114 } |
| 116 | 115 |
| 117 virtual ~MonitorLocker() { | 116 virtual ~MonitorLocker() { |
| 118 monitor_->Exit(); | 117 monitor_->Exit(); |
| 119 // TODO(iposva): Consider decrementing the no GC scope here. | 118 // TODO(iposva): Consider decrementing the no GC scope here. |
| 120 } | 119 } |
| 121 | 120 |
| 122 // May return too early due to spurious wakeups. Callers should test for this. | |
| 123 Monitor::WaitResult Wait(int64_t millis = Monitor::kNoTimeout) { | 121 Monitor::WaitResult Wait(int64_t millis = Monitor::kNoTimeout) { |
| 124 return monitor_->Wait(millis); | 122 return monitor_->Wait(millis); |
| 125 } | 123 } |
| 126 | 124 |
| 127 void Notify() { | 125 void Notify() { |
| 128 monitor_->Notify(); | 126 monitor_->Notify(); |
| 129 } | 127 } |
| 130 | 128 |
| 131 void NotifyAll() { | 129 void NotifyAll() { |
| 132 monitor_->NotifyAll(); | 130 monitor_->NotifyAll(); |
| 133 } | 131 } |
| 134 | 132 |
| 135 private: | 133 private: |
| 136 Monitor* const monitor_; | 134 Monitor* const monitor_; |
| 137 | 135 |
| 138 DISALLOW_COPY_AND_ASSIGN(MonitorLocker); | 136 DISALLOW_COPY_AND_ASSIGN(MonitorLocker); |
| 139 }; | 137 }; |
| 140 | 138 |
| 141 } // namespace dart | 139 } // namespace dart |
| 142 | 140 |
| 143 | 141 |
| 144 #endif // RUNTIME_VM_THREAD_H_ | 142 #endif // VM_THREAD_H_ |
| OLD | NEW |