mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 23:09:48 +00:00
[vm] Never enter a safepoint under a regular MutexLocker.
Change-Id: Ice7ff95c91e068bd3c494d853d0047612c337b3f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134563 Commit-Queue: Ryan Macnak <rmacnak@google.com> Reviewed-by: Alexander Aprelev <aam@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
parent
4f35a405ff
commit
41cef5f82f
|
@ -45,21 +45,20 @@ const bool kDontAssertNoSafepointScope = false;
|
|||
*/
|
||||
class MutexLocker : public ValueObject {
|
||||
public:
|
||||
explicit MutexLocker(Mutex* mutex, bool no_safepoint_scope = true)
|
||||
explicit MutexLocker(Mutex* mutex)
|
||||
:
|
||||
#if defined(DEBUG)
|
||||
no_safepoint_scope_(no_safepoint_scope),
|
||||
no_safepoint_scope_(true),
|
||||
#endif
|
||||
mutex_(mutex) {
|
||||
ASSERT(mutex != NULL);
|
||||
ASSERT(mutex != nullptr);
|
||||
#if defined(DEBUG)
|
||||
if (no_safepoint_scope_) {
|
||||
Thread* thread = Thread::Current();
|
||||
if (thread != NULL) {
|
||||
thread->IncrementNoSafepointScopeDepth();
|
||||
} else {
|
||||
no_safepoint_scope_ = false;
|
||||
}
|
||||
Thread* thread = Thread::Current();
|
||||
if ((thread != nullptr) &&
|
||||
(thread->execution_state() != Thread::kThreadInNative)) {
|
||||
thread->IncrementNoSafepointScopeDepth();
|
||||
} else {
|
||||
no_safepoint_scope_ = false;
|
||||
}
|
||||
#endif
|
||||
mutex_->Lock();
|
||||
|
|
|
@ -366,7 +366,7 @@ void ThreadLocalData::AddThreadLocal(ThreadLocalKey key,
|
|||
// We only care about thread locals with destructors.
|
||||
return;
|
||||
}
|
||||
MutexLocker ml(mutex_, false);
|
||||
MutexLocker ml(mutex_);
|
||||
#if defined(DEBUG)
|
||||
// Verify that we aren't added twice.
|
||||
for (intptr_t i = 0; i < thread_locals_->length(); i++) {
|
||||
|
@ -380,7 +380,7 @@ void ThreadLocalData::AddThreadLocal(ThreadLocalKey key,
|
|||
|
||||
void ThreadLocalData::RemoveThreadLocal(ThreadLocalKey key) {
|
||||
ASSERT(thread_locals_ != NULL);
|
||||
MutexLocker ml(mutex_, false);
|
||||
MutexLocker ml(mutex_);
|
||||
intptr_t i = 0;
|
||||
for (; i < thread_locals_->length(); i++) {
|
||||
const ThreadLocalEntry& entry = thread_locals_->At(i);
|
||||
|
@ -405,7 +405,7 @@ void ThreadLocalData::RunDestructors() {
|
|||
return;
|
||||
}
|
||||
ASSERT(mutex_ != NULL);
|
||||
MutexLocker ml(mutex_, false);
|
||||
MutexLocker ml(mutex_);
|
||||
for (intptr_t i = 0; i < thread_locals_->length(); i++) {
|
||||
const ThreadLocalEntry& entry = thread_locals_->At(i);
|
||||
// We access the exiting thread's TLS variable here.
|
||||
|
|
Loading…
Reference in a new issue