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

Side by Side Diff: runtime/vm/lockers.cc

Issue 1717803002: Add a SafepointMutexLocker class so that it is possible to have scopes inside the MutexLocker which… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: self-code-review 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 unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
27 monitor_->Exit(); 27 monitor_->Exit();
28 SafepointHandler* handler = thread->isolate()->safepoint_handler(); 28 SafepointHandler* handler = thread->isolate()->safepoint_handler();
29 handler->ExitSafepointUsingLock(thread); 29 handler->ExitSafepointUsingLock(thread);
30 monitor_->Enter(); 30 monitor_->Enter();
31 } 31 }
32 thread->set_execution_state(Thread::kThreadInVM); 32 thread->set_execution_state(Thread::kThreadInVM);
33 return result; 33 return result;
34 } 34 }
35 35
36 36
37 SafepointMutexLocker::SafepointMutexLocker(Mutex* mutex) : mutex_(mutex) {
38 ASSERT(mutex != NULL);
39 if (!mutex_->TryLock()) {
40 // We did not get the lock and could potentially block, so transition
41 // accordingly.
42 Thread* thread = Thread::Current();
43 thread->set_execution_state(Thread::kThreadInBlockedState);
44 thread->EnterSafepoint();
45 mutex->Lock();
46 // First try a fast update of the thread state to indicate it is not at a
47 // safepoint anymore.
48 uword old_state = Thread::SetAtSafepoint(true, 0);
49 uword addr =
50 reinterpret_cast<uword>(thread) + Thread::safepoint_state_offset();
51 if (AtomicOperations::CompareAndSwapWord(
52 reinterpret_cast<uword*>(addr), old_state, 0) != old_state) {
53 // Fast update failed which means we could potentially be in the middle
54 // of a safepoint operation and need to block for it.
55 SafepointHandler* handler = thread->isolate()->safepoint_handler();
56 handler->ExitSafepointUsingLock(thread);
57 }
58 thread->set_execution_state(Thread::kThreadInVM);
59 }
60 }
61
37 } // namespace dart 62 } // namespace dart
OLDNEW
« runtime/vm/isolate.h ('K') | « runtime/vm/lockers.h ('k') | runtime/vm/symbols.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698