OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 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 | 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 "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/lockers.h" | 6 #include "vm/lockers.h" |
7 #include "vm/safepoint.h" | 7 #include "vm/safepoint.h" |
8 | 8 |
9 namespace dart { | 9 namespace dart { |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 reinterpret_cast<uword*>(addr), old_state, 0) != old_state) { | 52 reinterpret_cast<uword*>(addr), old_state, 0) != old_state) { |
53 // Fast update failed which means we could potentially be in the middle | 53 // Fast update failed which means we could potentially be in the middle |
54 // of a safepoint operation and need to block for it. | 54 // of a safepoint operation and need to block for it. |
55 SafepointHandler* handler = thread->isolate()->safepoint_handler(); | 55 SafepointHandler* handler = thread->isolate()->safepoint_handler(); |
56 handler->ExitSafepointUsingLock(thread); | 56 handler->ExitSafepointUsingLock(thread); |
57 } | 57 } |
58 thread->set_execution_state(Thread::kThreadInVM); | 58 thread->set_execution_state(Thread::kThreadInVM); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 | |
63 SafepointMonitorLocker::SafepointMonitorLocker(Monitor* monitor) | |
64 : monitor_(monitor) { | |
65 ASSERT(monitor_ != NULL); | |
66 if (!monitor_->TryEnter()) { | |
67 // We did not get the lock and could potentially block, so transition | |
68 // accordingly. | |
69 Thread* thread = Thread::Current(); | |
70 thread->set_execution_state(Thread::kThreadInBlockedState); | |
71 thread->EnterSafepoint(); | |
72 monitor_->Enter(); | |
73 // First try a fast update of the thread state to indicate it is not at a | |
74 // safepoint anymore. | |
75 uword old_state = Thread::SetAtSafepoint(true, 0); | |
76 uword addr = | |
77 reinterpret_cast<uword>(thread) + Thread::safepoint_state_offset(); | |
78 if (AtomicOperations::CompareAndSwapWord( | |
79 reinterpret_cast<uword*>(addr), old_state, 0) != old_state) { | |
80 // Fast update failed which means we could potentially be in the middle | |
81 // of a safepoint operation and need to block for it. | |
82 SafepointHandler* handler = thread->isolate()->safepoint_handler(); | |
Cutch
2016/03/01 15:08:07
This 'fast update of the thread state' code is the
siva
2016/03/01 18:59:53
Done.
| |
83 handler->ExitSafepointUsingLock(thread); | |
84 } | |
85 thread->set_execution_state(Thread::kThreadInVM); | |
86 } | |
87 } | |
88 | |
89 | |
90 Monitor::WaitResult SafepointMonitorLocker::Wait(int64_t millis) { | |
91 Thread* thread = Thread::Current(); | |
92 thread->set_execution_state(Thread::kThreadInBlockedState); | |
93 thread->EnterSafepoint(); | |
94 Monitor::WaitResult result = monitor_->Wait(millis); | |
95 // First try a fast update of the thread state to indicate it is not at a | |
96 // safepoint anymore. | |
97 uword old_state = Thread::SetAtSafepoint(true, 0); | |
98 uword addr = | |
99 reinterpret_cast<uword>(thread) + Thread::safepoint_state_offset(); | |
100 if (AtomicOperations::CompareAndSwapWord( | |
101 reinterpret_cast<uword*>(addr), old_state, 0) != old_state) { | |
102 // Fast update failed which means we could potentially be in the middle | |
103 // of a safepoint operation and need to block for it. | |
104 monitor_->Exit(); | |
105 SafepointHandler* handler = thread->isolate()->safepoint_handler(); | |
106 handler->ExitSafepointUsingLock(thread); | |
107 monitor_->Enter(); | |
108 } | |
109 thread->set_execution_state(Thread::kThreadInVM); | |
110 return result; | |
111 } | |
112 | |
62 } // namespace dart | 113 } // namespace dart |
OLD | NEW |