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 "tm/io_task.h" 17 #include "dfx/trace_record/ffrt_trace_record.h" 18 #include "dfx/bbox/bbox.h" 19 20 namespace ffrt { IOTask(const ffrt_io_callable_t & work,const task_attr_private * attr)21IOTask::IOTask(const ffrt_io_callable_t& work, const task_attr_private* attr) 22 : TaskBase(ffrt_io_task, attr), work(work) {} 23 Execute()24void IOTask::Execute() 25 { 26 FFRTTraceRecord::TaskExecute<ffrt_io_task>(qos_); 27 FFRT_EXECUTOR_TASK_BEGIN(gid); 28 SetStatus(TaskStatus::EXECUTING); 29 ffrt_coroutine_ptr_t coroutine = work.exec; 30 ffrt_coroutine_ret_t ret = coroutine(work.data); 31 if (ret == ffrt_coroutine_ready) { 32 SetStatus(TaskStatus::FINISH); 33 work.destroy(work.data); 34 DecDeleteRef(); 35 FFRT_TASK_END(); 36 FFRTTraceRecord::TaskDone<ffrt_io_task>(qos_); 37 return; 38 } 39 FFRT_BLOCK_MARKER(gid); 40 SetStatus(TaskStatus::PENDING); 41 #ifdef FFRT_BBOX_ENABLE 42 TaskPendingCounterInc(); 43 #endif 44 FFRT_TASK_END(); 45 FFRTTraceRecord::TaskDone<ffrt_io_task>(qos_); 46 } 47 } // namespace ffrt 48