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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/builtin_sources.gypi ('k') | runtime/bin/thread_pool.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_
OLDNEW
« 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