Chromium Code Reviews| Index: runtime/vm/safepoint.h |
| diff --git a/runtime/vm/safepoint.h b/runtime/vm/safepoint.h |
| index 947742512ddad6f6991d01c183f526de79217968..3a962f8b2a9485914a8751ed979d4471ebbf6fdf 100644 |
| --- a/runtime/vm/safepoint.h |
| +++ b/runtime/vm/safepoint.h |
| @@ -317,6 +317,41 @@ class TransitionToGenerated : public TransitionSafepointState { |
| DISALLOW_COPY_AND_ASSIGN(TransitionToGenerated); |
| }; |
| + |
| +// TransitionToVM is used to transition the safepoint state of a |
| +// thread from "running native code" to "running vm code" |
| +// and ensures that the state is reverted back to "running native code" |
| +// when exiting the scope/frame. |
| +// This transition helper is mainly used in the error path of the |
| +// Dart API implementations where we sometimes do not have an explicit |
| +// transition set up. |
| +class TransitionToVM : public TransitionSafepointState { |
| + public: |
| + explicit TransitionToVM(Thread* T) : TransitionSafepointState(T), |
| + execution_state_(T->execution_state()) { |
| + ASSERT(T == Thread::Current()); |
| + ASSERT((execution_state_ == Thread::kThreadInVM) || |
| + (execution_state_ == Thread::kThreadInNative)); |
| + if (execution_state_ == Thread::kThreadInNative) { |
| + T->ExitSafepoint(); |
| + T->set_execution_state(Thread::kThreadInVM); |
| + } |
| + ASSERT(T->execution_state() == Thread::kThreadInVM); |
| + } |
| + |
| + ~TransitionToVM() { |
| + ASSERT(thread()->execution_state() == Thread::kThreadInVM); |
| + if (execution_state_ == Thread::kThreadInNative) { |
| + thread()->set_execution_state(Thread::kThreadInNative); |
| + thread()->EnterSafepoint(); |
| + } |
| + } |
| + |
| + private: |
| + int16_t execution_state_; |
|
rmacnak
2016/05/27 20:08:29
In Thread this is uint32_t.
siva
2016/05/27 20:53:16
Done.
|
| + DISALLOW_COPY_AND_ASSIGN(TransitionToVM); |
| +}; |
| + |
| } // namespace dart |
| #endif // VM_SAFEPOINT_H_ |