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  /**
17  * @file task.h
18  *
19  * @brief Declares the task inner interfaces in C++.
20  *
21  * @since 10
22  * @version 1.0
23  */
24 #ifndef FFRT_INNER_API_CPP_TASK_H
25 #define FFRT_INNER_API_CPP_TASK_H
26 #include <cstdint>
27 #include "c/task_ext.h"
28 #include "cpp/task.h"
29 
30 namespace ffrt {
31 /**
32  * @brief Skips a task.
33  *
34  * @param handle Indicates a task handle.
35  * @return Returns <b>0</b> if the task is skipped;
36            returns <b>-1</b> otherwise.
37  * @since 10
38  * @version 1.0
39  */
skip(task_handle &handle)40 static inline int skip(task_handle &handle)
41 {
42     return ffrt_skip(handle);
43 }
44 
45 void sync_io(int fd);
46 
47 void set_trace_tag(const char* name);
48 
49 void clear_trace_tag();
50 
set_cgroup_attr(qos qos_, ffrt_os_sched_attr *attr)51 static inline int set_cgroup_attr(qos qos_, ffrt_os_sched_attr *attr)
52 {
53     return ffrt_set_cgroup_attr(qos_, attr);
54 }
55 
restore_qos_config()56 static inline void restore_qos_config()
57 {
58     ffrt_restore_qos_config();
59 }
60 
61 /**
62  * @brief worker num setting.
63  *
64  * @param qosData param is default when value equal 0xffffffff.
65  * totalNum = lowQosReserveWorkerNum + highQosReserveWorkerNum + sum of all reserveNum
66  * totalNum is valid in (0,256].
67  * lowQosReserveWorkerNum is a low partition qos public resource.{[min, max], default} is {[0,256],12}.
68  * highQosReserveWorkerNum is a hight partition qos public resource.{[min, max], default} is {[0,256],12}.
69  * lowQosReserveWorkerNum is a global qos public resource.{[min, max], default} is {[0,256],24}.
70  * qosConfigArray is an array of ffrt_qos_config.
71  * effectLen: param setting will success when qosConfigArray index less than effectLen.
72  * qos valid in [0,5].
73  * reserveNum: mininum number which qos can create worker.{[min, max], default} is {[0,256],8}.
74  * maxConcurrency is amx concurrency num of the qos.{[min, max], default} is {[0,12],8}.
75  * hardLimit: max number which qos can create worker.{[min, max], default} is {[0,256],44}.
76  * @return return ture when setting success.return false when setting fail, and param is default.
77  * @version 1.0
78  */
set_qos_worker_num(ffrt_worker_num_param* qosData)79 static inline int set_qos_worker_num(ffrt_worker_num_param* qosData)
80 {
81     return ffrt_set_qos_worker_num(qosData);
82 }
83 
84 /**
85  * @brief Notifies a specified number of workers at a specified QoS level.
86  *
87  * @param qos_ Indicates the QoS.
88  * @param number Indicates the number of workers to be notified.
89  * @version 1.0
90  */
notify_workers(qos qos_, int number)91 static inline void notify_workers(qos qos_, int number)
92 {
93     return ffrt_notify_workers(qos_, number);
94 }
95 
96 /**
97  * @brief Obtains the ID of this queue.
98  *
99  * @return Returns the queue ID.
100  * @version 1.0
101  */
get_queue_id()102 static inline int64_t get_queue_id()
103 {
104     return ffrt_this_queue_get_id();
105 }
106 } // namespace ffrt
107 #endif
108