Files
xujie 479b7c3785 Clean Code For CodeHub Issues #96-#123 And #250-#264
According to the problems pointed out by the issuer and the
specifications compiled by Huawei, modify the non-compliant
parts of jsruntime.

Issue:https://gitee.com/openharmony/ark_js_runtime/issues/I4YLCQ

Signed-off-by: xujie <xujie101@huawei.com>
Change-Id: Iceb771dfd9f3aa9017205068fc50ab1a63aae08b
2022-03-21 17:09:19 +08:00

49 lines
1.6 KiB
C++

/*
* Copyright (c) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ecmascript/dfx/vm_thread_control.h"
namespace panda::ecmascript {
bool VmThreadControl::NotifyVMThreadSuspension() // block caller thread
{
if (VMNeedSuspension()) { // only enable one thread to post suspension
return false;
}
SetVMNeedSuspension(true);
os::memory::LockHolder lock(vmThreadSuspensionMutex_);
while (!IsSuspended()) {
vmThreadNeedSuspensionCV_.Wait(&vmThreadSuspensionMutex_);
}
return true;
}
void VmThreadControl::SuspendVM() // block vm thread
{
os::memory::LockHolder lock(vmThreadSuspensionMutex_);
SetVMSuspended(true);
vmThreadNeedSuspensionCV_.Signal(); // wake up the thread who needs suspend vmthread
while (VMNeedSuspension()) {
vmThreadHasSuspendedCV_.Wait(&vmThreadSuspensionMutex_);
}
SetVMSuspended(false);
}
void VmThreadControl::ResumeVM()
{
os::memory::LockHolder lock(vmThreadSuspensionMutex_);
SetVMNeedSuspension(false);
vmThreadHasSuspendedCV_.Signal();
}
} // namespace panda::ecmascript