!6749 Double SuspendAllScope enter may lead to perf degradation

Merge pull request !6749 from Aleksandr Emelenko/fix-double-suspendall-scopes-enter
This commit is contained in:
openharmony_ci 2024-04-08 06:30:21 +00:00 committed by Gitee
commit 024e742dc7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 10 additions and 0 deletions

View File

@ -166,6 +166,11 @@ void Runtime::ResumeAll(JSThread *current)
void Runtime::SuspendAllThreadsImpl(JSThread *current)
{
LockHolder lock(threadsLock_);
while (suspendNewCount_ != 0) {
// Someone has already suspended all threads.
// Wait until it finishes.
threadSuspendCondVar_.Wait(&threadsLock_);
}
suspendNewCount_++;
for (auto i : threads_) {
if (i != current) {
@ -180,6 +185,10 @@ void Runtime::ResumeAllThreadsImpl(JSThread *current)
if (suspendNewCount_ > 0) {
suspendNewCount_--;
}
if (suspendNewCount_ == 0) {
// Signal to waiting to suspend threads
threadSuspendCondVar_.Signal();
}
for (auto i : threads_) {
if (i != current) {
i->ResumeThread(true);

View File

@ -161,6 +161,7 @@ private:
}
Mutex threadsLock_;
ConditionVariable threadSuspendCondVar_;
Mutex serializeLock_;
std::list<JSThread*> threads_;
uint32_t suspendNewCount_ {0};