OLD | NEW |
(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 PLATFORM_THREAD_H_ |
| 6 #define PLATFORM_THREAD_H_ |
| 7 |
| 8 #include "platform/globals.h" |
| 9 |
| 10 // Declare the OS-specific types ahead of defining the generic classes. |
| 11 #if defined(TARGET_OS_LINUX) |
| 12 #include "platform/thread_linux.h" |
| 13 #elif defined(TARGET_OS_MACOS) |
| 14 #include "platform/thread_macos.h" |
| 15 #elif defined(TARGET_OS_WINDOWS) |
| 16 #include "platform/thread_win.h" |
| 17 #else |
| 18 #error Unknown target os. |
| 19 #endif |
| 20 |
| 21 namespace dart { |
| 22 |
| 23 class Thread { |
| 24 public: |
| 25 // Function to be called on thread start. |
| 26 typedef void (*ThreadStartFunction) (uword parameter); |
| 27 |
| 28 // TODO(iposva): Define the proper interface for spawning and killing threads. |
| 29 Thread(ThreadStartFunction function, uword parameters); |
| 30 ~Thread(); |
| 31 |
| 32 private: |
| 33 ThreadData data_; |
| 34 |
| 35 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 36 }; |
| 37 |
| 38 |
| 39 class Mutex { |
| 40 public: |
| 41 Mutex(); |
| 42 ~Mutex(); |
| 43 |
| 44 void Lock(); |
| 45 bool TryLock(); |
| 46 void Unlock(); |
| 47 |
| 48 private: |
| 49 MutexData data_; |
| 50 |
| 51 DISALLOW_COPY_AND_ASSIGN(Mutex); |
| 52 }; |
| 53 |
| 54 |
| 55 class Monitor { |
| 56 public: |
| 57 enum WaitResult { |
| 58 kNotified, |
| 59 kTimedOut |
| 60 }; |
| 61 |
| 62 static const int64_t kNoTimeout = 0; |
| 63 |
| 64 Monitor(); |
| 65 ~Monitor(); |
| 66 |
| 67 void Enter(); |
| 68 void Exit(); |
| 69 |
| 70 // Wait for notification or timeout. |
| 71 WaitResult Wait(int64_t millis); |
| 72 |
| 73 // Notify waiting threads. |
| 74 void Notify(); |
| 75 void NotifyAll(); |
| 76 |
| 77 private: |
| 78 MonitorData data_; // OS-specific data. |
| 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(Monitor); |
| 81 }; |
| 82 |
| 83 } // namespace dart |
| 84 |
| 85 |
| 86 #endif // PLATFORM_THREAD_H_ |
OLD | NEW |