[Suspend/Resume] Fix a perf issue during entering SuspendAllScope in two threads.

Now the thread under the SuspendAllScope doesn't have any suspend request.
Issue: #I9DCIT

Signed-off-by: Aleksandr Emelenko <emelenko.aleksandr@huawei.com>
Change-Id: I35571b4626ee0a97502b59d62841b4dc3df0ddf6
This commit is contained in:
Aleksandr Emelenko 2024-04-01 17:11:59 +08:00
parent 73565e8975
commit a501d4dd52
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};