| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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_THREAD_H_ | 5 #ifndef VM_THREAD_H_ |
| 6 #define VM_THREAD_H_ | 6 #define VM_THREAD_H_ |
| 7 | 7 |
| 8 #include "vm/globals.h" | 8 #include "vm/globals.h" |
| 9 #include "vm/handles.h" | 9 #include "vm/handles.h" |
| 10 #include "vm/os_thread.h" | 10 #include "vm/os_thread.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 146 |
| 147 #if defined(TARGET_OS_WINDOWS) | 147 #if defined(TARGET_OS_WINDOWS) |
| 148 // Clears the state of the current thread and frees the allocation. | 148 // Clears the state of the current thread and frees the allocation. |
| 149 static void CleanUp(); | 149 static void CleanUp(); |
| 150 #endif | 150 #endif |
| 151 | 151 |
| 152 // Called at VM startup. | 152 // Called at VM startup. |
| 153 static void InitOnceBeforeIsolate(); | 153 static void InitOnceBeforeIsolate(); |
| 154 static void InitOnceAfterObjectAndStubCode(); | 154 static void InitOnceAfterObjectAndStubCode(); |
| 155 | 155 |
| 156 // Called at VM shutdown |
| 157 static void Shutdown(); |
| 156 ~Thread(); | 158 ~Thread(); |
| 157 | 159 |
| 158 // The topmost zone used for allocation in this thread. | 160 // The topmost zone used for allocation in this thread. |
| 159 Zone* zone() const { return state_.zone; } | 161 Zone* zone() const { return state_.zone; } |
| 160 | 162 |
| 161 // The isolate that this thread is operating on, or NULL if none. | 163 // The isolate that this thread is operating on, or NULL if none. |
| 162 Isolate* isolate() const { return isolate_; } | 164 Isolate* isolate() const { return isolate_; } |
| 163 static intptr_t isolate_offset() { | 165 static intptr_t isolate_offset() { |
| 164 return OFFSET_OF(Thread, isolate_); | 166 return OFFSET_OF(Thread, isolate_); |
| 165 } | 167 } |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 408 |
| 407 #if defined(DEBUG) | 409 #if defined(DEBUG) |
| 408 #define REUSABLE_HANDLE_SCOPE_VARIABLE(object) \ | 410 #define REUSABLE_HANDLE_SCOPE_VARIABLE(object) \ |
| 409 bool reusable_##object##_handle_scope_active_; | 411 bool reusable_##object##_handle_scope_active_; |
| 410 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_VARIABLE); | 412 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_VARIABLE); |
| 411 #undef REUSABLE_HANDLE_SCOPE_VARIABLE | 413 #undef REUSABLE_HANDLE_SCOPE_VARIABLE |
| 412 #endif // defined(DEBUG) | 414 #endif // defined(DEBUG) |
| 413 | 415 |
| 414 VMHandles reusable_handles_; | 416 VMHandles reusable_handles_; |
| 415 | 417 |
| 418 // All |Thread|s are registered in the thread list. |
| 419 Thread* thread_list_next_; |
| 420 |
| 421 static Thread* thread_list_head_; |
| 422 static Mutex* thread_list_lock_; |
| 423 |
| 424 static void AddThreadToList(Thread* thread); |
| 425 static void RemoveThreadFromList(Thread* thread); |
| 426 |
| 416 explicit Thread(bool init_vm_constants = true); | 427 explicit Thread(bool init_vm_constants = true); |
| 417 | 428 |
| 418 void InitVMConstants(); | 429 void InitVMConstants(); |
| 419 | 430 |
| 420 void ClearState() { | 431 void ClearState() { |
| 421 memset(&state_, 0, sizeof(state_)); | 432 memset(&state_, 0, sizeof(state_)); |
| 422 } | 433 } |
| 423 | 434 |
| 424 void StoreBufferRelease( | 435 void StoreBufferRelease( |
| 425 StoreBuffer::ThresholdPolicy policy = StoreBuffer::kCheckThreshold); | 436 StoreBuffer::ThresholdPolicy policy = StoreBuffer::kCheckThreshold); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 439 void Unschedule(bool bypass_safepoint = false); | 450 void Unschedule(bool bypass_safepoint = false); |
| 440 | 451 |
| 441 #define REUSABLE_FRIEND_DECLARATION(name) \ | 452 #define REUSABLE_FRIEND_DECLARATION(name) \ |
| 442 friend class Reusable##name##HandleScope; | 453 friend class Reusable##name##HandleScope; |
| 443 REUSABLE_HANDLE_LIST(REUSABLE_FRIEND_DECLARATION) | 454 REUSABLE_HANDLE_LIST(REUSABLE_FRIEND_DECLARATION) |
| 444 #undef REUSABLE_FRIEND_DECLARATION | 455 #undef REUSABLE_FRIEND_DECLARATION |
| 445 | 456 |
| 446 friend class ApiZone; | 457 friend class ApiZone; |
| 447 friend class Isolate; | 458 friend class Isolate; |
| 448 friend class StackZone; | 459 friend class StackZone; |
| 460 friend class ThreadIterator; |
| 461 friend class ThreadIteratorTestHelper; |
| 449 friend class ThreadRegistry; | 462 friend class ThreadRegistry; |
| 463 |
| 450 DISALLOW_COPY_AND_ASSIGN(Thread); | 464 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 451 }; | 465 }; |
| 452 | 466 |
| 467 |
| 468 // Note that this takes the thread list lock, prohibiting threads from coming |
| 469 // on- or off-line. |
| 470 class ThreadIterator : public ValueObject { |
| 471 public: |
| 472 ThreadIterator(); |
| 473 ~ThreadIterator(); |
| 474 |
| 475 // Returns false when there are no more threads left. |
| 476 bool HasNext() const; |
| 477 |
| 478 // Returns the current thread and moves forward. |
| 479 Thread* Next(); |
| 480 |
| 481 private: |
| 482 Thread* next_; |
| 483 }; |
| 484 |
| 453 } // namespace dart | 485 } // namespace dart |
| 454 | 486 |
| 455 #endif // VM_THREAD_H_ | 487 #endif // VM_THREAD_H_ |
| OLD | NEW |