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_OS_THREAD_H_ | 5 #ifndef VM_OS_THREAD_H_ |
6 #define VM_OS_THREAD_H_ | 6 #define VM_OS_THREAD_H_ |
7 | 7 |
8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 OSThread* next_; | 260 OSThread* next_; |
261 }; | 261 }; |
262 | 262 |
263 | 263 |
264 class Mutex { | 264 class Mutex { |
265 public: | 265 public: |
266 Mutex(); | 266 Mutex(); |
267 ~Mutex(); | 267 ~Mutex(); |
268 | 268 |
269 void Lock(); | 269 void Lock(); |
270 bool TryLock(); | 270 bool TryLock(); // Returns false if lock is busy and locking failed. |
271 void Unlock(); | 271 void Unlock(); |
272 | 272 |
273 #if defined(DEBUG) | 273 #if defined(DEBUG) |
274 bool IsOwnedByCurrentThread() const { | 274 bool IsOwnedByCurrentThread() const { |
275 return owner_ == OSThread::GetCurrentThreadId(); | 275 return owner_ == OSThread::GetCurrentThreadId(); |
276 } | 276 } |
277 #else | 277 #else |
278 bool IsOwnedByCurrentThread() const { | 278 bool IsOwnedByCurrentThread() const { |
279 UNREACHABLE(); | 279 UNREACHABLE(); |
280 return false; | 280 return false; |
(...skipping 15 matching lines...) Expand all Loading... |
296 enum WaitResult { | 296 enum WaitResult { |
297 kNotified, | 297 kNotified, |
298 kTimedOut | 298 kTimedOut |
299 }; | 299 }; |
300 | 300 |
301 static const int64_t kNoTimeout = 0; | 301 static const int64_t kNoTimeout = 0; |
302 | 302 |
303 Monitor(); | 303 Monitor(); |
304 ~Monitor(); | 304 ~Monitor(); |
305 | 305 |
| 306 bool TryEnter(); // Returns false if lock is busy and locking failed. |
306 void Enter(); | 307 void Enter(); |
307 void Exit(); | 308 void Exit(); |
308 | 309 |
309 // Wait for notification or timeout. | 310 // Wait for notification or timeout. |
310 WaitResult Wait(int64_t millis); | 311 WaitResult Wait(int64_t millis); |
311 WaitResult WaitMicros(int64_t micros); | 312 WaitResult WaitMicros(int64_t micros); |
312 | 313 |
313 // Notify waiting threads. | 314 // Notify waiting threads. |
314 void Notify(); | 315 void Notify(); |
315 void NotifyAll(); | 316 void NotifyAll(); |
(...skipping 16 matching lines...) Expand all Loading... |
332 #endif // defined(DEBUG) | 333 #endif // defined(DEBUG) |
333 | 334 |
334 DISALLOW_COPY_AND_ASSIGN(Monitor); | 335 DISALLOW_COPY_AND_ASSIGN(Monitor); |
335 }; | 336 }; |
336 | 337 |
337 | 338 |
338 } // namespace dart | 339 } // namespace dart |
339 | 340 |
340 | 341 |
341 #endif // VM_OS_THREAD_H_ | 342 #endif // VM_OS_THREAD_H_ |
OLD | NEW |