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 "ffrt_task_handler_wrap.h"
17 #include "hilog_wrapper.h"
18
19 namespace OHOS {
20 namespace AAFwk {
SubmitTaskInner(std::function<void ()> && task,const TaskAttribute & taskAttr)21 std::shared_ptr<InnerTaskHandle> FfrtTaskHandlerWrap::SubmitTaskInner(std::function<void()> &&task,
22 const TaskAttribute &taskAttr)
23 {
24 if (taskAttr.IsDefault()) {
25 return std::make_shared<InnerTaskHandle>(ffrt::submit_h(std::move(task)));
26 } else {
27 ffrt::task_attr ffrtTaskAttr;
28 BuildFfrtTaskAttr(taskAttr, ffrtTaskAttr);
29 return std::make_shared<InnerTaskHandle>(ffrt::submit_h(std::move(task),
30 {}, {}, ffrtTaskAttr));
31 }
32 }
33
CancelTaskInner(const std::shared_ptr<InnerTaskHandle> & taskHandle)34 bool FfrtTaskHandlerWrap::CancelTaskInner(const std::shared_ptr<InnerTaskHandle> &taskHandle)
35 {
36 if (!taskHandle) {
37 return false;
38 }
39 return ffrt::skip(taskHandle->GetFfrtHandle()) == 0;
40 }
41
WaitTaskInner(const std::shared_ptr<InnerTaskHandle> & taskHandle)42 void FfrtTaskHandlerWrap::WaitTaskInner(const std::shared_ptr<InnerTaskHandle> &taskHandle)
43 {
44 if (!taskHandle) {
45 return;
46 }
47 ffrt::wait({taskHandle->GetFfrtHandle()});
48 }
49 } // namespace AAFwk
50 } // namespace OHOS