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/os_thread.h" | 9 #include "vm/os_thread.h" |
10 #include "vm/store_buffer.h" | 10 #include "vm/store_buffer.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 V(RawBool*, bool_false_, Object::bool_false().raw(), NULL) \ | 32 V(RawBool*, bool_false_, Object::bool_false().raw(), NULL) \ |
33 | 33 |
34 #define CACHED_ADDRESSES_LIST(V) \ | 34 #define CACHED_ADDRESSES_LIST(V) \ |
35 V(uword, update_store_buffer_entry_point_, \ | 35 V(uword, update_store_buffer_entry_point_, \ |
36 StubCode::UpdateStoreBuffer_entry()->EntryPoint(), 0) | 36 StubCode::UpdateStoreBuffer_entry()->EntryPoint(), 0) |
37 | 37 |
38 #define CACHED_CONSTANTS_LIST(V) \ | 38 #define CACHED_CONSTANTS_LIST(V) \ |
39 CACHED_VM_OBJECTS_LIST(V) \ | 39 CACHED_VM_OBJECTS_LIST(V) \ |
40 CACHED_ADDRESSES_LIST(V) | 40 CACHED_ADDRESSES_LIST(V) |
41 | 41 |
| 42 struct InterruptedThreadState { |
| 43 ThreadId tid; |
| 44 uintptr_t pc; |
| 45 uintptr_t csp; |
| 46 uintptr_t dsp; |
| 47 uintptr_t fp; |
| 48 uintptr_t lr; |
| 49 }; |
| 50 |
| 51 // When a thread is interrupted the thread specific interrupt callback will be |
| 52 // invoked. Each callback is given an InterruptedThreadState and the user data |
| 53 // pointer. When inside a thread interrupt callback doing any of the following |
| 54 // is forbidden: |
| 55 // * Accessing TLS -- Because on Windows the callback will be running in a |
| 56 // different thread. |
| 57 // * Allocating memory -- Because this takes locks which may already be held, |
| 58 // resulting in a dead lock. |
| 59 // * Taking a lock -- See above. |
| 60 typedef void (*ThreadInterruptCallback)(const InterruptedThreadState& state, |
| 61 void* data); |
42 | 62 |
43 // A VM thread; may be executing Dart code or performing helper tasks like | 63 // A VM thread; may be executing Dart code or performing helper tasks like |
44 // garbage collection or compilation. The Thread structure associated with | 64 // garbage collection or compilation. The Thread structure associated with |
45 // a thread is allocated by EnsureInit before entering an isolate, and destroyed | 65 // a thread is allocated by EnsureInit before entering an isolate, and destroyed |
46 // automatically when the underlying OS thread exits. NOTE: On Windows, CleanUp | 66 // automatically when the underlying OS thread exits. NOTE: On Windows, CleanUp |
47 // must currently be called manually (issue 23474). | 67 // must currently be called manually (issue 23474). |
48 class Thread { | 68 class Thread { |
49 public: | 69 public: |
50 // The currently executing thread, or NULL if not yet initialized. | 70 // The currently executing thread, or NULL if not yet initialized. |
51 static Thread* Current() { | 71 static Thread* Current() { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 246 |
227 void set_timeline_block(TimelineEventBlock* block) { | 247 void set_timeline_block(TimelineEventBlock* block) { |
228 state_.timeline_block = block; | 248 state_.timeline_block = block; |
229 } | 249 } |
230 | 250 |
231 LongJumpScope* long_jump_base() const { return state_.long_jump_base; } | 251 LongJumpScope* long_jump_base() const { return state_.long_jump_base; } |
232 void set_long_jump_base(LongJumpScope* value) { | 252 void set_long_jump_base(LongJumpScope* value) { |
233 state_.long_jump_base = value; | 253 state_.long_jump_base = value; |
234 } | 254 } |
235 | 255 |
| 256 ThreadId id() const { |
| 257 ASSERT(id_ != OSThread::kInvalidThreadId); |
| 258 return id_; |
| 259 } |
| 260 |
| 261 void SetThreadInterrupter(ThreadInterruptCallback callback, void* data); |
| 262 |
| 263 bool IsThreadInterrupterEnabled(ThreadInterruptCallback* callback, |
| 264 void** data) const; |
| 265 |
236 private: | 266 private: |
237 static ThreadLocalKey thread_key_; | 267 static ThreadLocalKey thread_key_; |
238 | 268 |
| 269 const ThreadId id_; |
| 270 ThreadInterruptCallback thread_interrupt_callback_; |
| 271 void* thread_interrupt_data_; |
239 Isolate* isolate_; | 272 Isolate* isolate_; |
240 Heap* heap_; | 273 Heap* heap_; |
241 State state_; | 274 State state_; |
242 StoreBufferBlock* store_buffer_block_; | 275 StoreBufferBlock* store_buffer_block_; |
243 #define DECLARE_MEMBERS(type_name, member_name, expr, default_init_value) \ | 276 #define DECLARE_MEMBERS(type_name, member_name, expr, default_init_value) \ |
244 type_name member_name; | 277 type_name member_name; |
245 CACHED_CONSTANTS_LIST(DECLARE_MEMBERS) | 278 CACHED_CONSTANTS_LIST(DECLARE_MEMBERS) |
246 #undef DECLARE_MEMBERS | 279 #undef DECLARE_MEMBERS |
247 | 280 |
248 explicit Thread(bool init_vm_constants = true); | 281 explicit Thread(bool init_vm_constants = true); |
(...skipping 23 matching lines...) Expand all Loading... |
272 friend class ApiZone; | 305 friend class ApiZone; |
273 friend class Isolate; | 306 friend class Isolate; |
274 friend class StackZone; | 307 friend class StackZone; |
275 friend class ThreadRegistry; | 308 friend class ThreadRegistry; |
276 DISALLOW_COPY_AND_ASSIGN(Thread); | 309 DISALLOW_COPY_AND_ASSIGN(Thread); |
277 }; | 310 }; |
278 | 311 |
279 } // namespace dart | 312 } // namespace dart |
280 | 313 |
281 #endif // VM_THREAD_H_ | 314 #endif // VM_THREAD_H_ |
OLD | NEW |