• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 HPAE_BASE_RS_HPAE_PERF_THREAD_H
17 #define HPAE_BASE_RS_HPAE_PERF_THREAD_H
18 
19 #include <future>
20 #include <thread>
21 #include <unordered_map>
22 #include <unordered_set>
23 #include "event_handler.h"
24 #include "refbase.h"
25 
26 namespace OHOS::Rosen {
27 
28 // reference: HgmTaskHandleThread
29 class RSHpaePerfThread {
30 public:
31     static RSHpaePerfThread& Instance();
GetRunner()32     const std::shared_ptr<AppExecFwk::EventRunner>& GetRunner() const { return runner_; }
33     std::shared_ptr<AppExecFwk::EventHandler> CreateHandler();
34     void PostTask(const std::function<void()>& task, int64_t delayTime = 0);
35     void PostSyncTask(const std::function<void()>& task);
36 
37 private:
38     RSHpaePerfThread();
39     ~RSHpaePerfThread() = default;
40     RSHpaePerfThread(const RSHpaePerfThread&);
41     RSHpaePerfThread(const RSHpaePerfThread&&);
42     RSHpaePerfThread& operator=(const RSHpaePerfThread&);
43     RSHpaePerfThread& operator=(const RSHpaePerfThread&&);
44 
45     std::shared_ptr<AppExecFwk::EventRunner> runner_ = nullptr;
46     std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr;
47     int32_t curThreadId_ = -1;
48 };
49 
50 } // OHOS::Rosen
51 
52 #endif // HPAE_BASE_RS_HPAE_PERF_THREAD_H