| 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 RUNTIME_BIN_THREAD_H_ | 5 #ifndef RUNTIME_BIN_THREAD_H_ |
| 6 #define RUNTIME_BIN_THREAD_H_ | 6 #define RUNTIME_BIN_THREAD_H_ |
| 7 | 7 |
| 8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| 11 namespace bin { | 11 namespace bin { |
| 12 class Thread; | 12 class Thread; |
| 13 class Mutex; | 13 class Mutex; |
| 14 class Monitor; | 14 class Monitor; |
| 15 } | 15 } // namespace bin |
| 16 } | 16 } // namespace dart |
| 17 | 17 |
| 18 // Declare the OS-specific types ahead of defining the generic classes. | 18 // Declare the OS-specific types ahead of defining the generic classes. |
| 19 #if defined(HOST_OS_ANDROID) | 19 #if defined(HOST_OS_ANDROID) |
| 20 #include "bin/thread_android.h" | 20 #include "bin/thread_android.h" |
| 21 #elif defined(HOST_OS_FUCHSIA) | 21 #elif defined(HOST_OS_FUCHSIA) |
| 22 #include "bin/thread_fuchsia.h" | 22 #include "bin/thread_fuchsia.h" |
| 23 #elif defined(HOST_OS_LINUX) | 23 #elif defined(HOST_OS_LINUX) |
| 24 #include "bin/thread_linux.h" | 24 #include "bin/thread_linux.h" |
| 25 #elif defined(HOST_OS_MACOS) | 25 #elif defined(HOST_OS_MACOS) |
| 26 #include "bin/thread_macos.h" | 26 #include "bin/thread_macos.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 56 static intptr_t ThreadIdToIntPtr(ThreadId id); | 56 static intptr_t ThreadIdToIntPtr(ThreadId id); |
| 57 static bool Compare(ThreadId a, ThreadId b); | 57 static bool Compare(ThreadId a, ThreadId b); |
| 58 | 58 |
| 59 static void InitOnce(); | 59 static void InitOnce(); |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 DISALLOW_ALLOCATION(); | 62 DISALLOW_ALLOCATION(); |
| 63 DISALLOW_IMPLICIT_CONSTRUCTORS(Thread); | 63 DISALLOW_IMPLICIT_CONSTRUCTORS(Thread); |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 | |
| 67 class Mutex { | 66 class Mutex { |
| 68 public: | 67 public: |
| 69 Mutex(); | 68 Mutex(); |
| 70 ~Mutex(); | 69 ~Mutex(); |
| 71 | 70 |
| 72 void Lock(); | 71 void Lock(); |
| 73 bool TryLock(); | 72 bool TryLock(); |
| 74 void Unlock(); | 73 void Unlock(); |
| 75 | 74 |
| 76 private: | 75 private: |
| 77 MutexData data_; | 76 MutexData data_; |
| 78 | 77 |
| 79 DISALLOW_COPY_AND_ASSIGN(Mutex); | 78 DISALLOW_COPY_AND_ASSIGN(Mutex); |
| 80 }; | 79 }; |
| 81 | 80 |
| 82 | |
| 83 class Monitor { | 81 class Monitor { |
| 84 public: | 82 public: |
| 85 enum WaitResult { kNotified, kTimedOut }; | 83 enum WaitResult { kNotified, kTimedOut }; |
| 86 | 84 |
| 87 static const int64_t kNoTimeout = 0; | 85 static const int64_t kNoTimeout = 0; |
| 88 | 86 |
| 89 Monitor(); | 87 Monitor(); |
| 90 ~Monitor(); | 88 ~Monitor(); |
| 91 | 89 |
| 92 void Enter(); | 90 void Enter(); |
| 93 void Exit(); | 91 void Exit(); |
| 94 | 92 |
| 95 // Wait for notification or timeout. | 93 // Wait for notification or timeout. |
| 96 WaitResult Wait(int64_t millis); | 94 WaitResult Wait(int64_t millis); |
| 97 WaitResult WaitMicros(int64_t micros); | 95 WaitResult WaitMicros(int64_t micros); |
| 98 | 96 |
| 99 // Notify waiting threads. | 97 // Notify waiting threads. |
| 100 void Notify(); | 98 void Notify(); |
| 101 void NotifyAll(); | 99 void NotifyAll(); |
| 102 | 100 |
| 103 private: | 101 private: |
| 104 MonitorData data_; // OS-specific data. | 102 MonitorData data_; // OS-specific data. |
| 105 | 103 |
| 106 DISALLOW_COPY_AND_ASSIGN(Monitor); | 104 DISALLOW_COPY_AND_ASSIGN(Monitor); |
| 107 }; | 105 }; |
| 108 | 106 |
| 109 } // namespace bin | 107 } // namespace bin |
| 110 } // namespace dart | 108 } // namespace dart |
| 111 | 109 |
| 112 | |
| 113 #endif // RUNTIME_BIN_THREAD_H_ | 110 #endif // RUNTIME_BIN_THREAD_H_ |
| OLD | NEW |