• 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 #ifndef _IO_TASK_H_
16 #define _IO_TASK_H_
17 
18 #include "task_base.h"
19 #include "core/task_io.h"
20 #include "core/task_attr_private.h"
21 #include "tm/task_factory.h"
22 #include "util/ffrt_facade.h"
23 
24 namespace ffrt {
25 class IOTask : public TaskBase {
26 public:
27     IOTask(const ffrt_io_callable_t& work, const task_attr_private* attr);
28 
Prepare()29     void Prepare() override {}
30 
Ready()31     void Ready() override
32     {
33         QoS taskQos = qos_;
34         FFRTTraceRecord::TaskSubmit<ffrt_io_task>(taskQos);
35         SetStatus(TaskStatus::READY);
36         FFRTFacade::GetSchedInstance()->GetScheduler(taskQos).PushTaskGlobal(this);
37         FFRTTraceRecord::TaskEnqueue<ffrt_io_task>(taskQos);
38         FFRTFacade::GetEUInstance().NotifyTask<TaskNotifyType::TASK_LOCAL>(taskQos);
39     }
40 
Pop()41     void Pop() override
42     {
43         SetStatus(TaskStatus::POPPED);
44     }
45 
46     void Execute() override;
47 
Block()48     BlockType Block() override
49     {
50         SetStatus(TaskStatus::THREAD_BLOCK);
51         return BlockType::BLOCK_THREAD;
52     }
53 
Wake()54     void Wake() override
55     {
56         SetStatus(TaskStatus::EXECUTING);
57     }
58 
Finish()59     void Finish() override {}
Cancel()60     void Cancel() override {}
61 
FreeMem()62     void FreeMem() override
63     {
64         TaskFactory<IOTask>::Free(this);
65     }
66 
SetQos(const QoS & newQos)67     void SetQos(const QoS& newQos) override
68     {
69         qos_ = newQos;
70     }
71 
GetLabel()72     std::string GetLabel() const override
73     {
74         return "io-task";
75     }
76 
GetBlockType()77     BlockType GetBlockType() const override
78     {
79         return BlockType::BLOCK_THREAD;
80     }
81 
82 private:
83     ffrt_io_callable_t work;
84 };
85 } /* namespace ffrt */
86 #endif
87