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 "pipeline/rs_task_dispatcher.h"
17 #include "platform/common/rs_log.h"
18 
19 namespace OHOS {
20 namespace Rosen {
GetInstance()21 RSTaskDispatcher& RSTaskDispatcher::GetInstance()
22 {
23     static RSTaskDispatcher instance;
24     return instance;
25 }
26 
RegisterTaskDispatchFunc(pid_t tid,const std::function<void (RSTask,bool)> & taskDispatchFunc)27 void RSTaskDispatcher::RegisterTaskDispatchFunc(pid_t tid, const std::function<void(RSTask, bool)>& taskDispatchFunc)
28 {
29     if (taskDispatchFunc) {
30         taskDispatchFuncMap_.emplace(tid, taskDispatchFunc);
31     }
32 }
33 
PostTask(pid_t tid,const RSTask & task,bool isSyncTask)34 void RSTaskDispatcher::PostTask(pid_t tid, const RSTask& task, bool isSyncTask)
35 {
36     if (taskDispatchFuncMap_.count(tid)) {
37         taskDispatchFuncMap_.at(tid)(task, isSyncTask);
38     } else {
39         if (task) {
40             task();
41         }
42     }
43 }
44 
HasRegisteredTask(pid_t tid) const45 bool RSTaskDispatcher::HasRegisteredTask(pid_t tid) const
46 {
47     if (taskDispatchFuncMap_.count(tid)) {
48         return true;
49     }
50     return false;
51 }
52 } // namespace Rosen
53 } // namespace OHOS
54