• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2024 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 #ifndef PANDA_RUNTIME_SINGLE_THREAD_MANAGER_H
16 #define PANDA_RUNTIME_SINGLE_THREAD_MANAGER_H
17 
18 #include "runtime/thread_manager.h"
19 
20 namespace ark {
21 class SingleThreadManager : public ThreadManager {
22 public:
23     NO_COPY_SEMANTIC(SingleThreadManager);
24     NO_MOVE_SEMANTIC(SingleThreadManager);
25 
26     SingleThreadManager() = default;
27 
28     ~SingleThreadManager() override = default;
29 
WaitForDeregistration()30     void WaitForDeregistration() override {}
31 
SuspendAllThreads()32     void SuspendAllThreads() override
33     {
34         ManagedThread *mainThread = GetMainThread();
35         if (Thread::GetCurrent() != mainThread) {
36             mainThread->SuspendImpl(true);
37         }
38     }
39 
ResumeAllThreads()40     void ResumeAllThreads() override
41     {
42         ManagedThread *mainThread = GetMainThread();
43         if (Thread::GetCurrent() != mainThread) {
44             mainThread->ResumeImpl(true);
45         }
46     }
47 
IsRunningThreadExist()48     bool IsRunningThreadExist() override
49     {
50         ManagedThread *mainThread = GetMainThread();
51         if (Thread::GetCurrent() != mainThread) {
52             if (mainThread->GetStatus() == ThreadStatus::RUNNING) {
53                 return true;
54             }
55         }
56         return false;
57     }
58 
59 protected:
EnumerateThreadsImpl(const Callback & cb,unsigned int incMask,unsigned int xorMask)60     bool EnumerateThreadsImpl(const Callback &cb, [[maybe_unused]] unsigned int incMask,
61                               [[maybe_unused]] unsigned int xorMask) const override
62     {
63         return cb(GetMainThread());
64     }
65 };
66 }  // namespace ark
67 
68 #endif  // PANDA_RUNTIME_SINGLE_THREAD_MANAGER_H
69