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 PLATFORM_THREAD_H_ | 5 #ifndef PLATFORM_THREAD_H_ |
6 #define PLATFORM_THREAD_H_ | 6 #define PLATFORM_THREAD_H_ |
7 | 7 |
8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
9 | 9 |
10 // Declare the OS-specific types ahead of defining the generic classes. | 10 // Declare the OS-specific types ahead of defining the generic classes. |
(...skipping 22 matching lines...) Expand all Loading... |
33 // the thread failed to start. | 33 // the thread failed to start. |
34 static int Start(ThreadStartFunction function, uword parameters); | 34 static int Start(ThreadStartFunction function, uword parameters); |
35 | 35 |
36 static ThreadLocalKey CreateThreadLocal(); | 36 static ThreadLocalKey CreateThreadLocal(); |
37 static void DeleteThreadLocal(ThreadLocalKey key); | 37 static void DeleteThreadLocal(ThreadLocalKey key); |
38 static uword GetThreadLocal(ThreadLocalKey key) { | 38 static uword GetThreadLocal(ThreadLocalKey key) { |
39 return ThreadInlineImpl::GetThreadLocal(key); | 39 return ThreadInlineImpl::GetThreadLocal(key); |
40 } | 40 } |
41 static void SetThreadLocal(ThreadLocalKey key, uword value); | 41 static void SetThreadLocal(ThreadLocalKey key, uword value); |
42 static intptr_t GetMaxStackSize(); | 42 static intptr_t GetMaxStackSize(); |
| 43 static ThreadId GetCurrentThreadId(); |
| 44 static void GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage); |
43 }; | 45 }; |
44 | 46 |
45 | 47 |
46 class Mutex { | 48 class Mutex { |
47 public: | 49 public: |
48 Mutex(); | 50 Mutex(); |
49 ~Mutex(); | 51 ~Mutex(); |
50 | 52 |
51 void Lock(); | 53 void Lock(); |
52 bool TryLock(); | 54 bool TryLock(); |
(...skipping 16 matching lines...) Expand all Loading... |
69 static const int64_t kNoTimeout = 0; | 71 static const int64_t kNoTimeout = 0; |
70 | 72 |
71 Monitor(); | 73 Monitor(); |
72 ~Monitor(); | 74 ~Monitor(); |
73 | 75 |
74 void Enter(); | 76 void Enter(); |
75 void Exit(); | 77 void Exit(); |
76 | 78 |
77 // Wait for notification or timeout. | 79 // Wait for notification or timeout. |
78 WaitResult Wait(int64_t millis); | 80 WaitResult Wait(int64_t millis); |
| 81 WaitResult WaitMicros(int64_t micros); |
79 | 82 |
80 // Notify waiting threads. | 83 // Notify waiting threads. |
81 void Notify(); | 84 void Notify(); |
82 void NotifyAll(); | 85 void NotifyAll(); |
83 | 86 |
84 private: | 87 private: |
85 MonitorData data_; // OS-specific data. | 88 MonitorData data_; // OS-specific data. |
86 | 89 |
87 DISALLOW_COPY_AND_ASSIGN(Monitor); | 90 DISALLOW_COPY_AND_ASSIGN(Monitor); |
88 }; | 91 }; |
89 | 92 |
| 93 |
| 94 class ScopedMutex { |
| 95 public: |
| 96 explicit ScopedMutex(Mutex* mutex) : mutex_(mutex) { |
| 97 ASSERT(mutex_ != NULL); |
| 98 mutex_->Lock(); |
| 99 } |
| 100 |
| 101 ~ScopedMutex() { |
| 102 mutex_->Unlock(); |
| 103 } |
| 104 |
| 105 private: |
| 106 Mutex* const mutex_; |
| 107 |
| 108 DISALLOW_COPY_AND_ASSIGN(ScopedMutex); |
| 109 }; |
| 110 |
| 111 |
| 112 class ScopedMonitor { |
| 113 public: |
| 114 explicit ScopedMonitor(Monitor* monitor) : monitor_(monitor) { |
| 115 ASSERT(monitor_ != NULL); |
| 116 monitor_->Enter(); |
| 117 } |
| 118 |
| 119 ~ScopedMonitor() { |
| 120 monitor_->Exit(); |
| 121 } |
| 122 |
| 123 Monitor::WaitResult Wait(int64_t millis = dart::Monitor::kNoTimeout) { |
| 124 return monitor_->Wait(millis); |
| 125 } |
| 126 |
| 127 Monitor::WaitResult WaitMicros(int64_t micros = dart::Monitor::kNoTimeout) { |
| 128 return monitor_->WaitMicros(micros); |
| 129 } |
| 130 |
| 131 void Notify() { |
| 132 monitor_->Notify(); |
| 133 } |
| 134 |
| 135 void NotifyAll() { |
| 136 monitor_->NotifyAll(); |
| 137 } |
| 138 |
| 139 private: |
| 140 Monitor* const monitor_; |
| 141 |
| 142 DISALLOW_COPY_AND_ASSIGN(ScopedMonitor); |
| 143 }; |
| 144 |
| 145 |
90 } // namespace dart | 146 } // namespace dart |
91 | 147 |
92 | 148 |
93 #endif // PLATFORM_THREAD_H_ | 149 #endif // PLATFORM_THREAD_H_ |
OLD | NEW |