| 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" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 timeline_block_(NULL), | 29 timeline_block_(NULL), |
| 30 thread_list_next_(NULL), | 30 thread_list_next_(NULL), |
| 31 thread_interrupt_disabled_(1), // Thread interrupts disabled by default. | 31 thread_interrupt_disabled_(1), // Thread interrupts disabled by default. |
| 32 log_(new class Log()), | 32 log_(new class Log()), |
| 33 stack_base_(0), | 33 stack_base_(0), |
| 34 thread_(NULL) { | 34 thread_(NULL) { |
| 35 } | 35 } |
| 36 | 36 |
| 37 | 37 |
| 38 OSThread* OSThread::CreateOSThread() { | 38 OSThread* OSThread::CreateOSThread() { |
| 39 if (thread_list_lock_ == NULL) { | 39 ASSERT(thread_list_lock_ != NULL); |
| 40 MutexLocker ml(thread_list_lock_); |
| 41 if (!creation_enabled_) { |
| 40 return NULL; | 42 return NULL; |
| 41 } | 43 } |
| 42 { | 44 OSThread* os_thread = new OSThread(); |
| 43 MutexLocker ml(thread_list_lock_); | 45 AddThreadToListLocked(os_thread); |
| 44 if (!creation_enabled_) { | 46 return os_thread; |
| 45 return NULL; | |
| 46 } | |
| 47 OSThread* os_thread = new OSThread(); | |
| 48 AddThreadToListLocked(os_thread); | |
| 49 return os_thread; | |
| 50 } | |
| 51 } | 47 } |
| 52 | 48 |
| 53 | 49 |
| 54 OSThread::~OSThread() { | 50 OSThread::~OSThread() { |
| 55 RemoveThreadFromList(this); | 51 RemoveThreadFromList(this); |
| 56 delete log_; | 52 delete log_; |
| 57 log_ = NULL; | 53 log_ = NULL; |
| 58 if (Timeline::recorder() != NULL) { | 54 if (Timeline::recorder() != NULL) { |
| 59 Timeline::recorder()->FinishBlock(timeline_block_); | 55 Timeline::recorder()->FinishBlock(timeline_block_); |
| 60 } | 56 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 109 |
| 114 // Create a new OSThread strcture and set it as the TLS. | 110 // Create a new OSThread strcture and set it as the TLS. |
| 115 OSThread* os_thread = CreateOSThread(); | 111 OSThread* os_thread = CreateOSThread(); |
| 116 ASSERT(os_thread != NULL); | 112 ASSERT(os_thread != NULL); |
| 117 OSThread::SetCurrent(os_thread); | 113 OSThread::SetCurrent(os_thread); |
| 118 os_thread->set_name("Dart_Initialize"); | 114 os_thread->set_name("Dart_Initialize"); |
| 119 } | 115 } |
| 120 | 116 |
| 121 | 117 |
| 122 void OSThread::Cleanup() { | 118 void OSThread::Cleanup() { |
| 119 // We cannot delete the thread local key and thread list lock, yet. |
| 120 // See the note on thread_list_lock_ in os_thread.h. |
| 121 #if 0 |
| 123 if (thread_list_lock_ != NULL) { | 122 if (thread_list_lock_ != NULL) { |
| 124 // Delete the thread local key. | 123 // Delete the thread local key. |
| 125 ASSERT(thread_key_ != kUnsetThreadLocalKey); | 124 ASSERT(thread_key_ != kUnsetThreadLocalKey); |
| 126 DeleteThreadLocal(thread_key_); | 125 DeleteThreadLocal(thread_key_); |
| 127 thread_key_ = kUnsetThreadLocalKey; | 126 thread_key_ = kUnsetThreadLocalKey; |
| 128 | 127 |
| 129 // Delete the global OSThread lock. | 128 // Delete the global OSThread lock. |
| 130 ASSERT(thread_list_lock_ != NULL); | 129 ASSERT(thread_list_lock_ != NULL); |
| 131 delete thread_list_lock_; | 130 delete thread_list_lock_; |
| 132 thread_list_lock_ = NULL; | 131 thread_list_lock_ = NULL; |
| 133 } | 132 } |
| 133 #endif |
| 134 } | 134 } |
| 135 | 135 |
| 136 | 136 |
| 137 OSThread* OSThread::CreateAndSetUnknownThread() { | 137 OSThread* OSThread::CreateAndSetUnknownThread() { |
| 138 ASSERT(OSThread::GetCurrentTLS() == NULL); | 138 ASSERT(OSThread::GetCurrentTLS() == NULL); |
| 139 OSThread* os_thread = CreateOSThread(); | 139 OSThread* os_thread = CreateOSThread(); |
| 140 if (os_thread != NULL) { | 140 if (os_thread != NULL) { |
| 141 OSThread::SetCurrent(os_thread); | 141 OSThread::SetCurrent(os_thread); |
| 142 os_thread->set_name("Unknown"); | 142 os_thread->set_name("Unknown"); |
| 143 } | 143 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 | 268 |
| 269 OSThread* OSThreadIterator::Next() { | 269 OSThread* OSThreadIterator::Next() { |
| 270 ASSERT(OSThread::thread_list_lock_ != NULL); | 270 ASSERT(OSThread::thread_list_lock_ != NULL); |
| 271 ASSERT(OSThread::thread_list_lock_->IsOwnedByCurrentThread()); | 271 ASSERT(OSThread::thread_list_lock_->IsOwnedByCurrentThread()); |
| 272 OSThread* current = next_; | 272 OSThread* current = next_; |
| 273 next_ = next_->thread_list_next_; | 273 next_ = next_->thread_list_next_; |
| 274 return current; | 274 return current; |
| 275 } | 275 } |
| 276 | 276 |
| 277 } // namespace dart | 277 } // namespace dart |
| OLD | NEW |