Chromium Code Reviews| 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 MutexLocker ml(thread_list_lock_); |
| 40 if (!creation_enabled_) { | |
| 40 return NULL; | 41 return NULL; |
| 41 } | 42 } |
| 42 { | 43 OSThread* os_thread = new OSThread(); |
| 43 MutexLocker ml(thread_list_lock_); | 44 AddThreadToListLocked(os_thread); |
| 44 if (!creation_enabled_) { | 45 return os_thread; |
| 45 return NULL; | |
| 46 } | |
| 47 OSThread* os_thread = new OSThread(); | |
| 48 AddThreadToListLocked(os_thread); | |
| 49 return os_thread; | |
| 50 } | |
| 51 } | 46 } |
| 52 | 47 |
| 53 | 48 |
| 54 OSThread::~OSThread() { | 49 OSThread::~OSThread() { |
| 55 RemoveThreadFromList(this); | 50 RemoveThreadFromList(this); |
| 56 delete log_; | 51 delete log_; |
| 57 log_ = NULL; | 52 log_ = NULL; |
| 58 if (Timeline::recorder() != NULL) { | 53 if (Timeline::recorder() != NULL) { |
| 59 Timeline::recorder()->FinishBlock(timeline_block_); | 54 Timeline::recorder()->FinishBlock(timeline_block_); |
| 60 } | 55 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 // Create a new OSThread strcture and set it as the TLS. | 109 // Create a new OSThread strcture and set it as the TLS. |
| 115 OSThread* os_thread = CreateOSThread(); | 110 OSThread* os_thread = CreateOSThread(); |
| 116 ASSERT(os_thread != NULL); | 111 ASSERT(os_thread != NULL); |
| 117 OSThread::SetCurrent(os_thread); | 112 OSThread::SetCurrent(os_thread); |
| 118 os_thread->set_name("Dart_Initialize"); | 113 os_thread->set_name("Dart_Initialize"); |
| 119 } | 114 } |
| 120 | 115 |
| 121 | 116 |
| 122 void OSThread::Cleanup() { | 117 void OSThread::Cleanup() { |
| 123 if (thread_list_lock_ != NULL) { | 118 if (thread_list_lock_ != NULL) { |
| 119 // We cannot delete the key, yet. See the note about thread_list_lock_. | |
| 124 // Delete the thread local key. | 120 // Delete the thread local key. |
| 125 ASSERT(thread_key_ != kUnsetThreadLocalKey); | 121 // ASSERT(thread_key_ != kUnsetThreadLocalKey); |
| 126 DeleteThreadLocal(thread_key_); | 122 // DeleteThreadLocal(thread_key_); |
| 127 thread_key_ = kUnsetThreadLocalKey; | 123 // thread_key_ = kUnsetThreadLocalKey; |
| 128 | 124 |
| 125 // The thread_list_lock_ cannot be deleted without a bit more cleverness. | |
| 126 // See the note in os_thread.h. | |
| 129 // Delete the global OSThread lock. | 127 // Delete the global OSThread lock. |
| 130 ASSERT(thread_list_lock_ != NULL); | 128 // ASSERT(thread_list_lock_ != NULL); |
| 131 delete thread_list_lock_; | 129 // delete thread_list_lock_; |
| 132 thread_list_lock_ = NULL; | 130 // thread_list_lock_ = NULL; |
| 133 } | 131 } |
|
siva
2016/01/04 23:07:55
Since everything inside the 'if statement' is comm
zra
2016/01/04 23:21:53
Done.
| |
| 134 } | 132 } |
| 135 | 133 |
| 136 | 134 |
| 137 OSThread* OSThread::CreateAndSetUnknownThread() { | 135 OSThread* OSThread::CreateAndSetUnknownThread() { |
| 138 ASSERT(OSThread::GetCurrentTLS() == NULL); | 136 ASSERT(OSThread::GetCurrentTLS() == NULL); |
| 139 OSThread* os_thread = CreateOSThread(); | 137 OSThread* os_thread = CreateOSThread(); |
| 140 if (os_thread != NULL) { | 138 if (os_thread != NULL) { |
| 141 OSThread::SetCurrent(os_thread); | 139 OSThread::SetCurrent(os_thread); |
| 142 os_thread->set_name("Unknown"); | 140 os_thread->set_name("Unknown"); |
| 143 } | 141 } |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 | 266 |
| 269 OSThread* OSThreadIterator::Next() { | 267 OSThread* OSThreadIterator::Next() { |
| 270 ASSERT(OSThread::thread_list_lock_ != NULL); | 268 ASSERT(OSThread::thread_list_lock_ != NULL); |
| 271 ASSERT(OSThread::thread_list_lock_->IsOwnedByCurrentThread()); | 269 ASSERT(OSThread::thread_list_lock_->IsOwnedByCurrentThread()); |
| 272 OSThread* current = next_; | 270 OSThread* current = next_; |
| 273 next_ = next_->thread_list_next_; | 271 next_ = next_->thread_list_next_; |
| 274 return current; | 272 return current; |
| 275 } | 273 } |
| 276 | 274 |
| 277 } // namespace dart | 275 } // namespace dart |
| OLD | NEW |