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

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

Issue 1412733008: Switch profiler from isolates to threads (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months 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
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/thread.h" 5 #include "vm/thread.h"
6 6
7 #include "vm/growable_array.h" 7 #include "vm/growable_array.h"
8 #include "vm/isolate.h" 8 #include "vm/isolate.h"
9 #include "vm/lockers.h" 9 #include "vm/lockers.h"
10 #include "vm/log.h" 10 #include "vm/log.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 while (current != NULL) { 59 while (current != NULL) {
60 ASSERT(current != thread); 60 ASSERT(current != thread);
61 current = current->thread_list_next_; 61 current = current->thread_list_next_;
62 } 62 }
63 } 63 }
64 #endif 64 #endif
65 65
66 // Insert at head of list. 66 // Insert at head of list.
67 thread->thread_list_next_ = thread_list_head_; 67 thread->thread_list_next_ = thread_list_head_;
68 thread_list_head_ = thread; 68 thread_list_head_ = thread;
69
70 // Make sure the thread interrupter is awake.
71 ThreadInterrupter::WakeUp();
69 } 72 }
70 73
71 74
72 void Thread::RemoveThreadFromList(Thread* thread) { 75 void Thread::RemoveThreadFromList(Thread* thread) {
73 ASSERT(thread != NULL); 76 ASSERT(thread != NULL);
74 ASSERT(thread->isolate() == NULL); 77 ASSERT(thread->isolate() == NULL);
75 ASSERT(thread_list_lock_ != NULL); 78 ASSERT(thread_list_lock_ != NULL);
76 MutexLocker ml(thread_list_lock_); 79 MutexLocker ml(thread_list_lock_);
77 80
78 // Handle case where |thread| is head of list. 81 // Handle case where |thread| is head of list.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 #endif // defined(DEBUG) 176 #endif // defined(DEBUG)
174 177
175 #define REUSABLE_HANDLE_INITIALIZERS(object) \ 178 #define REUSABLE_HANDLE_INITIALIZERS(object) \
176 object##_handle_(NULL), 179 object##_handle_(NULL),
177 180
178 181
179 Thread::Thread(bool init_vm_constants) 182 Thread::Thread(bool init_vm_constants)
180 : id_(OSThread::GetCurrentThreadId()), 183 : id_(OSThread::GetCurrentThreadId()),
181 thread_interrupt_callback_(NULL), 184 thread_interrupt_callback_(NULL),
182 thread_interrupt_data_(NULL), 185 thread_interrupt_data_(NULL),
186 thread_interrupt_disabled_(0),
183 isolate_(NULL), 187 isolate_(NULL),
184 heap_(NULL), 188 heap_(NULL),
185 timeline_block_(NULL), 189 timeline_block_(NULL),
186 store_buffer_block_(NULL), 190 store_buffer_block_(NULL),
187 log_(new class Log()), 191 log_(new class Log()),
188 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS) 192 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_INITIALIZERS)
189 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_INIT) 193 REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_SCOPE_INIT)
190 reusable_handles_(), 194 reusable_handles_(),
191 cha_(NULL), 195 cha_(NULL),
192 deopt_id_(0), 196 deopt_id_(0),
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 // Visit objects in thread specific handles area. 449 // Visit objects in thread specific handles area.
446 reusable_handles_.VisitObjectPointers(visitor); 450 reusable_handles_.VisitObjectPointers(visitor);
447 451
448 if (pending_functions_ != GrowableObjectArray::null()) { 452 if (pending_functions_ != GrowableObjectArray::null()) {
449 visitor->VisitPointer( 453 visitor->VisitPointer(
450 reinterpret_cast<RawObject**>(&pending_functions_)); 454 reinterpret_cast<RawObject**>(&pending_functions_));
451 } 455 }
452 } 456 }
453 457
454 458
459 void Thread::DisableThreadInterrupts() {
460 ASSERT(Thread::Current() == this);
461 AtomicOperations::FetchAndIncrement(&thread_interrupt_disabled_);
462 }
463
464
465 void Thread::EnableThreadInterrupts() {
466 ASSERT(Thread::Current() == this);
467 uintptr_t old =
468 AtomicOperations::FetchAndDecrement(&thread_interrupt_disabled_);
469 if (old == 1) {
470 // We just decremented from 1 to 0.
471 // Make sure the thread interrupter is awake.
472 ThreadInterrupter::WakeUp();
473 }
474 }
475
476
477 bool Thread::ThreadInterruptsEnabled() {
478 return AtomicOperations::LoadRelaxed(&thread_interrupt_disabled_) == 0;
479 }
480
481
455 void Thread::SetThreadInterrupter(ThreadInterruptCallback callback, 482 void Thread::SetThreadInterrupter(ThreadInterruptCallback callback,
456 void* data) { 483 void* data) {
457 ASSERT(Thread::Current() == this); 484 ASSERT(Thread::Current() == this);
458 thread_interrupt_callback_ = callback; 485 thread_interrupt_callback_ = callback;
459 thread_interrupt_data_ = data; 486 thread_interrupt_data_ = data;
460 } 487 }
461 488
462 489
463 bool Thread::IsThreadInterrupterEnabled(ThreadInterruptCallback* callback, 490 bool Thread::IsThreadInterrupterEnabled(ThreadInterruptCallback* callback,
464 void** data) const { 491 void** data) const {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 Thread* ThreadIterator::Next() { 570 Thread* ThreadIterator::Next() {
544 ASSERT(Thread::thread_list_lock_ != NULL); 571 ASSERT(Thread::thread_list_lock_ != NULL);
545 ASSERT(Thread::thread_list_lock_->IsOwnedByCurrentThread()); 572 ASSERT(Thread::thread_list_lock_->IsOwnedByCurrentThread());
546 Thread* current = next_; 573 Thread* current = next_;
547 next_ = next_->thread_list_next_; 574 next_ = next_->thread_list_next_;
548 return current; 575 return current;
549 } 576 }
550 577
551 578
552 } // namespace dart 579 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698