| 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/thread_registry.h" | 5 #include "vm/thread_registry.h" |
| 6 | 6 |
| 7 #include "vm/isolate.h" | 7 #include "vm/isolate.h" |
| 8 #include "vm/lockers.h" | 8 #include "vm/lockers.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 Thread* ThreadRegistry::Schedule(Isolate* isolate, | 69 Thread* ThreadRegistry::Schedule(Isolate* isolate, |
| 70 bool is_mutator, | 70 bool is_mutator, |
| 71 bool bypass_safepoint) { | 71 bool bypass_safepoint) { |
| 72 MonitorLocker ml(monitor_); | 72 MonitorLocker ml(monitor_); |
| 73 // Wait for any rendezvous in progress. | 73 // Wait for any rendezvous in progress. |
| 74 while (!bypass_safepoint && in_rendezvous_) { | 74 while (!bypass_safepoint && in_rendezvous_) { |
| 75 ml.Wait(Monitor::kNoTimeout); | 75 ml.Wait(Monitor::kNoTimeout); |
| 76 } | 76 } |
| 77 Thread* thread = NULL; | 77 Thread* thread = NULL; |
| 78 OSThread* os_thread = OSThread::Current(); | 78 OSThread* os_thread = OSThread::Current(); |
| 79 ASSERT(os_thread != NULL); | 79 if (os_thread != NULL) { |
| 80 ASSERT(isolate->heap() != NULL); | 80 ASSERT(isolate->heap() != NULL); |
| 81 // First get a Thread structure. (we special case the mutator thread | 81 // First get a Thread structure. (we special case the mutator thread |
| 82 // by reusing the cached structure, see comment in 'thread_registry.h'). | 82 // by reusing the cached structure, see comment in 'thread_registry.h'). |
| 83 if (is_mutator) { | 83 if (is_mutator) { |
| 84 if (mutator_thread_ == NULL) { | 84 if (mutator_thread_ == NULL) { |
| 85 mutator_thread_ = GetThreadFromFreelist(isolate); | 85 mutator_thread_ = GetThreadFromFreelist(isolate); |
| 86 } |
| 87 thread = mutator_thread_; |
| 88 } else { |
| 89 thread = GetThreadFromFreelist(isolate); |
| 90 ASSERT(thread->api_top_scope() == NULL); |
| 86 } | 91 } |
| 87 thread = mutator_thread_; | 92 // Now add this Thread to the active list for the isolate. |
| 88 } else { | 93 AddThreadToActiveList(thread); |
| 89 thread = GetThreadFromFreelist(isolate); | 94 // Set up other values and set the TLS value. |
| 90 ASSERT(thread->api_top_scope() == NULL); | 95 thread->isolate_ = isolate; |
| 96 thread->heap_ = isolate->heap(); |
| 97 thread->set_os_thread(os_thread); |
| 98 os_thread->set_thread(thread); |
| 99 Thread::SetCurrent(thread); |
| 100 os_thread->EnableThreadInterrupts(); |
| 91 } | 101 } |
| 92 // Now add this Thread to the active list for the isolate. | |
| 93 AddThreadToActiveList(thread); | |
| 94 // Set up other values and set the TLS value. | |
| 95 thread->isolate_ = isolate; | |
| 96 thread->heap_ = isolate->heap(); | |
| 97 thread->set_os_thread(os_thread); | |
| 98 os_thread->set_thread(thread); | |
| 99 Thread::SetCurrent(thread); | |
| 100 os_thread->EnableThreadInterrupts(); | |
| 101 return thread; | 102 return thread; |
| 102 } | 103 } |
| 103 | 104 |
| 104 | 105 |
| 105 void ThreadRegistry::Unschedule(Thread* thread, | 106 void ThreadRegistry::Unschedule(Thread* thread, |
| 106 bool is_mutator, | 107 bool is_mutator, |
| 107 bool bypass_safepoint) { | 108 bool bypass_safepoint) { |
| 108 MonitorLocker ml(monitor_); | 109 MonitorLocker ml(monitor_); |
| 109 OSThread* os_thread = thread->os_thread(); | 110 OSThread* os_thread = thread->os_thread(); |
| 110 ASSERT(os_thread != NULL); | 111 ASSERT(os_thread != NULL); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 intptr_t count = 0; | 238 intptr_t count = 0; |
| 238 Thread* current = active_list_; | 239 Thread* current = active_list_; |
| 239 while (current != NULL) { | 240 while (current != NULL) { |
| 240 ++count; | 241 ++count; |
| 241 current = current->next_; | 242 current = current->next_; |
| 242 } | 243 } |
| 243 return count; | 244 return count; |
| 244 } | 245 } |
| 245 | 246 |
| 246 } // namespace dart | 247 } // namespace dart |
| OLD | NEW |