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 * @addtogroup Ffrt 18 * @{ 19 * 20 * @brief ffrt provides APIs. 21 * 22 * 23 * @syscap SystemCapability.Resourceschedule.Ffrt.Core 24 * 25 * @since 10 26 */ 27 28 /** 29 * @file task.h 30 * @kit FunctionFlowRuntimeKit 31 * 32 * @brief Declares the task interfaces in C. 33 * 34 * @syscap SystemCapability.Resourceschedule.Ffrt.Core 35 * @since 10 36 * @version 1.0 37 */ 38 #ifndef FFRT_API_C_TASK_H 39 #define FFRT_API_C_TASK_H 40 #include <stdint.h> 41 #include "type_def.h" 42 43 /** 44 * @brief Initializes a task attribute. 45 * 46 * @param attr Indicates a pointer to the task attribute. 47 * @return Returns <b>0</b> if the task attribute is initialized; 48 returns <b>-1</b> otherwise. 49 * @since 10 50 * @version 1.0 51 */ 52 FFRT_C_API int ffrt_task_attr_init(ffrt_task_attr_t* attr); 53 54 /** 55 * @brief Sets a task name. 56 * 57 * @param attr Indicates a pointer to the task attribute. 58 * @param name Indicates a pointer to the task name. 59 * @since 10 60 * @version 1.0 61 */ 62 FFRT_C_API void ffrt_task_attr_set_name(ffrt_task_attr_t* attr, const char* name); 63 64 /** 65 * @brief Obtains a task name. 66 * 67 * @param attr Indicates a pointer to the task attribute. 68 * @return Returns a non-null pointer to the task name if the name is obtained; 69 returns a null pointer otherwise. 70 * @since 10 71 * @version 1.0 72 */ 73 FFRT_C_API const char* ffrt_task_attr_get_name(const ffrt_task_attr_t* attr); 74 75 /** 76 * @brief Destroys a task attribute. 77 * 78 * @param attr Indicates a pointer to the task attribute. 79 * @since 10 80 * @version 1.0 81 */ 82 FFRT_C_API void ffrt_task_attr_destroy(ffrt_task_attr_t* attr); 83 84 /** 85 * @brief Sets the QoS for a task attribute. 86 * 87 * @param attr Indicates a pointer to the task attribute. 88 * @param qos Indicates the QoS. 89 * @since 10 90 * @version 1.0 91 */ 92 FFRT_C_API void ffrt_task_attr_set_qos(ffrt_task_attr_t* attr, ffrt_qos_t qos); 93 94 /** 95 * @brief Obtains the QoS of a task attribute. 96 * 97 * @param attr Indicates a pointer to the task attribute. 98 * @return Returns the QoS, which is <b>ffrt_qos_default</b> by default. 99 * @since 10 100 * @version 1.0 101 */ 102 FFRT_C_API ffrt_qos_t ffrt_task_attr_get_qos(const ffrt_task_attr_t* attr); 103 104 /** 105 * @brief Sets the task delay time. 106 * 107 * @param attr Indicates a pointer to the task attribute. 108 * @param delay_us Indicates the delay time, in microseconds. 109 * @since 10 110 * @version 1.0 111 */ 112 FFRT_C_API void ffrt_task_attr_set_delay(ffrt_task_attr_t* attr, uint64_t delay_us); 113 114 /** 115 * @brief Obtains the task delay time. 116 * 117 * @param attr Indicates a pointer to the task attribute. 118 * @return Returns the delay time. 119 * @since 10 120 * @version 1.0 121 */ 122 FFRT_C_API uint64_t ffrt_task_attr_get_delay(const ffrt_task_attr_t* attr); 123 124 /** 125 * @brief Sets the task priority. 126 * 127 * @param attr Indicates a pointer to the task attribute. 128 * @param priority Indicates the execute priority of concurrent queue task. 129 * @since 12 130 * @version 1.0 131 */ 132 FFRT_C_API void ffrt_task_attr_set_queue_priority(ffrt_task_attr_t* attr, ffrt_queue_priority_t priority); 133 134 /** 135 * @brief Obtains the task priority. 136 * 137 * @param attr Indicates a pointer to the task attribute. 138 * @return Returns the priority of concurrent queue task. 139 * @since 12 140 * @version 1.0 141 */ 142 FFRT_C_API ffrt_queue_priority_t ffrt_task_attr_get_queue_priority(const ffrt_task_attr_t* attr); 143 144 /** 145 * @brief Sets the task stack size. 146 * 147 * @param attr Indicates a pointer to the task attribute. 148 * @param size Indicates the task stack size, unit is byte. 149 * @since 12 150 * @version 1.0 151 */ 152 FFRT_C_API void ffrt_task_attr_set_stack_size(ffrt_task_attr_t* attr, uint64_t size); 153 154 /** 155 * @brief Obtains the task stack size. 156 * 157 * @param attr Indicates a pointer to the task attribute. 158 * @return Returns the task stack size, unit is byte. 159 * @since 12 160 * @version 1.0 161 */ 162 FFRT_C_API uint64_t ffrt_task_attr_get_stack_size(const ffrt_task_attr_t* attr); 163 164 /** 165 * @brief Updates the QoS of this task. 166 * 167 * @param qos Indicates the new QoS. 168 * @return Returns <b>0</b> if the QoS is updated; 169 returns <b>-1</b> otherwise. 170 * @since 10 171 * @version 1.0 172 */ 173 FFRT_C_API int ffrt_this_task_update_qos(ffrt_qos_t qos); 174 175 /** 176 * @brief Obtains the qos of this task. 177 * 178 * @return Returns the task qos. 179 * @since 12 180 * @version 1.0 181 */ 182 FFRT_C_API ffrt_qos_t ffrt_this_task_get_qos(); 183 184 /** 185 * @brief Obtains the ID of this task. 186 * 187 * @return Returns the task ID. 188 * @since 10 189 * @version 1.0 190 */ 191 FFRT_C_API uint64_t ffrt_this_task_get_id(void); 192 193 /** 194 * @brief Applies for memory for the function execution structure. 195 * 196 * @param kind Indicates the type of the function execution structure, which can be common or queue. 197 * @return Returns a non-null pointer if the memory is allocated; 198 returns a null pointer otherwise. 199 * @since 10 200 * @version 1.0 201 */ 202 FFRT_C_API void *ffrt_alloc_auto_managed_function_storage_base(ffrt_function_kind_t kind); 203 204 /** 205 * @brief Submits a task. 206 * 207 * @param f Indicates a pointer to the task executor. 208 * @param in_deps Indicates a pointer to the input dependencies. 209 * @param out_deps Indicates a pointer to the output dependencies. 210 * @param attr Indicates a pointer to the task attribute. 211 * @since 10 212 * @version 1.0 213 */ 214 FFRT_C_API void ffrt_submit_base(ffrt_function_header_t* f, const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps, 215 const ffrt_task_attr_t* attr); 216 217 /** 218 * @brief Submits a task, and obtains a task handle. 219 * 220 * @param f Indicates a pointer to the task executor. 221 * @param in_deps Indicates a pointer to the input dependencies. 222 * @param out_deps Indicates a pointer to the output dependencies. 223 * @param attr Indicates a pointer to the task attribute. 224 * @return Returns a non-null task handle if the task is submitted; 225 returns a null pointer otherwise. 226 * @since 10 227 * @version 1.0 228 */ 229 FFRT_C_API ffrt_task_handle_t ffrt_submit_h_base(ffrt_function_header_t* f, const ffrt_deps_t* in_deps, 230 const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr); 231 232 /** 233 * @brief increase reference count of task handle. 234 * 235 * @param handle Indicates a task handle. 236 * @return return the task handle original reference count. 237 * @since 12 238 * @version 1.0 239 */ 240 FFRT_C_API uint32_t ffrt_task_handle_inc_ref(ffrt_task_handle_t handle); 241 242 /** 243 * @brief decrease reference count of task handle. 244 * 245 * @param handle Indicates a task handle. 246 * @return return the task handle original reference count. 247 * @since 12 248 * @version 1.0 249 */ 250 FFRT_C_API uint32_t ffrt_task_handle_dec_ref(ffrt_task_handle_t handle); 251 252 /** 253 * @brief Destroys a task handle. 254 * 255 * @param handle Indicates a task handle. 256 * @since 10 257 * @version 1.0 258 */ 259 FFRT_C_API void ffrt_task_handle_destroy(ffrt_task_handle_t handle); 260 261 /** 262 * @brief Waits until the dependent tasks are complete. 263 * 264 * @param deps Indicates a pointer to the dependent tasks. 265 * @since 10 266 * @version 1.0 267 */ 268 FFRT_C_API void ffrt_wait_deps(const ffrt_deps_t* deps); 269 270 /** 271 * @brief Waits until all submitted tasks are complete. 272 * 273 * @since 10 274 * @version 1.0 275 */ 276 FFRT_C_API void ffrt_wait(void); 277 278 #endif 279