• 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 "dm/dependence_manager.h"
17 #include "util/ffrt_facade.h"
18 #include "util/singleton_register.h"
19 #include "tm/io_task.h"
20 #include "tm/uv_task.h"
21 
22 namespace ffrt {
Instance()23 DependenceManager& DependenceManager::Instance()
24 {
25     return SingletonRegister<DependenceManager>::Instance();
26 }
27 
RegistInsCb(SingleInsCB<DependenceManager>::Instance && cb)28 void DependenceManager::RegistInsCb(SingleInsCB<DependenceManager>::Instance &&cb)
29 {
30     SingletonRegister<DependenceManager>::RegistInsCb(std::move(cb));
31 }
32 
onSubmitUV(ffrt_executor_task_t * task,const task_attr_private * attr)33 void DependenceManager::onSubmitUV(ffrt_executor_task_t *task, const task_attr_private *attr)
34 {
35     FFRT_TRACE_SCOPE(1, onSubmitUV);
36     UVTask* uvTask = TaskFactory<UVTask>::Alloc();
37     new(uvTask) UVTask(task, attr);
38     FFRT_EXECUTOR_TASK_SUBMIT_MARKER(uvTask->gid);
39     uvTask->Ready();
40 }
41 
onSubmitIO(const ffrt_io_callable_t & work,const task_attr_private * attr)42 void DependenceManager::onSubmitIO(const ffrt_io_callable_t& work, const task_attr_private* attr)
43 {
44     FFRT_TRACE_SCOPE(1, onSubmitIO);
45     IOTask* ioTask = TaskFactory<IOTask>::Alloc();
46     new (ioTask) IOTask(work, attr);
47     ioTask->Ready();
48 }
49 
onSkip(ffrt_task_handle_t handle)50 int DependenceManager::onSkip(ffrt_task_handle_t handle)
51 {
52     ffrt::CPUEUTask *task = static_cast<ffrt::CPUEUTask*>(handle);
53     if (task->type == ffrt_queue_task) {
54         FFRT_LOGE("use ffrt::queue::cancel instead of ffrt::skip for canceling queue task");
55         return ffrt_error;
56     }
57 
58     auto exp = ffrt::SkipStatus::SUBMITTED;
59     if (__atomic_compare_exchange_n(&task->skipped, &exp, ffrt::SkipStatus::SKIPPED, 0, __ATOMIC_ACQUIRE,
60         __ATOMIC_RELAXED)) {
61         task->Cancel();
62         return ffrt_success;
63     }
64     FFRT_LOGD("skip task [%lu] faild", task->gid);
65     return ffrt_error;
66 }
67 } // namespace ffrt