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 #include "hpae_base/rs_hpae_perf_thread.h"
17
18 #include <unistd.h>
19 #include "hpae_base/rs_hpae_log.h"
20
21 namespace OHOS::Rosen {
22
Instance()23 RSHpaePerfThread& RSHpaePerfThread::Instance()
24 {
25 static RSHpaePerfThread instance;
26 return instance;
27 }
28
RSHpaePerfThread()29 RSHpaePerfThread::RSHpaePerfThread() : runner_(AppExecFwk::EventRunner::Create("RSHpaePerfThread"))
30 {
31 handler_ = std::make_shared<AppExecFwk::EventHandler>(runner_);
32 if (handler_) {
33 handler_->PostSyncTask([this]() {
34 #if defined(ROSEN_OHOS)
35 this->curThreadId_ = gettid();
36 #else
37 this->curThreadId_ = 0;
38 #endif
39 });
40 }
41 }
42
CreateHandler()43 std::shared_ptr<AppExecFwk::EventHandler> RSHpaePerfThread::CreateHandler()
44 {
45 return std::make_shared<AppExecFwk::EventHandler>(runner_);
46 }
47
PostTask(const std::function<void ()> & task,int64_t delayTime)48 void RSHpaePerfThread::PostTask(const std::function<void()>& task, int64_t delayTime)
49 {
50 if (handler_) {
51 handler_->PostTask(task, delayTime, AppExecFwk::EventQueue::Priority::IMMEDIATE);
52 }
53 }
54
PostSyncTask(const std::function<void ()> & task)55 void RSHpaePerfThread::PostSyncTask(const std::function<void()>& task)
56 {
57 if (handler_) {
58 handler_->PostSyncTask(task, AppExecFwk::EventQueue::Priority::IMMEDIATE);
59 }
60 }
61
62 } // OHOS::Rosen