| 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 #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 join_id_(OSThread::GetCurrentThreadJoinId()), | 26 #if defined(DEBUG) |
| 27 join_id_(kInvalidThreadJoinId), |
| 28 #endif |
| 27 trace_id_(OSThread::GetCurrentThreadTraceId()), | 29 trace_id_(OSThread::GetCurrentThreadTraceId()), |
| 28 name_(NULL), | 30 name_(NULL), |
| 29 timeline_block_lock_(new Mutex()), | 31 timeline_block_lock_(new Mutex()), |
| 30 timeline_block_(NULL), | 32 timeline_block_(NULL), |
| 31 thread_list_next_(NULL), | 33 thread_list_next_(NULL), |
| 32 thread_interrupt_disabled_(1), // Thread interrupts disabled by default. | 34 thread_interrupt_disabled_(1), // Thread interrupts disabled by default. |
| 33 log_(new class Log()), | 35 log_(new class Log()), |
| 34 stack_base_(0), | 36 stack_base_(0), |
| 35 thread_(NULL) { | 37 thread_(NULL) { |
| 36 } | 38 } |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 ASSERT(OSThread::GetCurrentTLS() == NULL); | 155 ASSERT(OSThread::GetCurrentTLS() == NULL); |
| 154 OSThread* os_thread = CreateOSThread(); | 156 OSThread* os_thread = CreateOSThread(); |
| 155 if (os_thread != NULL) { | 157 if (os_thread != NULL) { |
| 156 OSThread::SetCurrent(os_thread); | 158 OSThread::SetCurrent(os_thread); |
| 157 os_thread->set_name("Unknown"); | 159 os_thread->set_name("Unknown"); |
| 158 } | 160 } |
| 159 return os_thread; | 161 return os_thread; |
| 160 } | 162 } |
| 161 | 163 |
| 162 | 164 |
| 163 bool OSThread::IsThreadInList(ThreadJoinId join_id) { | 165 bool OSThread::IsThreadInList(ThreadId id) { |
| 164 if (join_id == OSThread::kInvalidThreadJoinId) { | 166 if (id == OSThread::kInvalidThreadId) { |
| 165 return false; | 167 return false; |
| 166 } | 168 } |
| 167 OSThreadIterator it; | 169 OSThreadIterator it; |
| 168 while (it.HasNext()) { | 170 while (it.HasNext()) { |
| 169 ASSERT(OSThread::thread_list_lock_->IsOwnedByCurrentThread()); | 171 ASSERT(OSThread::thread_list_lock_->IsOwnedByCurrentThread()); |
| 170 OSThread* t = it.Next(); | 172 OSThread* t = it.Next(); |
| 171 // An address test is not sufficient because the allocator may recycle | 173 // An address test is not sufficient because the allocator may recycle |
| 172 // the address for another Thread. Test against the thread's join id. | 174 // the address for another Thread. Test against the thread's id. |
| 173 if (t->join_id() == join_id) { | 175 if (t->id() == id) { |
| 174 return true; | 176 return true; |
| 175 } | 177 } |
| 176 } | 178 } |
| 177 return false; | 179 return false; |
| 178 } | 180 } |
| 179 | 181 |
| 180 | 182 |
| 181 void OSThread::DisableOSThreadCreation() { | 183 void OSThread::DisableOSThreadCreation() { |
| 182 MutexLocker ml(thread_list_lock_); | 184 MutexLocker ml(thread_list_lock_); |
| 183 creation_enabled_ = false; | 185 creation_enabled_ = false; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 | 285 |
| 284 OSThread* OSThreadIterator::Next() { | 286 OSThread* OSThreadIterator::Next() { |
| 285 ASSERT(OSThread::thread_list_lock_ != NULL); | 287 ASSERT(OSThread::thread_list_lock_ != NULL); |
| 286 ASSERT(OSThread::thread_list_lock_->IsOwnedByCurrentThread()); | 288 ASSERT(OSThread::thread_list_lock_->IsOwnedByCurrentThread()); |
| 287 OSThread* current = next_; | 289 OSThread* current = next_; |
| 288 next_ = next_->thread_list_next_; | 290 next_ = next_->thread_list_next_; |
| 289 return current; | 291 return current; |
| 290 } | 292 } |
| 291 | 293 |
| 292 } // namespace dart | 294 } // namespace dart |
| OLD | NEW |