Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Unified Diff: runtime/bin/thread.h

Issue 9255012: Add MutexLocker and MonitorLocker to platform/bin (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/builtin_sources.gypi ('k') | runtime/bin/thread_pool.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/thread.h
diff --git a/runtime/bin/thread.h b/runtime/bin/thread.h
new file mode 100644
index 0000000000000000000000000000000000000000..a3c5a92e9c51cdacd4fb018deeb2062cd3a688cb
--- /dev/null
+++ b/runtime/bin/thread.h
@@ -0,0 +1,58 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+#ifndef BIN_THREAD_H_
+#define BIN_THREAD_H_
+
+#include "platform/assert.h"
+#include "platform/thread.h"
+
+class MutexLocker {
+ public:
+ explicit MutexLocker(dart::Mutex* mutex) : mutex_(mutex) {
+ ASSERT(mutex != NULL);
+ mutex_->Lock();
+ }
+
+ virtual ~MutexLocker() {
+ mutex_->Unlock();
+ }
+
+ private:
+ dart::Mutex* const mutex_;
+
+ DISALLOW_COPY_AND_ASSIGN(MutexLocker);
+};
+
+
+class MonitorLocker {
+ public:
+ explicit MonitorLocker(dart::Monitor* monitor) : monitor_(monitor) {
+ ASSERT(monitor != NULL);
+ monitor_->Enter();
+ }
+
+ virtual ~MonitorLocker() {
+ monitor_->Exit();
+ }
+
+ dart::Monitor::WaitResult Wait(int64_t millis = dart::Monitor::kNoTimeout) {
+ return monitor_->Wait(millis);
+ }
+
+ void Notify() {
+ monitor_->Notify();
+ }
+
+ void NotifyAll() {
+ monitor_->NotifyAll();
+ }
+
+ private:
+ dart::Monitor* const monitor_;
+
+ DISALLOW_COPY_AND_ASSIGN(MonitorLocker);
+};
+
+#endif // BIN_THREAD_H_
« no previous file with comments | « runtime/bin/builtin_sources.gypi ('k') | runtime/bin/thread_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698