OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_OS_THREAD_H_ | 5 #ifndef VM_OS_THREAD_H_ |
6 #define VM_OS_THREAD_H_ | 6 #define VM_OS_THREAD_H_ |
7 | 7 |
8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
10 #include "vm/globals.h" | 10 #include "vm/globals.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 // this factory style method 'CreateOSThread' to create OSThread structures. | 54 // this factory style method 'CreateOSThread' to create OSThread structures. |
55 // The method can return a NULL if the Dart VM is in shutdown mode. | 55 // The method can return a NULL if the Dart VM is in shutdown mode. |
56 static OSThread* CreateOSThread(); | 56 static OSThread* CreateOSThread(); |
57 ~OSThread(); | 57 ~OSThread(); |
58 | 58 |
59 ThreadId id() const { | 59 ThreadId id() const { |
60 ASSERT(id_ != OSThread::kInvalidThreadId); | 60 ASSERT(id_ != OSThread::kInvalidThreadId); |
61 return id_; | 61 return id_; |
62 } | 62 } |
63 | 63 |
64 ThreadJoinId join_id() const { | |
65 ASSERT(join_id_ != OSThread::kInvalidThreadJoinId); | |
66 return join_id_; | |
67 } | |
68 | |
69 ThreadId trace_id() const { | 64 ThreadId trace_id() const { |
70 ASSERT(trace_id_ != OSThread::kInvalidThreadJoinId); | 65 ASSERT(trace_id_ != OSThread::kInvalidThreadId); |
71 return trace_id_; | 66 return trace_id_; |
72 } | 67 } |
73 | 68 |
74 const char* name() const { | 69 const char* name() const { |
75 return name_; | 70 return name_; |
76 } | 71 } |
77 | 72 |
78 void SetName(const char* name); | 73 void SetName(const char* name); |
79 | 74 |
80 void set_name(const char* name) { | 75 void set_name(const char* name) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 return ThreadInlineImpl::GetThreadLocal(key); | 162 return ThreadInlineImpl::GetThreadLocal(key); |
168 } | 163 } |
169 static ThreadId GetCurrentThreadId(); | 164 static ThreadId GetCurrentThreadId(); |
170 static void SetThreadLocal(ThreadLocalKey key, uword value); | 165 static void SetThreadLocal(ThreadLocalKey key, uword value); |
171 static intptr_t GetMaxStackSize(); | 166 static intptr_t GetMaxStackSize(); |
172 static void Join(ThreadJoinId id); | 167 static void Join(ThreadJoinId id); |
173 static intptr_t ThreadIdToIntPtr(ThreadId id); | 168 static intptr_t ThreadIdToIntPtr(ThreadId id); |
174 static ThreadId ThreadIdFromIntPtr(intptr_t id); | 169 static ThreadId ThreadIdFromIntPtr(intptr_t id); |
175 static bool Compare(ThreadId a, ThreadId b); | 170 static bool Compare(ThreadId a, ThreadId b); |
176 | 171 |
| 172 // This function can be called only once per OSThread, and should only be |
| 173 // called when the retunred id will eventually be passed to OSThread::Join(). |
| 174 static ThreadJoinId GetCurrentThreadJoinId(OSThread* thread); |
| 175 |
177 // Called at VM startup and shutdown. | 176 // Called at VM startup and shutdown. |
178 static void InitOnce(); | 177 static void InitOnce(); |
179 | 178 |
180 static bool IsThreadInList(ThreadJoinId join_id); | 179 static bool IsThreadInList(ThreadId id); |
181 | 180 |
182 static void DisableOSThreadCreation(); | 181 static void DisableOSThreadCreation(); |
183 static void EnableOSThreadCreation(); | 182 static void EnableOSThreadCreation(); |
184 | 183 |
185 static const intptr_t kStackSizeBuffer = (4 * KB * kWordSize); | 184 static const intptr_t kStackSizeBuffer = (4 * KB * kWordSize); |
186 | 185 |
187 static const ThreadId kInvalidThreadId; | 186 static const ThreadId kInvalidThreadId; |
188 static const ThreadJoinId kInvalidThreadJoinId; | 187 static const ThreadJoinId kInvalidThreadJoinId; |
189 | 188 |
190 private: | 189 private: |
191 // The constructor is private as CreateOSThread should be used | 190 // The constructor is private as CreateOSThread should be used |
192 // to create a new OSThread structure. | 191 // to create a new OSThread structure. |
193 OSThread(); | 192 OSThread(); |
194 | 193 |
195 // These methods should not be used in a generic way and hence | 194 // These methods should not be used in a generic way and hence |
196 // are private, they have been added to solve the problem of | 195 // are private, they have been added to solve the problem of |
197 // accessing the VM thread structure from an OSThread object | 196 // accessing the VM thread structure from an OSThread object |
198 // in the windows thread interrupter which is used for profiling. | 197 // in the windows thread interrupter which is used for profiling. |
199 // We could eliminate this requirement if the windows thread interrupter | 198 // We could eliminate this requirement if the windows thread interrupter |
200 // is implemented differently. | 199 // is implemented differently. |
201 Thread* thread() const { return thread_; } | 200 Thread* thread() const { return thread_; } |
202 void set_thread(Thread* value) { | 201 void set_thread(Thread* value) { |
203 thread_ = value; | 202 thread_ = value; |
204 } | 203 } |
205 | 204 |
206 static void Cleanup(); | 205 static void Cleanup(); |
207 static ThreadId GetCurrentThreadTraceId(); | 206 static ThreadId GetCurrentThreadTraceId(); |
208 static ThreadJoinId GetCurrentThreadJoinId(); | |
209 static OSThread* GetOSThreadFromThread(Thread* thread); | 207 static OSThread* GetOSThreadFromThread(Thread* thread); |
210 static void AddThreadToListLocked(OSThread* thread); | 208 static void AddThreadToListLocked(OSThread* thread); |
211 static void RemoveThreadFromList(OSThread* thread); | 209 static void RemoveThreadFromList(OSThread* thread); |
212 static OSThread* CreateAndSetUnknownThread(); | 210 static OSThread* CreateAndSetUnknownThread(); |
213 | 211 |
214 static ThreadLocalKey thread_key_; | 212 static ThreadLocalKey thread_key_; |
215 | 213 |
216 const ThreadId id_; | 214 const ThreadId id_; |
217 const ThreadJoinId join_id_; | 215 #if defined(DEBUG) |
| 216 // In DEBUG mode we use this field to ensure that GetCurrentThreadJoinId is |
| 217 // only called once per OSThread. |
| 218 ThreadJoinId join_id_; |
| 219 #endif |
218 const ThreadId trace_id_; // Used to interface with tracing tools. | 220 const ThreadId trace_id_; // Used to interface with tracing tools. |
219 char* name_; // A name for this thread. | 221 char* name_; // A name for this thread. |
220 | 222 |
221 Mutex* timeline_block_lock_; | 223 Mutex* timeline_block_lock_; |
222 TimelineEventBlock* timeline_block_; | 224 TimelineEventBlock* timeline_block_; |
223 | 225 |
224 // All |Thread|s are registered in the thread list. | 226 // All |Thread|s are registered in the thread list. |
225 OSThread* thread_list_next_; | 227 OSThread* thread_list_next_; |
226 | 228 |
227 uintptr_t thread_interrupt_disabled_; | 229 uintptr_t thread_interrupt_disabled_; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 friend class SafepointMonitorLocker; | 346 friend class SafepointMonitorLocker; |
345 friend void Dart_TestMonitor(); | 347 friend void Dart_TestMonitor(); |
346 DISALLOW_COPY_AND_ASSIGN(Monitor); | 348 DISALLOW_COPY_AND_ASSIGN(Monitor); |
347 }; | 349 }; |
348 | 350 |
349 | 351 |
350 } // namespace dart | 352 } // namespace dart |
351 | 353 |
352 | 354 |
353 #endif // VM_OS_THREAD_H_ | 355 #endif // VM_OS_THREAD_H_ |
OLD | NEW |