OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 #include "platform/assert.h" |
| 6 #include "vm/lockers.h" |
| 7 #include "vm/safepoint.h" |
| 8 |
| 9 namespace dart { |
| 10 |
| 11 |
| 12 Monitor::WaitResult MonitorLocker::WaitWithSafepointCheck(Thread* thread, |
| 13 int64_t millis) { |
| 14 ASSERT(thread == Thread::Current()); |
| 15 thread->set_execution_state(Thread::kThreadInBlockedState); |
| 16 thread->EnterSafepoint(); |
| 17 Monitor::WaitResult result = monitor_->Wait(millis); |
| 18 // First try a fast update of the thread state to indicate it is not at a |
| 19 // safepoint anymore. |
| 20 uword old_state = Thread::SetAtSafepoint(true, 0); |
| 21 uword addr = |
| 22 reinterpret_cast<uword>(thread) + Thread::safepoint_state_offset(); |
| 23 if (AtomicOperations::CompareAndSwapWord( |
| 24 reinterpret_cast<uword*>(addr), old_state, 0) != old_state) { |
| 25 // Fast update failed which means we could potentially be in the middle |
| 26 // of a safepoint operation and need to block for it. |
| 27 monitor_->Exit(); |
| 28 SafepointHandler* handler = thread->isolate()->safepoint_handler(); |
| 29 handler->ExitSafepointUsingLock(thread); |
| 30 monitor_->Enter(); |
| 31 } |
| 32 thread->set_execution_state(Thread::kThreadInVM); |
| 33 return result; |
| 34 } |
| 35 |
| 36 |
| 37 } // namespace dart |
OLD | NEW |