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/isolate.h" | 8 #include "vm/isolate.h" |
9 | 9 |
10 namespace dart { | 10 namespace dart { |
11 | 11 |
12 // A VM thread; may be executing Dart code or performing helper tasks like | 12 // A VM thread; may be executing Dart code or performing helper tasks like |
13 // garbage collection. | 13 // garbage collection. |
14 class Thread { | 14 class Thread { |
15 public: | 15 public: |
16 static Thread* Current() { | 16 static Thread* Current() { |
17 // For now, there is still just one thread per isolate, and the Thread | 17 // For now, there is still just one thread per isolate, and the Thread |
18 // class just aliases the Isolate*. Once all interfaces and uses have been | 18 // class just aliases the Isolate*. Once all interfaces and uses have been |
19 // updated to distinguish between isolates and threads, Thread will get its | 19 // updated to distinguish between isolates and threads, Thread will get its |
20 // own thread-local storage key. | 20 // own thread-local storage key. |
21 return reinterpret_cast<Thread*>(Isolate::Current()); | 21 return reinterpret_cast<Thread*>(Isolate::Current()); |
22 } | 22 } |
| 23 // TODO(koda): Remove after pivoting to Thread* in native/runtime entries. |
| 24 static Thread* CurrentFromCurrentIsolate(BaseIsolate* isolate) { |
| 25 ASSERT(Isolate::Current() == isolate); |
| 26 return reinterpret_cast<Thread*>(isolate); |
| 27 } |
23 | 28 |
24 // The topmost zone used for allocation in this thread. | 29 // The topmost zone used for allocation in this thread. |
25 Zone* zone() { | 30 Zone* zone() { |
26 return reinterpret_cast<BaseIsolate*>(this)->current_zone(); | 31 return reinterpret_cast<BaseIsolate*>(this)->current_zone(); |
27 } | 32 } |
28 | 33 |
29 // The isolate that this thread is operating on. | 34 // The isolate that this thread is operating on. |
30 Isolate* isolate() { | 35 Isolate* isolate() { |
31 return reinterpret_cast<Isolate*>(this); | 36 return reinterpret_cast<Isolate*>(this); |
32 } | 37 } |
33 | 38 |
34 // The log for this thread. | 39 // The log for this thread. |
35 class Log* Log() { | 40 class Log* Log() { |
36 return reinterpret_cast<Isolate*>(this)->Log(); | 41 return reinterpret_cast<Isolate*>(this)->Log(); |
37 } | 42 } |
38 | 43 |
39 private: | 44 private: |
40 DISALLOW_COPY_AND_ASSIGN(Thread); | 45 DISALLOW_COPY_AND_ASSIGN(Thread); |
41 }; | 46 }; |
42 | 47 |
43 } // namespace dart | 48 } // namespace dart |
44 | 49 |
45 #endif // VM_THREAD_H_ | 50 #endif // VM_THREAD_H_ |
OLD | NEW |