Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: runtime/vm/os_thread.h

Issue 1483113002: Thread and Timeline fixes for Mojo. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Move OSThread creation from API call to OSThread::Current() Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 class OSThread : public BaseThread { 51 class OSThread : public BaseThread {
52 public: 52 public:
53 OSThread(); 53 OSThread();
54 ~OSThread(); 54 ~OSThread();
55 55
56 ThreadId id() const { 56 ThreadId id() const {
57 ASSERT(id_ != OSThread::kInvalidThreadId); 57 ASSERT(id_ != OSThread::kInvalidThreadId);
58 return id_; 58 return id_;
59 } 59 }
60 60
61 ThreadId join_id() const { 61 ThreadJoinId join_id() const {
62 ASSERT(join_id_ != OSThread::kInvalidThreadJoinId); 62 ASSERT(join_id_ != OSThread::kInvalidThreadJoinId);
63 return join_id_; 63 return join_id_;
64 } 64 }
65 65
66 ThreadId trace_id() const { 66 ThreadId trace_id() const {
67 ASSERT(trace_id_ != OSThread::kInvalidThreadJoinId); 67 ASSERT(trace_id_ != OSThread::kInvalidThreadJoinId);
68 return trace_id_; 68 return trace_id_;
69 } 69 }
70 70
71 const char* name() const { 71 const char* name() const {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 static OSThread* Current() { 119 static OSThread* Current() {
120 BaseThread* thread = GetCurrentTLS(); 120 BaseThread* thread = GetCurrentTLS();
121 OSThread* os_thread = NULL; 121 OSThread* os_thread = NULL;
122 if (thread != NULL) { 122 if (thread != NULL) {
123 if (thread->is_os_thread()) { 123 if (thread->is_os_thread()) {
124 os_thread = reinterpret_cast<OSThread*>(thread); 124 os_thread = reinterpret_cast<OSThread*>(thread);
125 } else { 125 } else {
126 Thread* vm_thread = reinterpret_cast<Thread*>(thread); 126 Thread* vm_thread = reinterpret_cast<Thread*>(thread);
127 os_thread = GetOSThreadFromThread(vm_thread); 127 os_thread = GetOSThreadFromThread(vm_thread);
128 } 128 }
129 } else {
130 os_thread = new OSThread();
Ivan Posva 2015/12/01 18:00:51 Wondering whether we should move this out into a h
zra 2015/12/01 18:51:51 Done.
131 OSThread::SetCurrent(os_thread);
132 os_thread->set_name("Unknown");
129 } 133 }
130 return os_thread; 134 return os_thread;
131 } 135 }
132 static void SetCurrent(OSThread* current); 136 static void SetCurrent(OSThread* current);
133 137
134 // TODO(5411455): Use flag to override default value and Validate the 138 // TODO(5411455): Use flag to override default value and Validate the
135 // stack size by querying OS. 139 // stack size by querying OS.
136 static uword GetSpecifiedStackSize() { 140 static uword GetSpecifiedStackSize() {
137 ASSERT(OSThread::kStackSizeBuffer < OSThread::GetMaxStackSize()); 141 ASSERT(OSThread::kStackSizeBuffer < OSThread::GetMaxStackSize());
138 uword stack_size = OSThread::GetMaxStackSize() - OSThread::kStackSizeBuffer; 142 uword stack_size = OSThread::GetMaxStackSize() - OSThread::kStackSizeBuffer;
(...skipping 25 matching lines...) Expand all
164 static intptr_t GetMaxStackSize(); 168 static intptr_t GetMaxStackSize();
165 static void Join(ThreadJoinId id); 169 static void Join(ThreadJoinId id);
166 static intptr_t ThreadIdToIntPtr(ThreadId id); 170 static intptr_t ThreadIdToIntPtr(ThreadId id);
167 static ThreadId ThreadIdFromIntPtr(intptr_t id); 171 static ThreadId ThreadIdFromIntPtr(intptr_t id);
168 static bool Compare(ThreadId a, ThreadId b); 172 static bool Compare(ThreadId a, ThreadId b);
169 static void GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage); 173 static void GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage);
170 174
171 // Called at VM startup and shutdown. 175 // Called at VM startup and shutdown.
172 static void InitOnce(); 176 static void InitOnce();
173 177
174 static bool IsThreadInList(ThreadId join_id); 178 static bool IsThreadInList(ThreadJoinId join_id);
175 179
176 static const intptr_t kStackSizeBuffer = (4 * KB * kWordSize); 180 static const intptr_t kStackSizeBuffer = (4 * KB * kWordSize);
177 181
178 static ThreadLocalKey kUnsetThreadLocalKey; 182 static ThreadLocalKey kUnsetThreadLocalKey;
179 static ThreadId kInvalidThreadId; 183 static ThreadId kInvalidThreadId;
180 static ThreadJoinId kInvalidThreadJoinId; 184 static ThreadJoinId kInvalidThreadJoinId;
181 185
182 private: 186 private:
183 // These methods should not be used in a generic way and hence 187 // These methods should not be used in a generic way and hence
184 // are private, they have been added to solve the problem of 188 // are private, they have been added to solve the problem of
185 // accessing the VM thread structure from an OSThread object 189 // accessing the VM thread structure from an OSThread object
186 // in the windows thread interrupter which is used for profiling. 190 // in the windows thread interrupter which is used for profiling.
187 // We could eliminate this requirement if the windows thread interrupter 191 // We could eliminate this requirement if the windows thread interrupter
188 // is implemented differently. 192 // is implemented differently.
189 Thread* thread() const { return thread_; } 193 Thread* thread() const { return thread_; }
190 void set_thread(Thread* value) { 194 void set_thread(Thread* value) {
191 thread_ = value; 195 thread_ = value;
192 } 196 }
193 197
194 static void Cleanup(); 198 static void Cleanup();
195 static ThreadId GetCurrentThreadTraceId(); 199 static ThreadId GetCurrentThreadTraceId();
196 static ThreadJoinId GetCurrentThreadJoinId(); 200 static ThreadJoinId GetCurrentThreadJoinId();
197 static OSThread* GetOSThreadFromThread(Thread* thread); 201 static OSThread* GetOSThreadFromThread(Thread* thread);
198 static void AddThreadToList(OSThread* thread); 202 static void AddThreadToList(OSThread* thread);
199 static void RemoveThreadFromList(OSThread* thread); 203 static void RemoveThreadFromList(OSThread* thread);
200 204
201 static ThreadLocalKey thread_key_; 205 static ThreadLocalKey thread_key_;
202 206
203 const ThreadId id_; 207 const ThreadId id_;
204 const ThreadId join_id_; 208 const ThreadJoinId join_id_;
205 const ThreadId trace_id_; // Used to interface with tracing tools. 209 const ThreadId trace_id_; // Used to interface with tracing tools.
206 char* name_; // A name for this thread. 210 char* name_; // A name for this thread.
207 211
208 Mutex* timeline_block_lock_; 212 Mutex* timeline_block_lock_;
209 TimelineEventBlock* timeline_block_; 213 TimelineEventBlock* timeline_block_;
210 214
211 // All |Thread|s are registered in the thread list. 215 // All |Thread|s are registered in the thread list.
212 OSThread* thread_list_next_; 216 OSThread* thread_list_next_;
213 217
214 uintptr_t thread_interrupt_disabled_; 218 uintptr_t thread_interrupt_disabled_;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 #endif // defined(DEBUG) 318 #endif // defined(DEBUG)
315 319
316 DISALLOW_COPY_AND_ASSIGN(Monitor); 320 DISALLOW_COPY_AND_ASSIGN(Monitor);
317 }; 321 };
318 322
319 323
320 } // namespace dart 324 } // namespace dart
321 325
322 326
323 #endif // VM_OS_THREAD_H_ 327 #endif // VM_OS_THREAD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698