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

Unified Diff: runtime/vm/safepoint.h

Issue 2018673003: Fix for issue 26511 (VM hangs waiting for all threads that are not already at (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-review-comments Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
« runtime/vm/dart_api_impl.cc ('K') | « runtime/vm/lockers.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_
« runtime/vm/dart_api_impl.cc ('K') | « runtime/vm/lockers.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698