• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 "common/include/task_scheduler.h"
17 
18 #include "window_manager_hilog.h"
19 
20 namespace OHOS::Rosen {
21 namespace {
22 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "TaskScheduler" };
23 }
24 
TaskScheduler(const std::string & threadName)25 TaskScheduler::TaskScheduler(const std::string& threadName)
26 {
27     auto runner = AppExecFwk::EventRunner::Create(threadName);
28     handler_ = std::make_shared<AppExecFwk::EventHandler>(runner);
29 }
30 
GetEventHandler()31 std::shared_ptr<AppExecFwk::EventHandler> TaskScheduler::GetEventHandler()
32 {
33     return handler_;
34 }
35 
PostVoidSyncTask(Task task)36 void TaskScheduler::PostVoidSyncTask(Task task)
37 {
38     if (handler_ == nullptr) {
39         WLOGFE("Failed to post task, handler is null!");
40         return;
41     }
42     handler_->PostSyncTask(std::move(task), AppExecFwk::EventQueue::Priority::IMMEDIATE);
43 }
44 
PostAsyncTask(Task task,int64_t delayTime)45 void TaskScheduler::PostAsyncTask(Task task, int64_t delayTime)
46 {
47     if (handler_ == nullptr) {
48         WLOGFE("Failed to post task, handler is null!");
49         return;
50     }
51     handler_->PostTask(std::move(task), delayTime, AppExecFwk::EventQueue::Priority::IMMEDIATE);
52 }
53 } // namespace OHOS::Rosen
54