| 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/base_isolate.h" | 8 #include "vm/base_isolate.h" |
| 9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
| 10 #include "vm/os_thread.h" | 10 #include "vm/os_thread.h" |
| 11 | 11 |
| 12 namespace dart { | 12 namespace dart { |
| 13 | 13 |
| 14 class CHA; | 14 class CHA; |
| 15 class Isolate; | 15 class Isolate; |
| 16 | 16 |
| 17 // A VM thread; may be executing Dart code or performing helper tasks like | 17 // A VM thread; may be executing Dart code or performing helper tasks like |
| 18 // garbage collection or compilation. | 18 // garbage collection or compilation. The Thread structure associated with |
| 19 // a thread is allocated when the thread enters an isolate, and destroyed |
| 20 // upon exiting an isolate or an explicit call to CleanUp. |
| 19 class Thread { | 21 class Thread { |
| 20 public: | 22 public: |
| 21 explicit Thread(Isolate* isolate) | 23 // The currently executing thread, or NULL if not yet initialized. |
| 22 : isolate_(isolate), | |
| 23 cha_(NULL) {} | |
| 24 | |
| 25 static void InitOnce(); | |
| 26 | |
| 27 static Thread* Current() { | 24 static Thread* Current() { |
| 28 return reinterpret_cast<Thread*>(OSThread::GetThreadLocal(thread_key_)); | 25 return reinterpret_cast<Thread*>(OSThread::GetThreadLocal(thread_key_)); |
| 29 } | 26 } |
| 30 static void SetCurrent(Thread* current); | 27 |
| 28 // Makes the current thread enter 'isolate'. Also calls EnsureInit. |
| 29 static void EnterIsolate(Isolate* isolate); |
| 30 // Makes the current thread exit its isolate. Also calls CleanUp. |
| 31 static void ExitIsolate(); |
| 32 |
| 33 // Initializes the current thread as a VM thread, if not already done. |
| 34 static void EnsureInit(); |
| 35 // Clears the state of the current thread. |
| 36 static void CleanUp(); |
| 37 |
| 38 // Called at VM startup. |
| 39 static void InitOnce(); |
| 31 | 40 |
| 32 // The topmost zone used for allocation in this thread. | 41 // The topmost zone used for allocation in this thread. |
| 33 Zone* zone() { | 42 Zone* zone() { |
| 34 return reinterpret_cast<BaseIsolate*>(isolate())->current_zone(); | 43 return reinterpret_cast<BaseIsolate*>(isolate())->current_zone(); |
| 35 } | 44 } |
| 36 | 45 |
| 37 // The isolate that this thread is operating on, or NULL if none. | 46 // The isolate that this thread is operating on, or NULL if none. |
| 38 Isolate* isolate() const { return isolate_; } | 47 Isolate* isolate() const { return isolate_; } |
| 39 | 48 |
| 40 // The (topmost) CHA for the compilation in this thread. | 49 // The (topmost) CHA for the compilation in this thread. |
| 41 CHA* cha() const { return cha_; } | 50 CHA* cha() const { return cha_; } |
| 42 void set_cha(CHA* value) { cha_ = value; } | 51 void set_cha(CHA* value) { cha_ = value; } |
| 43 | 52 |
| 44 private: | 53 private: |
| 45 static ThreadLocalKey thread_key_; | 54 static ThreadLocalKey thread_key_; |
| 46 | 55 |
| 47 Isolate* isolate_; | 56 Isolate* isolate_; |
| 48 CHA* cha_; | 57 CHA* cha_; |
| 49 | 58 |
| 59 Thread() |
| 60 : isolate_(NULL), |
| 61 cha_(NULL) {} |
| 62 |
| 63 static void SetCurrent(Thread* current); |
| 64 |
| 50 DISALLOW_COPY_AND_ASSIGN(Thread); | 65 DISALLOW_COPY_AND_ASSIGN(Thread); |
| 51 }; | 66 }; |
| 52 | 67 |
| 53 } // namespace dart | 68 } // namespace dart |
| 54 | 69 |
| 55 #endif // VM_THREAD_H_ | 70 #endif // VM_THREAD_H_ |
| OLD | NEW |