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 "io_task.h" 17 #include "dfx/trace_record/ffrt_trace_record.h" 18 #include "dfx/trace/ffrt_trace.h" 19 #include "dfx/bbox/bbox.h" 20 #include "tm/task_factory.h" 21 22 namespace ffrt { IOTask(const ffrt_io_callable_t & work,const task_attr_private * attr)23IOTask::IOTask(const ffrt_io_callable_t& work, const task_attr_private* attr) : work(work) 24 { 25 this->type = ffrt_io_task; 26 this->qos_ = (attr == nullptr || attr->qos_ == qos_inherit) ? QoS() 27 : QoS(attr->qos_); 28 fq_we.task = reinterpret_cast<CPUEUTask*>(this); 29 } 30 FreeMem()31void IOTask::FreeMem() 32 { 33 TaskFactory<IOTask>::Free(this); 34 } 35 Execute()36void IOTask::Execute() 37 { 38 FFRTTraceRecord::TaskExecute<ffrt_io_task>(qos_); 39 FFRT_EXECUTOR_TASK_BEGIN(this); 40 status = ExecTaskStatus::ET_EXECUTING; 41 ffrt_coroutine_ptr_t coroutine = work.exec; 42 ffrt_coroutine_ret_t ret = coroutine(work.data); 43 if (ret == ffrt_coroutine_ready) { 44 status = ExecTaskStatus::ET_FINISH; 45 work.destroy(work.data); 46 DecDeleteRef(); 47 FFRT_EXECUTOR_TASK_END(); 48 return; 49 } 50 FFRT_EXECUTOR_TASK_BLOCK_MARKER(this); 51 status = ExecTaskStatus::ET_PENDING; 52 #ifdef FFRT_BBOX_ENABLE 53 TaskPendingCounterInc(); 54 #endif 55 FFRT_EXECUTOR_TASK_END(); 56 FFRTTraceRecord::TaskDone<ffrt_io_task>(qos_); 57 } 58 } // namespace ffrt