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

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: Cleanup 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
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/os_thread.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 = CreateAndSetUnknownThread();
129 } 131 }
130 return os_thread; 132 return os_thread;
131 } 133 }
132 static void SetCurrent(OSThread* current); 134 static void SetCurrent(OSThread* current);
133 135
134 // TODO(5411455): Use flag to override default value and Validate the 136 // TODO(5411455): Use flag to override default value and Validate the
135 // stack size by querying OS. 137 // stack size by querying OS.
136 static uword GetSpecifiedStackSize() { 138 static uword GetSpecifiedStackSize() {
137 ASSERT(OSThread::kStackSizeBuffer < OSThread::GetMaxStackSize()); 139 ASSERT(OSThread::kStackSizeBuffer < OSThread::GetMaxStackSize());
138 uword stack_size = OSThread::GetMaxStackSize() - OSThread::kStackSizeBuffer; 140 uword stack_size = OSThread::GetMaxStackSize() - OSThread::kStackSizeBuffer;
(...skipping 25 matching lines...) Expand all
164 static intptr_t GetMaxStackSize(); 166 static intptr_t GetMaxStackSize();
165 static void Join(ThreadJoinId id); 167 static void Join(ThreadJoinId id);
166 static intptr_t ThreadIdToIntPtr(ThreadId id); 168 static intptr_t ThreadIdToIntPtr(ThreadId id);
167 static ThreadId ThreadIdFromIntPtr(intptr_t id); 169 static ThreadId ThreadIdFromIntPtr(intptr_t id);
168 static bool Compare(ThreadId a, ThreadId b); 170 static bool Compare(ThreadId a, ThreadId b);
169 static void GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage); 171 static void GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage);
170 172
171 // Called at VM startup and shutdown. 173 // Called at VM startup and shutdown.
172 static void InitOnce(); 174 static void InitOnce();
173 175
174 static bool IsThreadInList(ThreadId join_id); 176 static bool IsThreadInList(ThreadJoinId join_id);
175 177
176 static const intptr_t kStackSizeBuffer = (4 * KB * kWordSize); 178 static const intptr_t kStackSizeBuffer = (4 * KB * kWordSize);
177 179
178 static ThreadLocalKey kUnsetThreadLocalKey; 180 static ThreadLocalKey kUnsetThreadLocalKey;
179 static ThreadId kInvalidThreadId; 181 static ThreadId kInvalidThreadId;
180 static ThreadJoinId kInvalidThreadJoinId; 182 static ThreadJoinId kInvalidThreadJoinId;
181 183
182 private: 184 private:
183 // These methods should not be used in a generic way and hence 185 // These methods should not be used in a generic way and hence
184 // are private, they have been added to solve the problem of 186 // are private, they have been added to solve the problem of
185 // accessing the VM thread structure from an OSThread object 187 // accessing the VM thread structure from an OSThread object
186 // in the windows thread interrupter which is used for profiling. 188 // in the windows thread interrupter which is used for profiling.
187 // We could eliminate this requirement if the windows thread interrupter 189 // We could eliminate this requirement if the windows thread interrupter
188 // is implemented differently. 190 // is implemented differently.
189 Thread* thread() const { return thread_; } 191 Thread* thread() const { return thread_; }
190 void set_thread(Thread* value) { 192 void set_thread(Thread* value) {
191 thread_ = value; 193 thread_ = value;
192 } 194 }
193 195
194 static void Cleanup(); 196 static void Cleanup();
195 static ThreadId GetCurrentThreadTraceId(); 197 static ThreadId GetCurrentThreadTraceId();
196 static ThreadJoinId GetCurrentThreadJoinId(); 198 static ThreadJoinId GetCurrentThreadJoinId();
197 static OSThread* GetOSThreadFromThread(Thread* thread); 199 static OSThread* GetOSThreadFromThread(Thread* thread);
198 static void AddThreadToList(OSThread* thread); 200 static void AddThreadToList(OSThread* thread);
199 static void RemoveThreadFromList(OSThread* thread); 201 static void RemoveThreadFromList(OSThread* thread);
202 static OSThread* CreateAndSetUnknownThread();
200 203
201 static ThreadLocalKey thread_key_; 204 static ThreadLocalKey thread_key_;
202 205
203 const ThreadId id_; 206 const ThreadId id_;
204 const ThreadId join_id_; 207 const ThreadJoinId join_id_;
205 const ThreadId trace_id_; // Used to interface with tracing tools. 208 const ThreadId trace_id_; // Used to interface with tracing tools.
206 char* name_; // A name for this thread. 209 char* name_; // A name for this thread.
207 210
208 Mutex* timeline_block_lock_; 211 Mutex* timeline_block_lock_;
209 TimelineEventBlock* timeline_block_; 212 TimelineEventBlock* timeline_block_;
210 213
211 // All |Thread|s are registered in the thread list. 214 // All |Thread|s are registered in the thread list.
212 OSThread* thread_list_next_; 215 OSThread* thread_list_next_;
213 216
214 uintptr_t thread_interrupt_disabled_; 217 uintptr_t thread_interrupt_disabled_;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 #endif // defined(DEBUG) 317 #endif // defined(DEBUG)
315 318
316 DISALLOW_COPY_AND_ASSIGN(Monitor); 319 DISALLOW_COPY_AND_ASSIGN(Monitor);
317 }; 320 };
318 321
319 322
320 } // namespace dart 323 } // namespace dart
321 324
322 325
323 #endif // VM_OS_THREAD_H_ 326 #endif // VM_OS_THREAD_H_
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/os_thread.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698