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. | |
Ivan Posva
2015/08/20 18:00:10
Can you please explain in the comments why these t
Cutch
2015/08/20 20:40:19
Done.
| |
56 // * Allocating memory. | |
koda
2015/08/20 15:45:14
To catch violations of this in DEBUG mode, conside
Cutch
2015/08/20 20:40:19
This comment was about native C allocations.
| |
57 // * Taking a lock. | |
58 typedef void (*ThreadInterruptCallback)(const InterruptedThreadState& state, | |
59 void* data); | |
42 | 60 |
43 // A VM thread; may be executing Dart code or performing helper tasks like | 61 // A VM thread; may be executing Dart code or performing helper tasks like |
44 // garbage collection or compilation. The Thread structure associated with | 62 // garbage collection or compilation. The Thread structure associated with |
45 // a thread is allocated by EnsureInit before entering an isolate, and destroyed | 63 // a thread is allocated by EnsureInit before entering an isolate, and destroyed |
46 // automatically when the underlying OS thread exits. NOTE: On Windows, CleanUp | 64 // automatically when the underlying OS thread exits. NOTE: On Windows, CleanUp |
47 // must currently be called manually (issue 23474). | 65 // must currently be called manually (issue 23474). |
48 class Thread { | 66 class Thread { |
49 public: | 67 public: |
50 // The currently executing thread, or NULL if not yet initialized. | 68 // The currently executing thread, or NULL if not yet initialized. |
51 static Thread* Current() { | 69 static Thread* Current() { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 | 244 |
227 void set_timeline_block(TimelineEventBlock* block) { | 245 void set_timeline_block(TimelineEventBlock* block) { |
228 state_.timeline_block = block; | 246 state_.timeline_block = block; |
229 } | 247 } |
230 | 248 |
231 LongJumpScope* long_jump_base() const { return state_.long_jump_base; } | 249 LongJumpScope* long_jump_base() const { return state_.long_jump_base; } |
232 void set_long_jump_base(LongJumpScope* value) { | 250 void set_long_jump_base(LongJumpScope* value) { |
233 state_.long_jump_base = value; | 251 state_.long_jump_base = value; |
234 } | 252 } |
235 | 253 |
254 ThreadId id() const { | |
255 return id_; | |
256 } | |
257 | |
258 ThreadInterruptCallback thread_interrupt_callback() const { | |
259 return thread_interrupt_callback_; | |
260 } | |
261 | |
262 void* thread_interrupt_data() const { | |
263 return thread_interrupt_data_; | |
264 } | |
265 | |
266 void SetThreadInterrupter(ThreadInterruptCallback callback, void* data); | |
267 | |
268 bool ShouldInterrupt() const; | |
269 | |
236 private: | 270 private: |
237 static ThreadLocalKey thread_key_; | 271 static ThreadLocalKey thread_key_; |
238 | 272 |
273 const ThreadId id_; | |
274 ThreadInterruptCallback thread_interrupt_callback_; | |
275 void* thread_interrupt_data_; | |
239 Isolate* isolate_; | 276 Isolate* isolate_; |
240 Heap* heap_; | 277 Heap* heap_; |
241 State state_; | 278 State state_; |
242 StoreBufferBlock* store_buffer_block_; | 279 StoreBufferBlock* store_buffer_block_; |
243 #define DECLARE_MEMBERS(type_name, member_name, expr, default_init_value) \ | 280 #define DECLARE_MEMBERS(type_name, member_name, expr, default_init_value) \ |
244 type_name member_name; | 281 type_name member_name; |
245 CACHED_CONSTANTS_LIST(DECLARE_MEMBERS) | 282 CACHED_CONSTANTS_LIST(DECLARE_MEMBERS) |
246 #undef DECLARE_MEMBERS | 283 #undef DECLARE_MEMBERS |
247 | 284 |
248 explicit Thread(bool init_vm_constants = true); | 285 explicit Thread(bool init_vm_constants = true); |
(...skipping 23 matching lines...) Expand all Loading... | |
272 friend class ApiZone; | 309 friend class ApiZone; |
273 friend class Isolate; | 310 friend class Isolate; |
274 friend class StackZone; | 311 friend class StackZone; |
275 friend class ThreadRegistry; | 312 friend class ThreadRegistry; |
276 DISALLOW_COPY_AND_ASSIGN(Thread); | 313 DISALLOW_COPY_AND_ASSIGN(Thread); |
277 }; | 314 }; |
278 | 315 |
279 } // namespace dart | 316 } // namespace dart |
280 | 317 |
281 #endif // VM_THREAD_H_ | 318 #endif // VM_THREAD_H_ |
OLD | NEW |