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