OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 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 | 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 VM_THREAD_H_ | 5 #ifndef VM_THREAD_H_ |
6 #define VM_THREAD_H_ | 6 #define VM_THREAD_H_ |
7 | 7 |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
| 9 #include "platform/thread.h" |
9 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
10 #include "vm/globals.h" | 11 #include "vm/globals.h" |
11 #include "vm/isolate.h" | 12 #include "vm/isolate.h" |
12 | 13 |
13 // Declare the OS-specific types ahead of defining the generic classes. | 14 // Declare the OS-specific types ahead of defining the generic classes. |
14 #if defined(TARGET_OS_LINUX) | 15 #if defined(TARGET_OS_LINUX) |
15 #include "vm/thread_linux.h" | 16 #include "vm/thread_linux.h" |
16 #elif defined(TARGET_OS_MACOS) | 17 #elif defined(TARGET_OS_MACOS) |
17 #include "vm/thread_macos.h" | 18 #include "vm/thread_macos.h" |
18 #elif defined(TARGET_OS_WINDOWS) | 19 #elif defined(TARGET_OS_WINDOWS) |
(...skipping 13 matching lines...) Expand all Loading... |
32 Thread(ThreadStartFunction function, uword parameters); | 33 Thread(ThreadStartFunction function, uword parameters); |
33 ~Thread(); | 34 ~Thread(); |
34 | 35 |
35 private: | 36 private: |
36 ThreadData data_; | 37 ThreadData data_; |
37 | 38 |
38 DISALLOW_COPY_AND_ASSIGN(Thread); | 39 DISALLOW_COPY_AND_ASSIGN(Thread); |
39 }; | 40 }; |
40 | 41 |
41 | 42 |
42 class Mutex { | |
43 public: | |
44 Mutex(); | |
45 ~Mutex(); | |
46 | |
47 void Lock(); | |
48 bool TryLock(); | |
49 void Unlock(); | |
50 | |
51 private: | |
52 MutexData data_; | |
53 | |
54 DISALLOW_COPY_AND_ASSIGN(Mutex); | |
55 }; | |
56 | |
57 | |
58 class Monitor { | |
59 public: | |
60 enum WaitResult { | |
61 kNotified, | |
62 kTimedOut | |
63 }; | |
64 | |
65 static const int64_t kNoTimeout = 0; | |
66 | |
67 Monitor(); | |
68 ~Monitor(); | |
69 | |
70 void Enter(); | |
71 void Exit(); | |
72 | |
73 // Wait for notification or timeout. | |
74 WaitResult Wait(int64_t millis); | |
75 | |
76 // Notify waiting threads. | |
77 void Notify(); | |
78 void NotifyAll(); | |
79 | |
80 private: | |
81 MonitorData data_; // OS-specific data. | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(Monitor); | |
84 }; | |
85 | |
86 | |
87 class MutexLocker : public StackResource { | 43 class MutexLocker : public StackResource { |
88 public: | 44 public: |
89 explicit MutexLocker(Mutex* mutex) : | 45 explicit MutexLocker(Mutex* mutex) : |
90 StackResource(Isolate::Current()), | 46 StackResource(Isolate::Current()), |
91 mutex_(mutex) { | 47 mutex_(mutex) { |
92 ASSERT(mutex != NULL); | 48 ASSERT(mutex != NULL); |
93 // TODO(iposva): Consider adding a no GC scope here. | 49 // TODO(iposva): Consider adding a no GC scope here. |
94 mutex_->Lock(); | 50 mutex_->Lock(); |
95 } | 51 } |
96 | 52 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 private: | 92 private: |
137 Monitor* const monitor_; | 93 Monitor* const monitor_; |
138 | 94 |
139 DISALLOW_COPY_AND_ASSIGN(MonitorLocker); | 95 DISALLOW_COPY_AND_ASSIGN(MonitorLocker); |
140 }; | 96 }; |
141 | 97 |
142 } // namespace dart | 98 } // namespace dart |
143 | 99 |
144 | 100 |
145 #endif // VM_THREAD_H_ | 101 #endif // VM_THREAD_H_ |
OLD | NEW |