| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 #ifndef BIN_THREAD_H_ |
| 6 #define BIN_THREAD_H_ |
| 7 |
| 8 #include "platform/assert.h" |
| 9 #include "platform/thread.h" |
| 10 |
| 11 class MutexLocker { |
| 12 public: |
| 13 explicit MutexLocker(dart::Mutex* mutex) : mutex_(mutex) { |
| 14 ASSERT(mutex != NULL); |
| 15 mutex_->Lock(); |
| 16 } |
| 17 |
| 18 virtual ~MutexLocker() { |
| 19 mutex_->Unlock(); |
| 20 } |
| 21 |
| 22 private: |
| 23 dart::Mutex* const mutex_; |
| 24 |
| 25 DISALLOW_COPY_AND_ASSIGN(MutexLocker); |
| 26 }; |
| 27 |
| 28 |
| 29 class MonitorLocker { |
| 30 public: |
| 31 explicit MonitorLocker(dart::Monitor* monitor) : monitor_(monitor) { |
| 32 ASSERT(monitor != NULL); |
| 33 monitor_->Enter(); |
| 34 } |
| 35 |
| 36 virtual ~MonitorLocker() { |
| 37 monitor_->Exit(); |
| 38 } |
| 39 |
| 40 dart::Monitor::WaitResult Wait(int64_t millis = dart::Monitor::kNoTimeout) { |
| 41 return monitor_->Wait(millis); |
| 42 } |
| 43 |
| 44 void Notify() { |
| 45 monitor_->Notify(); |
| 46 } |
| 47 |
| 48 void NotifyAll() { |
| 49 monitor_->NotifyAll(); |
| 50 } |
| 51 |
| 52 private: |
| 53 dart::Monitor* const monitor_; |
| 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(MonitorLocker); |
| 56 }; |
| 57 |
| 58 #endif // BIN_THREAD_H_ |
| OLD | NEW |