mirror of
https://github.com/dart-lang/sdk
synced 2024-10-04 19:18:27 +00:00
[vm/concurrency] Allow calling SafepointRwLock::IsCurrentThreadReader() inside safepoint operation scope
Currently `IsCurrentThreadReader()` can only be called outside safepoint operations. We'll loosen that restriction for future CLs which require calling this method inside safepoint operations. Change-Id: I23a99cc535df47c1dbd41f92e29e669e7ddd921f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170685 Reviewed-by: Alexander Aprelev <aam@google.com> Commit-Queue: Martin Kustermann <kustermann@google.com>
This commit is contained in:
parent
466f2fd8a7
commit
391bc8d33d
|
@ -322,11 +322,11 @@ class SafepointRwLock {
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
bool IsCurrentThreadReader() {
|
bool IsCurrentThreadReader() {
|
||||||
SafepointMonitorLocker ml(&monitor_);
|
|
||||||
ThreadId id = OSThread::GetCurrentThreadId();
|
ThreadId id = OSThread::GetCurrentThreadId();
|
||||||
if (IsCurrentThreadWriter()) {
|
if (IsCurrentThreadWriter()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
MutexLocker ml(&reader_ids_mutex_);
|
||||||
for (intptr_t i = readers_ids_.length() - 1; i >= 0; i--) {
|
for (intptr_t i = readers_ids_.length() - 1; i >= 0; i--) {
|
||||||
if (readers_ids_.At(i) == id) {
|
if (readers_ids_.At(i) == id) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -356,7 +356,10 @@ class SafepointRwLock {
|
||||||
ml.Wait();
|
ml.Wait();
|
||||||
}
|
}
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
|
{
|
||||||
|
MutexLocker ml(&reader_ids_mutex_);
|
||||||
readers_ids_.Add(OSThread::GetCurrentThreadId());
|
readers_ids_.Add(OSThread::GetCurrentThreadId());
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
++state_;
|
++state_;
|
||||||
return true;
|
return true;
|
||||||
|
@ -365,6 +368,8 @@ class SafepointRwLock {
|
||||||
SafepointMonitorLocker ml(&monitor_);
|
SafepointMonitorLocker ml(&monitor_);
|
||||||
ASSERT(state_ > 0);
|
ASSERT(state_ > 0);
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
|
{
|
||||||
|
MutexLocker ml(&reader_ids_mutex_);
|
||||||
intptr_t i = readers_ids_.length() - 1;
|
intptr_t i = readers_ids_.length() - 1;
|
||||||
ThreadId id = OSThread::GetCurrentThreadId();
|
ThreadId id = OSThread::GetCurrentThreadId();
|
||||||
while (i >= 0) {
|
while (i >= 0) {
|
||||||
|
@ -375,6 +380,7 @@ class SafepointRwLock {
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
ASSERT(i >= 0);
|
ASSERT(i >= 0);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (--state_ == 0) {
|
if (--state_ == 0) {
|
||||||
ml.NotifyAll();
|
ml.NotifyAll();
|
||||||
|
@ -411,6 +417,7 @@ class SafepointRwLock {
|
||||||
intptr_t state_ = 0;
|
intptr_t state_ = 0;
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
|
Mutex reader_ids_mutex_;
|
||||||
MallocGrowableArray<ThreadId> readers_ids_;
|
MallocGrowableArray<ThreadId> readers_ids_;
|
||||||
#endif
|
#endif
|
||||||
ThreadId writer_id_ = OSThread::kInvalidThreadId;
|
ThreadId writer_id_ = OSThread::kInvalidThreadId;
|
||||||
|
|
Loading…
Reference in a new issue