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 "concurrent_adapter.h"
17
18 namespace DistributedDB {
ScheduleTask(const TaskAction & action,Dependence inDeps,Dependence outDeps)19 int ConcurrentAdapter::ScheduleTask(const TaskAction &action, Dependence inDeps, Dependence outDeps)
20 {
21 #ifdef USE_FFRT
22 if (inDeps == nullptr && outDeps == nullptr) {
23 ffrt::submit(action);
24 } else if (inDeps == nullptr) {
25 ffrt::submit(action, {}, { outDeps });
26 } else if (outDeps == nullptr) {
27 ffrt::submit(action, { inDeps }, {});
28 } else {
29 ffrt::submit(action, { inDeps }, { outDeps });
30 }
31 return E_OK;
32 #else
33 return RuntimeContext::GetInstance()->ScheduleTask(action);
34 #endif
35 }
36
ScheduleTaskH(const TaskAction & action,Dependence inDeps,Dependence outDeps)37 TaskHandle ConcurrentAdapter::ScheduleTaskH(const TaskAction &action, Dependence inDeps, Dependence outDeps)
38 {
39 #ifdef USE_FFRT
40 if (inDeps == nullptr && outDeps == nullptr) {
41 return ffrt::submit_h(action);
42 } else if (inDeps == nullptr) {
43 return ffrt::submit_h(action, {}, { outDeps });
44 } else if (outDeps == nullptr) {
45 return ffrt::submit_h(action, { inDeps }, {});
46 } else {
47 return ffrt::submit_h(action, { inDeps }, { outDeps });
48 }
49 #else
50 (void)action();
51 return 0;
52 #endif
53 }
54 }