• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ECMASCRIPT_VM_THREAD_CONTROL_H
17 #define ECMASCRIPT_VM_THREAD_CONTROL_H
18 
19 #include "ecmascript/js_thread.h"
20 #include "libpandabase/os/mutex.h"
21 #include "libpandabase/utils/bit_field.h"
22 
23 namespace panda::ecmascript {
24 class VmThreadControl {
25 public:
26     static constexpr char VM_NEED_SUSPENSION = 1;
27 
VmThreadControl(JSThread * thread)28     VmThreadControl(JSThread *thread)
29     {
30         thread_ = thread;
31     }
32 
33     void SetVMNeedSuspension(bool flag);
34 
35     bool VMNeedSuspension() const;
36 
37     void SuspendVM();
38 
39     void ResumeVM();
40 
41     bool NotifyVMThreadSuspension();
42 
43     void SetVMSuspended(bool flag);
44 
45     bool IsSuspended() const;
46 
47 private:
48     JSThread *thread_;
49     os::memory::Mutex vmThreadSuspensionMutex_;
50     os::memory::ConditionVariable vmThreadNeedSuspensionCV_;
51     os::memory::ConditionVariable vmThreadHasSuspendedCV_;
52 };
53 } // namespace panda::ecmascript
54 #endif  // ECMASCRIPT_VM_THREAD_CONTROL_H