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

Unified Diff: runtime/vm/lockers.cc

Issue 1751913003: Check for Thread::Current being non NULL as in some situations (shutdown) it could be NULL. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/lockers.cc
diff --git a/runtime/vm/lockers.cc b/runtime/vm/lockers.cc
index 8eddc7390f3f20aa06bb4b8e78ced906ac3c4463..2efe2458b927339fe57752d3eb575565b2f39198 100644
--- a/runtime/vm/lockers.cc
+++ b/runtime/vm/lockers.cc
@@ -57,11 +57,15 @@ SafepointMutexLocker::SafepointMutexLocker(Mutex* mutex) : mutex_(mutex) {
// We did not get the lock and could potentially block, so transition
// accordingly.
Thread* thread = Thread::Current();
- thread->set_execution_state(Thread::kThreadInBlockedState);
- thread->EnterSafepoint();
- mutex->Lock();
- // Update thread state and block if a safepoint operation is in progress.
- updateThreadState(thread);
+ if (thread != NULL) {
+ thread->set_execution_state(Thread::kThreadInBlockedState);
+ thread->EnterSafepoint();
+ mutex->Lock();
+ // Update thread state and block if a safepoint operation is in progress.
+ updateThreadState(thread);
+ } else {
+ mutex->Lock();
+ }
}
}
@@ -73,36 +77,44 @@ SafepointMonitorLocker::SafepointMonitorLocker(Monitor* monitor)
// We did not get the lock and could potentially block, so transition
// accordingly.
Thread* thread = Thread::Current();
- thread->set_execution_state(Thread::kThreadInBlockedState);
- thread->EnterSafepoint();
- monitor_->Enter();
- // Update thread state and block if a safepoint operation is in progress.
- updateThreadState(thread);
+ if (thread != NULL) {
+ thread->set_execution_state(Thread::kThreadInBlockedState);
+ thread->EnterSafepoint();
+ monitor_->Enter();
+ // Update thread state and block if a safepoint operation is in progress.
+ updateThreadState(thread);
+ } else {
+ monitor_->Enter();
+ }
}
}
Monitor::WaitResult SafepointMonitorLocker::Wait(int64_t millis) {
Thread* thread = Thread::Current();
- thread->set_execution_state(Thread::kThreadInBlockedState);
- thread->EnterSafepoint();
- Monitor::WaitResult result = monitor_->Wait(millis);
- // First try a fast update of the thread state to indicate it is not at a
- // safepoint anymore.
- uword old_state = Thread::SetAtSafepoint(true, 0);
- uword addr =
- reinterpret_cast<uword>(thread) + Thread::safepoint_state_offset();
- if (AtomicOperations::CompareAndSwapWord(
- reinterpret_cast<uword*>(addr), old_state, 0) != old_state) {
- // Fast update failed which means we could potentially be in the middle
- // of a safepoint operation and need to block for it.
- monitor_->Exit();
- SafepointHandler* handler = thread->isolate()->safepoint_handler();
- handler->ExitSafepointUsingLock(thread);
- monitor_->Enter();
+ if (thread != NULL) {
+ thread->set_execution_state(Thread::kThreadInBlockedState);
+ thread->EnterSafepoint();
+ Monitor::WaitResult result = monitor_->Wait(millis);
+ // First try a fast update of the thread state to indicate it is not at a
+ // safepoint anymore.
+ uword old_state = Thread::SetAtSafepoint(true, 0);
+ uword addr =
+ reinterpret_cast<uword>(thread) + Thread::safepoint_state_offset();
+ if (AtomicOperations::CompareAndSwapWord(
+ reinterpret_cast<uword*>(addr), old_state, 0) != old_state) {
+ // Fast update failed which means we could potentially be in the middle
+ // of a safepoint operation and need to block for it.
+ monitor_->Exit();
+ SafepointHandler* handler = thread->isolate()->safepoint_handler();
+ handler->ExitSafepointUsingLock(thread);
+ monitor_->Enter();
+ }
+ thread->set_execution_state(Thread::kThreadInVM);
+ return result;
+ } else {
+ return monitor_->Wait(millis);
}
- thread->set_execution_state(Thread::kThreadInVM);
- return result;
}
} // namespace dart
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698