| 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_VM_OS_THREAD_H_ | 5 #ifndef RUNTIME_VM_OS_THREAD_H_ |
| 6 #define RUNTIME_VM_OS_THREAD_H_ | 6 #define RUNTIME_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 30 matching lines...) Expand all Loading... |
| 41 ~BaseThread() {} | 41 ~BaseThread() {} |
| 42 | 42 |
| 43 bool is_os_thread_; | 43 bool is_os_thread_; |
| 44 | 44 |
| 45 friend class Thread; | 45 friend class Thread; |
| 46 friend class OSThread; | 46 friend class OSThread; |
| 47 | 47 |
| 48 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseThread); | 48 DISALLOW_IMPLICIT_CONSTRUCTORS(BaseThread); |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 | |
| 52 // Low-level operations on OS platform threads. | 51 // Low-level operations on OS platform threads. |
| 53 class OSThread : public BaseThread { | 52 class OSThread : public BaseThread { |
| 54 public: | 53 public: |
| 55 // The constructor of OSThread is never called directly, instead we call | 54 // The constructor of OSThread is never called directly, instead we call |
| 56 // this factory style method 'CreateOSThread' to create OSThread structures. | 55 // this factory style method 'CreateOSThread' to create OSThread structures. |
| 57 // The method can return a NULL if the Dart VM is in shutdown mode. | 56 // The method can return a NULL if the Dart VM is in shutdown mode. |
| 58 static OSThread* CreateOSThread(); | 57 static OSThread* CreateOSThread(); |
| 59 ~OSThread(); | 58 ~OSThread(); |
| 60 | 59 |
| 61 ThreadId id() const { | 60 ThreadId id() const { |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 static Mutex* thread_list_lock_; | 247 static Mutex* thread_list_lock_; |
| 249 static OSThread* thread_list_head_; | 248 static OSThread* thread_list_head_; |
| 250 static bool creation_enabled_; | 249 static bool creation_enabled_; |
| 251 | 250 |
| 252 friend class Isolate; // to access set_thread(Thread*). | 251 friend class Isolate; // to access set_thread(Thread*). |
| 253 friend class OSThreadIterator; | 252 friend class OSThreadIterator; |
| 254 friend class ThreadInterrupterWin; | 253 friend class ThreadInterrupterWin; |
| 255 friend class ThreadInterrupterFuchsia; | 254 friend class ThreadInterrupterFuchsia; |
| 256 }; | 255 }; |
| 257 | 256 |
| 258 | |
| 259 // Note that this takes the thread list lock, prohibiting threads from coming | 257 // Note that this takes the thread list lock, prohibiting threads from coming |
| 260 // on- or off-line. | 258 // on- or off-line. |
| 261 class OSThreadIterator : public ValueObject { | 259 class OSThreadIterator : public ValueObject { |
| 262 public: | 260 public: |
| 263 OSThreadIterator(); | 261 OSThreadIterator(); |
| 264 ~OSThreadIterator(); | 262 ~OSThreadIterator(); |
| 265 | 263 |
| 266 // Returns false when there are no more threads left. | 264 // Returns false when there are no more threads left. |
| 267 bool HasNext() const; | 265 bool HasNext() const; |
| 268 | 266 |
| 269 // Returns the current thread and moves forward. | 267 // Returns the current thread and moves forward. |
| 270 OSThread* Next(); | 268 OSThread* Next(); |
| 271 | 269 |
| 272 private: | 270 private: |
| 273 OSThread* next_; | 271 OSThread* next_; |
| 274 }; | 272 }; |
| 275 | 273 |
| 276 | |
| 277 class Mutex { | 274 class Mutex { |
| 278 public: | 275 public: |
| 279 Mutex(); | 276 Mutex(); |
| 280 ~Mutex(); | 277 ~Mutex(); |
| 281 | 278 |
| 282 #if defined(DEBUG) | 279 #if defined(DEBUG) |
| 283 bool IsOwnedByCurrentThread() const { | 280 bool IsOwnedByCurrentThread() const { |
| 284 return owner_ == OSThread::GetCurrentThreadId(); | 281 return owner_ == OSThread::GetCurrentThreadId(); |
| 285 } | 282 } |
| 286 #else | 283 #else |
| (...skipping 17 matching lines...) Expand all Loading... |
| 304 friend class MutexLocker; | 301 friend class MutexLocker; |
| 305 friend class SafepointMutexLocker; | 302 friend class SafepointMutexLocker; |
| 306 friend class OSThreadIterator; | 303 friend class OSThreadIterator; |
| 307 friend class TimelineEventBlockIterator; | 304 friend class TimelineEventBlockIterator; |
| 308 friend class TimelineEventRecorder; | 305 friend class TimelineEventRecorder; |
| 309 friend class PageSpace; | 306 friend class PageSpace; |
| 310 friend void Dart_TestMutex(); | 307 friend void Dart_TestMutex(); |
| 311 DISALLOW_COPY_AND_ASSIGN(Mutex); | 308 DISALLOW_COPY_AND_ASSIGN(Mutex); |
| 312 }; | 309 }; |
| 313 | 310 |
| 314 | |
| 315 class Monitor { | 311 class Monitor { |
| 316 public: | 312 public: |
| 317 enum WaitResult { kNotified, kTimedOut }; | 313 enum WaitResult { kNotified, kTimedOut }; |
| 318 | 314 |
| 319 static const int64_t kNoTimeout = 0; | 315 static const int64_t kNoTimeout = 0; |
| 320 | 316 |
| 321 Monitor(); | 317 Monitor(); |
| 322 ~Monitor(); | 318 ~Monitor(); |
| 323 | 319 |
| 324 #if defined(DEBUG) | 320 #if defined(DEBUG) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 349 #if defined(DEBUG) | 345 #if defined(DEBUG) |
| 350 ThreadId owner_; | 346 ThreadId owner_; |
| 351 #endif // defined(DEBUG) | 347 #endif // defined(DEBUG) |
| 352 | 348 |
| 353 friend class MonitorLocker; | 349 friend class MonitorLocker; |
| 354 friend class SafepointMonitorLocker; | 350 friend class SafepointMonitorLocker; |
| 355 friend void Dart_TestMonitor(); | 351 friend void Dart_TestMonitor(); |
| 356 DISALLOW_COPY_AND_ASSIGN(Monitor); | 352 DISALLOW_COPY_AND_ASSIGN(Monitor); |
| 357 }; | 353 }; |
| 358 | 354 |
| 359 | |
| 360 } // namespace dart | 355 } // namespace dart |
| 361 | 356 |
| 362 | |
| 363 #endif // RUNTIME_VM_OS_THREAD_H_ | 357 #endif // RUNTIME_VM_OS_THREAD_H_ |
| OLD | NEW |