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

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

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month 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/os_thread.h ('k') | runtime/vm/os_thread_android.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) 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 #include "vm/os_thread.h" 5 #include "vm/os_thread.h"
6 6
7 #include "vm/atomic.h" 7 #include "vm/atomic.h"
8 #include "vm/lockers.h" 8 #include "vm/lockers.h"
9 #include "vm/log.h" 9 #include "vm/log.h"
10 #include "vm/thread_interrupter.h" 10 #include "vm/thread_interrupter.h"
11 #include "vm/timeline.h" 11 #include "vm/timeline.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 // The single thread local key which stores all the thread local data 15 // The single thread local key which stores all the thread local data
16 // for a thread. 16 // for a thread.
17 ThreadLocalKey OSThread::thread_key_ = kUnsetThreadLocalKey; 17 ThreadLocalKey OSThread::thread_key_ = kUnsetThreadLocalKey;
18 OSThread* OSThread::thread_list_head_ = NULL; 18 OSThread* OSThread::thread_list_head_ = NULL;
19 Mutex* OSThread::thread_list_lock_ = NULL; 19 Mutex* OSThread::thread_list_lock_ = NULL;
20 bool OSThread::creation_enabled_ = false; 20 bool OSThread::creation_enabled_ = false;
21 21
22 22
23 OSThread::OSThread() : 23 OSThread::OSThread()
24 BaseThread(true), 24 : BaseThread(true),
25 id_(OSThread::GetCurrentThreadId()), 25 id_(OSThread::GetCurrentThreadId()),
26 #if defined(DEBUG) 26 #if defined(DEBUG)
27 join_id_(kInvalidThreadJoinId), 27 join_id_(kInvalidThreadJoinId),
28 #endif 28 #endif
29 #ifndef PRODUCT 29 #ifndef PRODUCT
30 trace_id_(OSThread::GetCurrentThreadTraceId()), 30 trace_id_(OSThread::GetCurrentThreadTraceId()),
31 #endif 31 #endif
32 name_(NULL), 32 name_(NULL),
33 timeline_block_lock_(new Mutex()), 33 timeline_block_lock_(new Mutex()),
34 timeline_block_(NULL), 34 timeline_block_(NULL),
35 thread_list_next_(NULL), 35 thread_list_next_(NULL),
36 thread_interrupt_disabled_(1), // Thread interrupts disabled by default. 36 thread_interrupt_disabled_(1), // Thread interrupts disabled by default.
37 log_(new class Log()), 37 log_(new class Log()),
38 stack_base_(0), 38 stack_base_(0),
39 thread_(NULL) { 39 thread_(NULL) {
40 } 40 }
41 41
42 42
43 OSThread* OSThread::CreateOSThread() { 43 OSThread* OSThread::CreateOSThread() {
44 ASSERT(thread_list_lock_ != NULL); 44 ASSERT(thread_list_lock_ != NULL);
45 MutexLocker ml(thread_list_lock_); 45 MutexLocker ml(thread_list_lock_);
46 if (!creation_enabled_) { 46 if (!creation_enabled_) {
47 return NULL; 47 return NULL;
48 } 48 }
49 OSThread* os_thread = new OSThread(); 49 OSThread* os_thread = new OSThread();
(...skipping 10 matching lines...) Expand all
60 if (Timeline::recorder() != NULL) { 60 if (Timeline::recorder() != NULL) {
61 Timeline::recorder()->FinishBlock(timeline_block_); 61 Timeline::recorder()->FinishBlock(timeline_block_);
62 } 62 }
63 } 63 }
64 timeline_block_ = NULL; 64 timeline_block_ = NULL;
65 delete timeline_block_lock_; 65 delete timeline_block_lock_;
66 free(name_); 66 free(name_);
67 } 67 }
68 68
69 69
70
71 void OSThread::SetName(const char* name) { 70 void OSThread::SetName(const char* name) {
72 MutexLocker ml(thread_list_lock_); 71 MutexLocker ml(thread_list_lock_);
73 // Clear the old thread name. 72 // Clear the old thread name.
74 if (name_ != NULL) { 73 if (name_ != NULL) {
75 free(name_); 74 free(name_);
76 name_ = NULL; 75 name_ = NULL;
77 } 76 }
78 set_name(name); 77 set_name(name);
79 } 78 }
80 79
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 127
129 // Create a new OSThread strcture and set it as the TLS. 128 // Create a new OSThread strcture and set it as the TLS.
130 OSThread* os_thread = CreateOSThread(); 129 OSThread* os_thread = CreateOSThread();
131 ASSERT(os_thread != NULL); 130 ASSERT(os_thread != NULL);
132 OSThread::SetCurrent(os_thread); 131 OSThread::SetCurrent(os_thread);
133 os_thread->set_name("Dart_Initialize"); 132 os_thread->set_name("Dart_Initialize");
134 } 133 }
135 134
136 135
137 void OSThread::Cleanup() { 136 void OSThread::Cleanup() {
138 // We cannot delete the thread local key and thread list lock, yet. 137 // We cannot delete the thread local key and thread list lock, yet.
139 // See the note on thread_list_lock_ in os_thread.h. 138 // See the note on thread_list_lock_ in os_thread.h.
140 #if 0 139 #if 0
141 if (thread_list_lock_ != NULL) { 140 if (thread_list_lock_ != NULL) {
142 // Delete the thread local key. 141 // Delete the thread local key.
143 ASSERT(thread_key_ != kUnsetThreadLocalKey); 142 ASSERT(thread_key_ != kUnsetThreadLocalKey);
144 DeleteThreadLocal(thread_key_); 143 DeleteThreadLocal(thread_key_);
145 thread_key_ = kUnsetThreadLocalKey; 144 thread_key_ = kUnsetThreadLocalKey;
146 145
147 // Delete the global OSThread lock. 146 // Delete the global OSThread lock.
148 ASSERT(thread_list_lock_ != NULL); 147 ASSERT(thread_list_lock_ != NULL);
149 delete thread_list_lock_; 148 delete thread_list_lock_;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // Scan across list and remove |thread|. 235 // Scan across list and remove |thread|.
237 while (current != NULL) { 236 while (current != NULL) {
238 if (current == thread) { 237 if (current == thread) {
239 // We found |thread|, remove from list. 238 // We found |thread|, remove from list.
240 if (previous == NULL) { 239 if (previous == NULL) {
241 thread_list_head_ = thread->thread_list_next_; 240 thread_list_head_ = thread->thread_list_next_;
242 } else { 241 } else {
243 previous->thread_list_next_ = current->thread_list_next_; 242 previous->thread_list_next_ = current->thread_list_next_;
244 } 243 }
245 thread->thread_list_next_ = NULL; 244 thread->thread_list_next_ = NULL;
246 final_thread = !creation_enabled_ && (thread_list_head_ == NULL); 245 final_thread = !creation_enabled_ && (thread_list_head_ == NULL);
247 break; 246 break;
248 } 247 }
249 previous = current; 248 previous = current;
250 current = current->thread_list_next_; 249 current = current->thread_list_next_;
251 } 250 }
252 } 251 }
253 // Check if this is the last thread. The last thread does a cleanup 252 // Check if this is the last thread. The last thread does a cleanup
254 // which removes the thread local key and the associated mutex. 253 // which removes the thread local key and the associated mutex.
255 if (final_thread) { 254 if (final_thread) {
256 Cleanup(); 255 Cleanup();
(...skipping 30 matching lines...) Expand all
287 286
288 OSThread* OSThreadIterator::Next() { 287 OSThread* OSThreadIterator::Next() {
289 ASSERT(OSThread::thread_list_lock_ != NULL); 288 ASSERT(OSThread::thread_list_lock_ != NULL);
290 ASSERT(OSThread::thread_list_lock_->IsOwnedByCurrentThread()); 289 ASSERT(OSThread::thread_list_lock_->IsOwnedByCurrentThread());
291 OSThread* current = next_; 290 OSThread* current = next_;
292 next_ = next_->thread_list_next_; 291 next_ = next_->thread_list_next_;
293 return current; 292 return current;
294 } 293 }
295 294
296 } // namespace dart 295 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/os_thread.h ('k') | runtime/vm/os_thread_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698