1# FFRT 2 3 4## Overview 5 6Function Flow Runtime (FFRT) is a software runtime library that works with the Function Flow programming model. It is used to schedule and execute tasks of an application developed on the Function Flow programming model. 7 8**System capability**: SystemCapability.Resourceschedule.Ffrt.Core 9 10**Since**: 10 11 12 13## Summary 14 15 16### Files 17 18| Name| Description| 19| -------- | -------- | 20| [condition_variable.h](condition__variable_8h.md) | Declares the condition variable interfaces in C. | 21| [loop.h](loop_8h.md) | Declares the loop interfaces in C. | 22| [mutex.h](mutex_8h.md) | Declares the mutex interfaces in C. | 23| [queue.h](queue_8h.md) | Declares the queue interfaces in C. | 24| [sleep.h](sleep_8h.md) | Declares the sleep and yield interfaces in C. | 25| [task.h](task_8h.md) | Declares the task interfaces in C. | 26| [timer.h](timer_8h.md) | Declares the timer interfaces in C. | 27| [type_def.h](type__def_8h.md) | Declares the common types. | 28 29 30### Structs 31 32| Name| Description| 33| -------- | -------- | 34| struct [ffrt_function_header_t](ffrt__function__header__t.md) | Describes a task execution function. | 35| struct [ffrt_dependence_t](ffrt__dependence__t.md) | Describes dependency data. | 36| struct [ffrt_deps_t](ffrt__deps__t.md) | Describes dependencies. | 37| struct [ffrt_task_attr_t](ffrt__task__attr__t.md) | Describes a task attribute. | 38| struct [ffrt_queue_attr_t](ffrt__queue__attr__t.md) | Describes a queue attribute. | 39| struct [ffrt_condattr_t](ffrt__condattr__t.md) | Describes a condition variable attribute. | 40| struct [ffrt_mutexattr_t](ffrt__mutexattr__t.md) | Describes a mutex attribute. | 41| struct [ffrt_mutex_t](ffrt__mutex__t.md) | Describes a mutex. | 42| struct [ffrt_cond_t](ffrt__cond__t.md) | Describes a condition variable. | 43 44 45### Types 46 47| Name| Description| 48| -------- | -------- | 49| typedef void \* [ffrt_loop_t](#ffrt_loop_t) | Defines the handle to a loop. | 50| typedef void \* [ffrt_queue_t](#ffrt_queue_t) | Defines the handle to a queue. | 51| typedef int [ffrt_qos_t](#ffrt_qos_t) | Defines the QoS type. | 52| typedef void(\* [ffrt_function_t](#ffrt_function_t)) (void \*) | Defines the type of the pointer to a task execution function. | 53| typedef void \* [ffrt_task_handle_t](#ffrt_task_handle_t) | Defines the handle to a task. | 54| typedef void(\* [ffrt_poller_cb](#ffrt_poller_cb)) (void \*data, uint32_t event) | Defines the poller callback function. | 55| typedef void(\* [ffrt_timer_cb](#ffrt_timer_cb)) (void \*data) | Defines the timer callback function. | 56| typedef int [ffrt_timer_t](#ffrt_timer_t) | Handle to the timer. | 57 58 59### Enums 60 61| Name| Description| 62| -------- | -------- | 63| [ffrt_queue_type_t](#ffrt_queue_type_t) {<br>ffrt_queue_serial, <br>ffrt_queue_concurrent, <br>ffrt_queue_max <br>} | Enumerates the queue types. | 64| [ffrt_queue_priority_t](#ffrt_queue_priority_t) { <br>ffrt_queue_priority_immediate = 0, <br>ffrt_queue_priority_high, <br>ffrt_queue_priority_low, <br>ffrt_queue_priority_idle <br>} | Enumerates the task priority types. | 65| [ffrt_qos_default_t](#ffrt_qos_default_t) {<br>ffrt_qos_inherit = -1, <br>ffrt_qos_background, <br>ffrt_qos_utility, <br>ffrt_qos_default,<br>ffrt_qos_user_initiated<br>} | Enumerates the task QoS types. | 66| [ffrt_storage_size_t](#ffrt_storage_size_t) {<br>ffrt_task_attr_storage_size = 128, <br>ffrt_auto_managed_function_storage_size = 64 + sizeof(ffrt_function_header_t), <br>ffrt_mutex_storage_size = 64, <br>ffrt_cond_storage_size = 64,<br>ffrt_queue_attr_storage_size = 128<br>} | Enumerates the storage sizes available for different types of structs. | 67| [ffrt_function_kind_t](#ffrt_function_kind_t) { <br>ffrt_function_kind_general, <br>ffrt_function_kind_queue <br>} | Enumerates the task types. | 68| [ffrt_dependence_type_t](#ffrt_dependence_type_t) { <br>ffrt_dependence_data, <br>ffrt_dependence_task<br> } | Enumerates the dependency types. | 69| [ffrt_error_t](#ffrt_error_t) {<br>ffrt_error = -1, <br>ffrt_success = 0, <br>ffrt_error_nomem = ENOMEM, <br>ffrt_error_timedout = ETIMEDOUT,<br>ffrt_error_busy = EBUSY, <br>ffrt_error_inval = EINVAL<br>} | Enumerates the FFRT error codes. | 70| [ffrt_mutex_type](#ffrt_mutex_type) { <br>ffrt_mutex_normal = 0, <br>ffrt_mutex_recursive = 2, <br>ffrt_mutex_default = ffrt_mutex_normal <br>} | Enumerates the mutex types. | 71 72 73### Functions 74 75| Name| Description| 76| -------- | -------- | 77| FFRT_C_API int [ffrt_cond_init](#ffrt_cond_init) ([ffrt_cond_t](ffrt__cond__t.md) \*cond, const [ffrt_condattr_t](ffrt__condattr__t.md) \*attr) | Initializes a condition variable. | 78| FFRT_C_API int [ffrt_cond_signal](#ffrt_cond_signal) ([ffrt_cond_t](ffrt__cond__t.md) \*cond) | Unblocks at least one of the threads that are blocked on a condition variable. | 79| FFRT_C_API int [ffrt_cond_broadcast](#ffrt_cond_broadcast) ([ffrt_cond_t](ffrt__cond__t.md) \*cond) | Unblocks all threads currently blocked on a condition variable. | 80| FFRT_C_API int [ffrt_cond_wait](#ffrt_cond_wait) ([ffrt_cond_t](ffrt__cond__t.md) \*cond, [ffrt_mutex_t](ffrt__mutex__t.md) \*mutex) | Blocks the calling thread on a condition variable. | 81| FFRT_C_API int [ffrt_cond_timedwait](#ffrt_cond_timedwait) ([ffrt_cond_t](ffrt__cond__t.md) \*cond, [ffrt_mutex_t](ffrt__mutex__t.md) \*mutex, const struct timespec \*time_point) | Blocks the calling thread on a condition variable for a given duration. | 82| FFRT_C_API int [ffrt_cond_destroy](#ffrt_cond_destroy) ([ffrt_cond_t](ffrt__cond__t.md) \*cond) | Destroys a condition variable. | 83| FFRT_C_API [ffrt_loop_t](#ffrt_loop_t) [ffrt_loop_create](#ffrt_loop_create) ([ffrt_queue_t](#ffrt_queue_t) queue) | Creates a loop. | 84| FFRT_C_API int [ffrt_loop_destroy](#ffrt_loop_destroy) ([ffrt_loop_t](#ffrt_loop_t) loop) | Destroys a loop. | 85| FFRT_C_API int [ffrt_loop_run](#ffrt_loop_run) ([ffrt_loop_t](#ffrt_loop_t) loop) | Runs a loop. | 86| FFRT_C_API void [ffrt_loop_stop](#ffrt_loop_stop) ([ffrt_loop_t](#ffrt_loop_t) loop) | Stops a loop. | 87| FFRT_C_API int [ffrt_loop_epoll_ctl](#ffrt_loop_epoll_ctl) ([ffrt_loop_t](#ffrt_loop_t) loop, int op, int fd, uint32_t events, void \*data, [ffrt_poller_cb](#ffrt_poller_cb) cb) | Manages listening events on a loop. | 88| FFRT_C_API [ffrt_timer_t](#ffrt_timer_t) [ffrt_loop_timer_start](#ffrt_loop_timer_start) ([ffrt_loop_t](#ffrt_loop_t) loop, uint64_t timeout, void \*data, [ffrt_timer_cb](#ffrt_timer_cb) cb, bool repeat) | Starts the timer on a loop. | 89| FFRT_C_API int [ffrt_loop_timer_stop](#ffrt_loop_timer_stop) ([ffrt_loop_t](#ffrt_loop_t) loop, [ffrt_timer_t](#ffrt_timer_t) handle) | Stops the timer on a loop. | 90| FFRT_C_API int [ffrt_mutexattr_init](#ffrt_mutexattr_init) ([ffrt_mutexattr_t](ffrt__mutexattr__t.md) \*attr) | Initializes the mutex attribute. | 91| FFRT_C_API int [ffrt_mutexattr_settype](#ffrt_mutexattr_settype) ([ffrt_mutexattr_t](ffrt__mutexattr__t.md) \*attr, int type) | Sets the mutex attribute type. | 92| FFRT_C_API int [ffrt_mutexattr_gettype](#ffrt_mutexattr_gettype) ([ffrt_mutexattr_t](ffrt__mutexattr__t.md) \*attr, int \*type) | Obtains the mutex type. | 93| FFRT_C_API int [ffrt_mutexattr_destroy](#ffrt_mutexattr_destroy) ([ffrt_mutexattr_t](ffrt__mutexattr__t.md) \*attr) | Destroys the mutex attribute. This API needs to be called by users. | 94| FFRT_C_API int [ffrt_mutex_init](#ffrt_mutex_init) ([ffrt_mutex_t](ffrt__mutex__t.md) \*mutex, const [ffrt_mutexattr_t](ffrt__mutexattr__t.md) \*attr) | Initializes a mutex. | 95| FFRT_C_API int [ffrt_mutex_lock](#ffrt_mutex_lock) ([ffrt_mutex_t](ffrt__mutex__t.md) \*mutex) | Locks a mutex. | 96| FFRT_C_API int [ffrt_mutex_unlock](#ffrt_mutex_unlock) ([ffrt_mutex_t](ffrt__mutex__t.md) \*mutex) | Unlocks a mutex. | 97| FFRT_C_API int [ffrt_mutex_trylock](#ffrt_mutex_trylock) ([ffrt_mutex_t](ffrt__mutex__t.md) \*mutex) | Attempts to lock a mutex. | 98| FFRT_C_API int [ffrt_mutex_destroy](#ffrt_mutex_destroy) ([ffrt_mutex_t](ffrt__mutex__t.md) \*mutex) | Destroys a mutex. | 99| FFRT_C_API int [ffrt_queue_attr_init](#ffrt_queue_attr_init) ([ffrt_queue_attr_t](ffrt__queue__attr__t.md) \*attr) | Initializes the queue attribute. | 100| FFRT_C_API void [ffrt_queue_attr_destroy](#ffrt_queue_attr_destroy) ([ffrt_queue_attr_t](ffrt__queue__attr__t.md) \*attr) | Destroys the queue attribute. | 101| FFRT_C_API void [ffrt_queue_attr_set_qos](#ffrt_queue_attr_set_qos) ([ffrt_queue_attr_t](ffrt__queue__attr__t.md) \*attr, [ffrt_qos_t](#ffrt_qos_t) qos) | Sets the queue QoS. | 102| FFRT_C_API [ffrt_qos_t](#ffrt_qos_t) [ffrt_queue_attr_get_qos](#ffrt_queue_attr_get_qos) (const [ffrt_queue_attr_t](ffrt__queue__attr__t.md) \*attr) | Obtains the queue QoS. | 103| FFRT_C_API void [ffrt_queue_attr_set_timeout](#ffrt_queue_attr_set_timeout) ([ffrt_queue_attr_t](ffrt__queue__attr__t.md) \*attr, uint64_t timeout_us) | Sets the queue timeout. | 104| FFRT_C_API uint64_t [ffrt_queue_attr_get_timeout](#ffrt_queue_attr_get_timeout) (const [ffrt_queue_attr_t](ffrt__queue__attr__t.md) \*attr) | Obtains the queue timeout. | 105| FFRT_C_API void [ffrt_queue_attr_set_callback](#ffrt_queue_attr_set_callback) ([ffrt_queue_attr_t](ffrt__queue__attr__t.md) \*attr, [ffrt_function_header_t](ffrt__function__header__t.md) \*f) | Sets a callback that is invoked when a queue task times out. | 106| FFRT_C_API [ffrt_function_header_t](ffrt__function__header__t.md) \* [ffrt_queue_attr_get_callback](#ffrt_queue_attr_get_callback) (const [ffrt_queue_attr_t](ffrt__queue__attr__t.md) \*attr) | Obtains the callback that is invoked when a queue task times out. | 107| FFRT_C_API void [ffrt_queue_attr_set_max_concurrency](#ffrt_queue_attr_set_max_concurrency) ([ffrt_queue_attr_t](ffrt__queue__attr__t.md) \*attr, const int max_concurrency) | Sets the maximum concurrency for a queue, which must be a concurrent queue. | 108| FFRT_C_API int [ffrt_queue_attr_get_max_concurrency](#ffrt_queue_attr_get_max_concurrency) (const [ffrt_queue_attr_t](ffrt__queue__attr__t.md) \*attr) | Obtains the maximum concurrency of a queue, which must be a concurrent queue. | 109| FFRT_C_API [ffrt_queue_t](#ffrt_queue_t) [ffrt_queue_create](#ffrt_queue_create) ([ffrt_queue_type_t](#ffrt_queue_type_t) type, const char \*name, const [ffrt_queue_attr_t](ffrt__queue__attr__t.md) \*attr) | Creates a queue. | 110| FFRT_C_API void [ffrt_queue_destroy](#ffrt_queue_destroy) ([ffrt_queue_t](#ffrt_queue_t) queue) | Destroys a queue. | 111| FFRT_C_API void [ffrt_queue_submit](#ffrt_queue_submit) ([ffrt_queue_t](#ffrt_queue_t) queue, [ffrt_function_header_t](ffrt__function__header__t.md) \*f, const [ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr) | Submits a task to a queue. | 112| FFRT_C_API [ffrt_task_handle_t](#ffrt_task_handle_t) [ffrt_queue_submit_h](#ffrt_queue_submit_h) ([ffrt_queue_t](#ffrt_queue_t) queue, [ffrt_function_header_t](ffrt__function__header__t.md) \*f, const [ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr) | Submits a task to a queue, and obtains the task handle. | 113| FFRT_C_API void [ffrt_queue_wait](#ffrt_queue_wait) ([ffrt_task_handle_t](#ffrt_task_handle_t) handle) | Waits until a task in the queue is complete. | 114| FFRT_C_API int [ffrt_queue_cancel](#ffrt_queue_cancel) ([ffrt_task_handle_t](#ffrt_task_handle_t) handle) | Cancels a task in the queue. | 115| FFRT_C_API [ffrt_queue_t](#ffrt_queue_t) [ffrt_get_main_queue](#ffrt_get_main_queue) (void) | Obtains the main thread queue. | 116| FFRT_C_API [ffrt_queue_t](#ffrt_queue_t) [ffrt_get_current_queue](#ffrt_get_current_queue) (void) | Obtains the ArkTS Worker thread queue. | 117| FFRT_C_API int [ffrt_usleep](#ffrt_usleep) (uint64_t usec) | Sets the fixed sleep time. | 118| FFRT_C_API void [ffrt_yield](#ffrt_yield) (void) | Passes control to other tasks so that they can be executed. | 119| FFRT_C_API int [ffrt_task_attr_init](#ffrt_task_attr_init) ([ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr) | Initializes a task attribute. | 120| FFRT_C_API void [ffrt_task_attr_set_name](#ffrt_task_attr_set_name) ([ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr, const char \*name) | Sets a task name. | 121| FFRT_C_API const char \* [ffrt_task_attr_get_name](#ffrt_task_attr_get_name) (const [ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr) | Obtains a task name. | 122| FFRT_C_API void [ffrt_task_attr_destroy](#ffrt_task_attr_destroy) ([ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr) | Destroys a task attribute. | 123| FFRT_C_API void [ffrt_task_attr_set_qos](#ffrt_task_attr_set_qos) ([ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr, [ffrt_qos_t](#ffrt_qos_t) qos) | Sets the task QoS. | 124| FFRT_C_API [ffrt_qos_t](#ffrt_qos_t) [ffrt_task_attr_get_qos](#ffrt_task_attr_get_qos) (const [ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr) | Obtains the task QoS. | 125| FFRT_C_API void [ffrt_task_attr_set_delay](#ffrt_task_attr_set_delay) ([ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr, uint64_t delay_us) | Sets the task delay time. | 126| FFRT_C_API uint64_t [ffrt_task_attr_get_delay](#ffrt_task_attr_get_delay) (const [ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr) | Obtains the task delay time. | 127| FFRT_C_API void [ffrt_task_attr_set_queue_priority](#ffrt_task_attr_set_queue_priority) ([ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr, [ffrt_queue_priority_t](#ffrt_queue_priority_t) priority) | Sets the task priority in the queue. | 128| FFRT_C_API [ffrt_queue_priority_t](#ffrt_queue_priority_t) [ffrt_task_attr_get_queue_priority](#ffrt_task_attr_get_queue_priority) (const [ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr) | Obtains the task priority in the queue. | 129| FFRT_C_API void [ffrt_task_attr_set_stack_size](#ffrt_task_attr_set_stack_size) ([ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr, uint64_t size) | Sets the task stack size. | 130| FFRT_C_API uint64_t [ffrt_task_attr_get_stack_size](#ffrt_task_attr_get_stack_size) (const [ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr) | Obtains the task stack size. | 131| FFRT_C_API int [ffrt_this_task_update_qos](#ffrt_this_task_update_qos) ([ffrt_qos_t](#ffrt_qos_t) qos) | Updates the task QoS. | 132| FFRT_C_API [ffrt_qos_t](#ffrt_qos_t) [ffrt_this_task_get_qos](#ffrt_this_task_get_qos) (void) | Obtains the task QoS. | 133| FFRT_C_API uint64_t [ffrt_this_task_get_id](#ffrt_this_task_get_id) (void) | Obtains the ID of this task. | 134| FFRT_C_API void \* [ffrt_alloc_auto_managed_function_storage_base](#ffrt_alloc_auto_managed_function_storage_base) ([ffrt_function_kind_t](#ffrt_function_kind_t) kind) | Applies for memory for the task execution function struct. | 135| FFRT_C_API void [ffrt_submit_base](#ffrt_submit_base) ([ffrt_function_header_t](ffrt__function__header__t.md) \*f, const [ffrt_deps_t](ffrt__deps__t.md) \*in_deps, const [ffrt_deps_t](ffrt__deps__t.md) \*out_deps, const [ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr) | Submits a task. | 136| FFRT_C_API [ffrt_task_handle_t](#ffrt_task_handle_t) [ffrt_submit_h_base](#ffrt_submit_h_base) ([ffrt_function_header_t](ffrt__function__header__t.md) \*f, const [ffrt_deps_t](ffrt__deps__t.md) \*in_deps, const [ffrt_deps_t](ffrt__deps__t.md) \*out_deps, const [ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr) | Submits a task, and obtains the task handle. | 137| FFRT_C_API uint32_t [ffrt_task_handle_inc_ref](#ffrt_task_handle_inc_ref) ([ffrt_task_handle_t](#ffrt_task_handle_t) handle) | Increases the number of task handle references. | 138| FFRT_C_API uint32_t [ffrt_task_handle_dec_ref](#ffrt_task_handle_dec_ref) ([ffrt_task_handle_t](#ffrt_task_handle_t) handle) | Decreases the number of task handle references. | 139| FFRT_C_API void [ffrt_task_handle_destroy](#ffrt_task_handle_destroy) ([ffrt_task_handle_t](#ffrt_task_handle_t) handle) | Destroys a task handle. | 140| FFRT_C_API void [ffrt_wait_deps](#ffrt_wait_deps) (const [ffrt_deps_t](ffrt__deps__t.md) \*deps) | Waits until the dependent tasks are complete. | 141| FFRT_C_API void [ffrt_wait](#ffrt_wait) (void) | Waits until all submitted tasks are complete. | 142| FFRT_C_API [ffrt_timer_t](#ffrt_timer_t) [ffrt_timer_start](#ffrt_timer_start) ([ffrt_qos_t](#ffrt_qos_t) qos, uint64_t timeout, void \*data, [ffrt_timer_cb](#ffrt_timer_cb) cb, bool repeat) | Starts the timer. | 143| FFRT_C_API int [ffrt_timer_stop](#ffrt_timer_stop) ([ffrt_qos_t](#ffrt_qos_t) qos, [ffrt_timer_t](#ffrt_timer_t) handle) | Stops the timer. | 144 145 146## Type Description 147 148 149### ffrt_function_t 150 151``` 152typedef void(* ffrt_function_t) (void *) 153``` 154**Description** 155Defines the type of the pointer to a task execution function. 156 157**Since**: 10 158 159 160### ffrt_loop_t 161 162``` 163typedef void* ffrt_loop_t 164``` 165**Description** 166Defines the handle to a loop. 167 168**Since**: 12 169 170 171### ffrt_poller_cb 172 173``` 174typedef void(* ffrt_poller_cb) (void *data, uint32_t event) 175``` 176**Description** 177Defines the poller callback function. 178 179**Since**: 12 180 181 182### ffrt_qos_t 183 184``` 185typedef int ffrt_qos_t 186``` 187**Description** 188Defines the QoS type. 189 190**Since**: 10 191 192 193### ffrt_queue_t 194 195``` 196typedef void* ffrt_queue_t 197``` 198**Description** 199Defines the handle to a queue. 200 201**Since**: 10 202 203 204### ffrt_task_handle_t 205 206``` 207typedef void* ffrt_task_handle_t 208``` 209**Description** 210Defines the handle to a task. 211 212**Since**: 10 213 214 215### ffrt_timer_cb 216 217``` 218typedef void(* ffrt_timer_cb) (void *data) 219``` 220**Description** 221Defines the timer callback function. 222 223**Since**: 12 224 225 226### ffrt_timer_t 227 228``` 229typedef int ffrt_timer_t 230``` 231**Description** 232Handle to the timer. 233 234**Since**: 12 235 236 237## Enum Description 238 239 240### ffrt_dependence_type_t 241 242``` 243enum ffrt_dependence_type_t 244``` 245**Description** 246Enumerates the dependency types. 247 248**Since**: 10 249 250| Value| Description| 251| -------- | -------- | 252| ffrt_dependence_data | Data dependency.| 253| ffrt_dependence_task | Task dependency.| 254 255 256### ffrt_error_t 257 258``` 259enum ffrt_error_t 260``` 261**Description** 262Enumerates the FFRT error codes. 263 264**Since**: 10 265 266| Value| Description| 267| -------- | -------- | 268| ffrt_error | Failure.| 269| ffrt_success | Success.| 270| ffrt_error_nomem | Insufficient memory.| 271| ffrt_error_timedout | Timeout.| 272| ffrt_error_busy | Try again.| 273| ffrt_error_inval | Invalid value.| 274 275 276### ffrt_function_kind_t 277 278``` 279enum ffrt_function_kind_t 280``` 281**Description** 282Enumerates the task types. 283 284**Since**: 10 285 286| Value| Description| 287| -------- | -------- | 288| ffrt_function_kind_general | General task.| 289| ffrt_function_kind_queue | Queue task.| 290 291 292### ffrt_mutex_type 293 294``` 295enum ffrt_mutex_type 296``` 297**Description** 298Enumerates the mutex types. 299 300**ffrt_mutex_normal** indicates a normal mutex, **ffrt_mutex_recursive** indicates a recursive mutex, and **ffrt_mutex_default** indicates a default mutex. 301 302**Since**: 12 303 304| Value| Description| 305| -------- | -------- | 306| ffrt_mutex_normal | Normal mutex.| 307| ffrt_mutex_recursive | Recursive mutex.| 308| ffrt_mutex_default | Default mutex.| 309 310 311### ffrt_qos_default_t 312 313``` 314enum ffrt_qos_default_t 315``` 316**Description** 317Enumerates the task QoS types. 318 319**Since**: 10 320 321| Value| Description| 322| -------- | -------- | 323| ffrt_qos_inherit | Inherited task QoS.| 324| ffrt_qos_background | Background task.| 325| ffrt_qos_utility | Real-time utility.| 326| ffrt_qos_default | Default type.| 327| ffrt_qos_user_initiated | User initiated.| 328 329 330### ffrt_queue_priority_t 331 332``` 333enum ffrt_queue_priority_t 334``` 335**Description** 336Enumerates the task priority types. 337 338**Since**: 12 339 340| Value| Description| 341| -------- | -------- | 342| ffrt_queue_priority_immediate | Immediate priority.| 343| ffrt_queue_priority_high | High priority.| 344| ffrt_queue_priority_low | Low priority.| 345| ffrt_queue_priority_idle | Lowest priority.| 346 347 348### ffrt_queue_type_t 349 350``` 351enum ffrt_queue_type_t 352``` 353**Description** 354Enumerates the queue types. 355 356**Since**: 12 357 358| Value| Description| 359| -------- | -------- | 360| ffrt_queue_serial | Serial queue| 361| ffrt_queue_concurrent | Concurrent queue.| 362| ffrt_queue_max | Invalid queue type.| 363 364 365### ffrt_storage_size_t 366 367``` 368enum ffrt_storage_size_t 369``` 370**Description** 371Enumerates the storage sizes available for different types of structs. 372 373**Since**: 10 374 375| Value| Description| 376| -------- | -------- | 377| ffrt_task_attr_storage_size | Pointer to the task attribute.| 378| ffrt_auto_managed_function_storage_size | Describes a task execution function.| 379| ffrt_mutex_storage_size | Storage size for the mutex struct.| 380| ffrt_cond_storage_size | Storage size for the condition variable struct.| 381| ffrt_queue_attr_storage_size | Pointer to the queue attribute.| 382 383 384## Function Description 385 386 387### ffrt_alloc_auto_managed_function_storage_base() 388 389``` 390FFRT_C_API void* ffrt_alloc_auto_managed_function_storage_base (ffrt_function_kind_t kind) 391``` 392**Description** 393Applies for memory for the task execution function struct. 394 395**Since**: 10 396 397**Parameters** 398 399| Name| Description| 400| -------- | -------- | 401| kind | Type of the task execution function, which can be general or queue. | 402 403**Returns** 404 405Returns a non-null pointer if the memory is allocated; returns a null pointer otherwise. 406 407 408### ffrt_cond_broadcast() 409 410``` 411FFRT_C_API int ffrt_cond_broadcast (ffrt_cond_t * cond) 412``` 413**Description** 414Unblocks all threads currently blocked on a condition variable. 415 416**Since**: 10 417 418**Parameters** 419 420| Name| Description| 421| -------- | -------- | 422| cond | Pointer to the condition variable. | 423 424**Returns** 425 426Returns **ffrt_success** if all the threads are unblocked; returns **ffrt_error_inval** otherwise. 427 428 429### ffrt_cond_destroy() 430 431``` 432FFRT_C_API int ffrt_cond_destroy (ffrt_cond_t * cond) 433``` 434**Description** 435Destroys a condition variable. 436 437**Since**: 10 438 439**Parameters** 440 441| Name| Description| 442| -------- | -------- | 443| cond | Pointer to the condition variable. | 444 445**Returns** 446 447Returns **ffrt_success** if the condition variable is destroyed; returns **ffrt_error_inval** otherwise. 448 449 450### ffrt_cond_init() 451 452``` 453FFRT_C_API int ffrt_cond_init (ffrt_cond_t * cond, const ffrt_condattr_t * attr ) 454``` 455**Description** 456Initializes a condition variable. 457 458**Since**: 10 459 460**Parameters** 461 462| Name| Description| 463| -------- | -------- | 464| cond | Pointer to the condition variable. | 465| attr | Pointer to the condition variable attribute. | 466 467**Returns** 468 469Returns **ffrt_success** if the condition variable is initialized; returns **ffrt_error_inval** otherwise. 470 471 472### ffrt_cond_signal() 473 474``` 475FFRT_C_API int ffrt_cond_signal (ffrt_cond_t * cond) 476``` 477**Description** 478Unblocks at least one of the threads that are blocked on a condition variable. 479 480**Since**: 10 481 482**Parameters** 483 484| Name| Description| 485| -------- | -------- | 486| cond | Pointer to the condition variable. | 487 488**Returns** 489 490Returns **ffrt_success** if at least one of the threads is unblocked; returns **ffrt_error_inval** otherwise. 491 492 493### ffrt_cond_timedwait() 494 495``` 496FFRT_C_API int ffrt_cond_timedwait (ffrt_cond_t * cond, ffrt_mutex_t * mutex, const struct timespec * time_point ) 497``` 498**Description** 499Blocks the calling thread on a condition variable for a given duration. 500 501If **ffrt_cond_signal** or **ffrt_cond_broadcast** is not called to unblock the thread when the maximum wait time is reached, the thread is automatically unblocked. 502 503**Since**: 10 504 505**Parameters** 506 507| Name| Description| 508| -------- | -------- | 509| cond | Pointer to the condition variable. | 510| mutex | Pointer to the mutex. | 511| time_point | Pointer to the maximum duration that the thread is blocked. If **ffrt_cond_signal** or **ffrt_cond_broadcast** is not called to unblock the thread when the maximum duration reaches, the thread is automatically unblocked. | 512 513**Returns** 514 515Returns **ffrt_success** if the thread is blocked; returns **ffrt_error_timedout** if the maximum duration reaches; returns **ffrt_error_inval** if the waiting fails. 516 517 518### ffrt_cond_wait() 519 520``` 521FFRT_C_API int ffrt_cond_wait (ffrt_cond_t * cond, ffrt_mutex_t * mutex ) 522``` 523**Description** 524Blocks the calling thread on a condition variable. 525 526**Since**: 10 527 528**Parameters** 529 530| Name| Description| 531| -------- | -------- | 532| cond | Pointer to the condition variable. | 533| mutex | Pointer to the mutex. | 534 535**Returns** 536 537Returns **ffrt_success** if the thread is blocked; returns **ffrt_error_inval** if the blocking fails. 538 539 540### ffrt_get_current_queue() 541 542``` 543FFRT_C_API ffrt_queue_t ffrt_get_current_queue (void ) 544``` 545**Description** 546Obtains the ArkTS Worker thread queue. 547 548**Since**: 12 549 550**Deprecated version**: 18 551 552**Returns** 553 554Returns the handle to the thread queue. 555 556 557### ffrt_get_main_queue() 558 559``` 560FFRT_C_API ffrt_queue_t ffrt_get_main_queue (void ) 561``` 562**Description** 563Obtains the main thread queue. 564 565**Since**: 12 566 567**Returns** 568 569Returns the handle to the main thread queue. 570 571 572### ffrt_loop_create() 573 574``` 575FFRT_C_API ffrt_loop_t ffrt_loop_create (ffrt_queue_t queue) 576``` 577**Description** 578Creates a loop. 579 580**Since**: 12 581 582**Parameters** 583 584| Name| Description| 585| -------- | -------- | 586| queue | Concurrent queue. | 587 588**Returns** 589 590Returns the **ffrt_loop_t** object if the loop is created; returns a null pointer otherwise. 591 592 593### ffrt_loop_destroy() 594 595``` 596FFRT_C_API int ffrt_loop_destroy (ffrt_loop_t loop) 597``` 598**Description** 599Destroys a loop. 600 601**Since**: 12 602 603**Parameters** 604 605| Name| Description| 606| -------- | -------- | 607| loop | Loop object. | 608 609**Returns** 610 611Returns **0** if the loop is destroyed; returns **-1** otherwise. 612 613 614### ffrt_loop_epoll_ctl() 615 616``` 617FFRT_C_API int ffrt_loop_epoll_ctl (ffrt_loop_t loop, int op, int fd, uint32_t events, void * data, ffrt_poller_cb cb ) 618``` 619**Description** 620Manages listening events on a loop. 621 622**Since**: 12 623 624**Parameters** 625 626| Name| Description| 627| -------- | -------- | 628| loop | Loop object. | 629| op | Operation to be performed. | 630| fd | File descriptor. | 631| events | Events linked to the file descriptor. | 632| data | Pointer to the input parameter in the callback function invoked upon event changes. | 633| cb | Callback function invoked upon event changes. | 634 635**Returns** 636 637Returns **0** if the operation is successful; returns **-1** otherwise. 638 639 640### ffrt_loop_run() 641 642``` 643FFRT_C_API int ffrt_loop_run (ffrt_loop_t loop) 644``` 645**Description** 646Runs a loop. 647 648**Since**: 12 649 650**Parameters** 651 652| Name| Description| 653| -------- | -------- | 654| loop | Loop object. | 655 656**Returns** 657 658Returns **0** if the loop runs successfully; returns **-1** otherwise. 659 660 661### ffrt_loop_stop() 662 663``` 664FFRT_C_API void ffrt_loop_stop (ffrt_loop_t loop) 665``` 666**Description** 667Stops a loop. 668 669**Since**: 12 670 671**Parameters** 672 673| Name| Description| 674| -------- | -------- | 675| loop | Loop object. | 676 677 678### ffrt_loop_timer_start() 679 680``` 681FFRT_C_API ffrt_timer_t ffrt_loop_timer_start (ffrt_loop_t loop, uint64_t timeout, void * data, ffrt_timer_cb cb, bool repeat ) 682``` 683**Description** 684Starts the timer on a loop. 685 686**Since**: 12 687 688**Parameters** 689 690| Name| Description| 691| -------- | -------- | 692| loop | Loop object. | 693| timeout | Timeout duration of the timer. | 694| data | Pointer to the input parameter in the callback function invoked upon event changes. | 695| cb | Callback function invoked upon event changes. | 696| repeat | Whether to repeat the timer. | 697 698**Returns** 699 700Returns the timer handle. 701 702 703### ffrt_loop_timer_stop() 704 705``` 706FFRT_C_API int ffrt_loop_timer_stop (ffrt_loop_t loop, ffrt_timer_t handle ) 707``` 708**Description** 709Stops the timer on a loop. 710 711**Since**: 12 712 713**Parameters** 714 715| Name| Description| 716| -------- | -------- | 717| loop | Loop object. | 718| handle | Timer handle. | 719 720**Returns** 721 722Returns **0** if the operation is successful; returns **-1** otherwise. 723 724 725### ffrt_mutex_destroy() 726 727``` 728FFRT_C_API int ffrt_mutex_destroy (ffrt_mutex_t * mutex) 729``` 730**Description** 731Destroys a mutex. 732 733**Since**: 10 734 735**Parameters** 736 737| Name| Description| 738| -------- | -------- | 739| mutex | Pointer to the mutex. | 740 741**Returns** 742 743Returns **ffrt_success** if the mutex is destroyed; returns **ffrt_error_inval** otherwise. 744 745 746### ffrt_mutex_init() 747 748``` 749FFRT_C_API int ffrt_mutex_init (ffrt_mutex_t * mutex, const ffrt_mutexattr_t * attr ) 750``` 751**Description** 752Initializes a mutex. 753 754**Since**: 10 755 756**Parameters** 757 758| Name| Description| 759| -------- | -------- | 760| mutex | Pointer to the mutex. | 761| attr | Pointer to the mutex attribute. | 762 763**Returns** 764 765Returns **ffrt_success** if the mutex is initialized; returns **ffrt_error_inval** otherwise. 766 767 768### ffrt_mutex_lock() 769 770``` 771FFRT_C_API int ffrt_mutex_lock (ffrt_mutex_t * mutex) 772``` 773**Description** 774Locks a mutex. 775 776**Since**: 10 777 778**Parameters** 779 780| Name| Description| 781| -------- | -------- | 782| mutex | Pointer to the mutex. | 783 784**Returns** 785 786Returns **ffrt_success** if the mutex is locked; returns **ffrt_error_inval** or blocks the calling thread otherwise. 787 788 789### ffrt_mutex_trylock() 790 791``` 792FFRT_C_API int ffrt_mutex_trylock (ffrt_mutex_t * mutex) 793``` 794**Description** 795Attempts to lock a mutex. 796 797**Since**: 10 798 799**Parameters** 800 801| Name| Description| 802| -------- | -------- | 803| mutex | Pointer to the mutex. | 804 805**Returns** 806 807Returns **ffrt_success** if the mutex is locked; returns **ffrt_error_inval** or **ffrt_error_busy** otherwise. 808 809 810### ffrt_mutex_unlock() 811 812``` 813FFRT_C_API int ffrt_mutex_unlock (ffrt_mutex_t * mutex) 814``` 815**Description** 816Unlocks a mutex. 817 818**Since**: 10 819 820**Parameters** 821 822| Name| Description| 823| -------- | -------- | 824| mutex | Pointer to the mutex. | 825 826**Returns** 827 828Returns **ffrt_success** if the mutex is unlocked; returns **ffrt_error_inval** otherwise. 829 830 831### ffrt_mutexattr_destroy() 832 833``` 834FFRT_C_API int ffrt_mutexattr_destroy (ffrt_mutexattr_t * attr) 835``` 836**Description** 837Destroys the mutex attribute. This API needs to be called by users. 838 839**Since**: 12 840 841**Parameters** 842 843| Name| Description| 844| -------- | -------- | 845| attr | Pointer to the mutex attribute. | 846 847**Returns** 848 849Returns **ffrt_success** if the mutex is destroyed; returns **ffrt_error_inval** otherwise. 850 851 852### ffrt_mutexattr_gettype() 853 854``` 855FFRT_C_API int ffrt_mutexattr_gettype (ffrt_mutexattr_t * attr, int * type ) 856``` 857**Description** 858Obtains the mutex type. 859 860**Since**: 12 861 862**Parameters** 863 864| Name| Description| 865| -------- | -------- | 866| attr | Pointer to the mutex attribute. | 867| type | Pointer to the mutex type. | 868 869**Returns** 870 871Returns **ffrt_success** if the mutex is obtained; returns **ffrt_error_inval** if the pointer to the mutex attribute or mutex type is null. 872 873 874### ffrt_mutexattr_init() 875 876``` 877FFRT_C_API int ffrt_mutexattr_init (ffrt_mutexattr_t * attr) 878``` 879**Description** 880Initializes the mutex attribute. 881 882**Since**: 12 883 884**Parameters** 885 886| Name| Description| 887| -------- | -------- | 888| attr | Pointer to the mutex attribute. | 889 890**Returns** 891 892Returns **ffrt_success** if the mutex is initialized; returns **ffrt_error_inval** otherwise. 893 894 895### ffrt_mutexattr_settype() 896 897``` 898FFRT_C_API int ffrt_mutexattr_settype (ffrt_mutexattr_t * attr, int type ) 899``` 900**Description** 901Sets the mutex attribute type. 902 903**Since**: 12 904 905**Parameters** 906 907| Name| Description| 908| -------- | -------- | 909| attr | Pointer to the mutex attribute. | 910| type | Mutex type. | 911 912**Returns** 913 914Returns **ffrt_success** if the mutex is set; returns **ffrt_error_inval** if the pointer to the mutex attribute is null or the mutex is not of the **ffrt_mutex_normal** or **ffrt_mutex_recursive** type. 915 916 917### ffrt_queue_attr_destroy() 918 919``` 920FFRT_C_API void ffrt_queue_attr_destroy (ffrt_queue_attr_t * attr) 921``` 922**Description** 923Destroys the queue attribute. 924 925**Since**: 10 926 927**Parameters** 928 929| Name| Description| 930| -------- | -------- | 931| attr | Pointer to the queue attribute. | 932 933 934### ffrt_queue_attr_get_callback() 935 936``` 937FFRT_C_API ffrt_function_header_t* ffrt_queue_attr_get_callback (const ffrt_queue_attr_t * attr) 938``` 939**Description** 940Obtains the callback that is invoked when a queue task times out. 941 942**Since**: 10 943 944**Parameters** 945 946| Name| Description| 947| -------- | -------- | 948| attr | Pointer to the queue attribute. | 949 950**Returns** 951 952Returns the callback. 953 954 955### ffrt_queue_attr_get_max_concurrency() 956 957``` 958FFRT_C_API int ffrt_queue_attr_get_max_concurrency (const ffrt_queue_attr_t * attr) 959``` 960**Description** 961Obtains the maximum concurrency of a queue, which must be a concurrent queue. 962 963**Since**: 12 964 965**Parameters** 966 967| Name| Description| 968| -------- | -------- | 969| attr | Pointer to the queue attribute. | 970 971**Returns** 972 973Returns the maximum concurrency. 974 975 976### ffrt_queue_attr_get_qos() 977 978``` 979FFRT_C_API ffrt_qos_t ffrt_queue_attr_get_qos (const ffrt_queue_attr_t * attr) 980``` 981**Description** 982Obtains the queue QoS. 983 984**Since**: 10 985 986**Parameters** 987 988| Name| Description| 989| -------- | -------- | 990| attr | Pointer to the queue attribute. | 991 992**Returns** 993 994Returns the queue QoS. 995 996 997### ffrt_queue_attr_get_timeout() 998 999``` 1000FFRT_C_API uint64_t ffrt_queue_attr_get_timeout (const ffrt_queue_attr_t * attr) 1001``` 1002**Description** 1003Obtains the queue timeout. 1004 1005**Since**: 10 1006 1007**Parameters** 1008 1009| Name| Description| 1010| -------- | -------- | 1011| attr | Pointer to the queue attribute. | 1012 1013**Returns** 1014 1015Returns the timeout. 1016 1017 1018### ffrt_queue_attr_init() 1019 1020``` 1021FFRT_C_API int ffrt_queue_attr_init (ffrt_queue_attr_t * attr) 1022``` 1023**Description** 1024Initializes the queue attribute. 1025 1026**Since**: 10 1027 1028**Parameters** 1029 1030| Name| Description| 1031| -------- | -------- | 1032| attr | Pointer to the queue attribute. | 1033 1034**Returns** 1035 1036Returns **0** if the queue attribute is initialized; returns **-1** otherwise. 1037 1038 1039### ffrt_queue_attr_set_callback() 1040 1041``` 1042FFRT_C_API void ffrt_queue_attr_set_callback (ffrt_queue_attr_t * attr, ffrt_function_header_t * f ) 1043``` 1044**Description** 1045Sets a callback that is invoked when a queue task times out. 1046 1047**Since**: 10 1048 1049**Parameters** 1050 1051| Name| Description| 1052| -------- | -------- | 1053| attr | Pointer to the queue attribute. | 1054| f | Pointer to the callback function invoked upon a timeout. | 1055 1056 1057### ffrt_queue_attr_set_max_concurrency() 1058 1059``` 1060FFRT_C_API void ffrt_queue_attr_set_max_concurrency (ffrt_queue_attr_t * attr, const int max_concurrency ) 1061``` 1062**Description** 1063Sets the maximum concurrency for a queue, which must be a concurrent queue. 1064 1065**Since**: 12 1066 1067**Parameters** 1068 1069| Name| Description| 1070| -------- | -------- | 1071| attr | Pointer to the queue attribute. | 1072| max_concurrency | Maximum concurrency. | 1073 1074 1075### ffrt_queue_attr_set_qos() 1076 1077``` 1078FFRT_C_API void ffrt_queue_attr_set_qos (ffrt_queue_attr_t * attr, ffrt_qos_t qos ) 1079``` 1080**Description** 1081Sets the queue QoS. 1082 1083**Since**: 10 1084 1085**Parameters** 1086 1087| Name| Description| 1088| -------- | -------- | 1089| attr | Pointer to the queue attribute. | 1090| qos | QoS. | 1091 1092 1093### ffrt_queue_attr_set_timeout() 1094 1095``` 1096FFRT_C_API void ffrt_queue_attr_set_timeout (ffrt_queue_attr_t * attr, uint64_t timeout_us ) 1097``` 1098**Description** 1099Sets the queue timeout. 1100 1101**Since**: 10 1102 1103**Parameters** 1104 1105| Name| Description| 1106| -------- | -------- | 1107| attr | Pointer to the queue attribute. | 1108| timeout_us | Timeout. | 1109 1110 1111### ffrt_queue_cancel() 1112 1113``` 1114FFRT_C_API int ffrt_queue_cancel (ffrt_task_handle_t handle) 1115``` 1116**Description** 1117Cancels a task in the queue. 1118 1119**Since**: 10 1120 1121**Parameters** 1122 1123| Name| Description| 1124| -------- | -------- | 1125| handle | Task handle. | 1126 1127**Returns** 1128 1129Returns **0** if the task is canceled; returns **-1** otherwise. 1130 1131 1132### ffrt_queue_create() 1133 1134``` 1135FFRT_C_API ffrt_queue_t ffrt_queue_create (ffrt_queue_type_t type, const char * name, const ffrt_queue_attr_t * attr ) 1136``` 1137**Description** 1138Creates a queue. 1139 1140**Since**: 10 1141 1142**Parameters** 1143 1144| Name| Description| 1145| -------- | -------- | 1146| type | Queue type. | 1147| name | Pointer to the queue name. | 1148| attr | Pointer to the queue attribute. | 1149 1150**Returns** 1151 1152Returns a non-null queue handle if the queue is created; returns a null pointer otherwise. 1153 1154 1155### ffrt_queue_destroy() 1156 1157``` 1158FFRT_C_API void ffrt_queue_destroy (ffrt_queue_t queue) 1159``` 1160**Description** 1161Destroys a queue. 1162 1163**Since**: 10 1164 1165**Parameters** 1166 1167| Name| Description| 1168| -------- | -------- | 1169| queue | Queue handle. | 1170 1171 1172### ffrt_queue_submit() 1173 1174``` 1175FFRT_C_API void ffrt_queue_submit (ffrt_queue_t queue, ffrt_function_header_t * f, const ffrt_task_attr_t * attr ) 1176``` 1177**Description** 1178Submits a task to a queue. 1179 1180**Since**: 10 1181 1182**Parameters** 1183 1184| Name| Description| 1185| -------- | -------- | 1186| queue | Queue handle. | 1187| f | Pointer to the task execution function. | 1188| attr | Pointer to the task attribute. | 1189 1190 1191### ffrt_queue_submit_h() 1192 1193``` 1194FFRT_C_API ffrt_task_handle_t ffrt_queue_submit_h (ffrt_queue_t queue, ffrt_function_header_t * f, const ffrt_task_attr_t * attr ) 1195``` 1196**Description** 1197Submits a task to a queue, and obtains the task handle. 1198 1199**Since**: 10 1200 1201**Parameters** 1202 1203| Name| Description| 1204| -------- | -------- | 1205| queue | Queue handle. | 1206| f | Pointer to the task execution function. | 1207| attr | Pointer to the task attribute. | 1208 1209**Returns** 1210 1211Returns a non-null task handle if the task is submitted; returns a null pointer otherwise. 1212 1213 1214### ffrt_queue_wait() 1215 1216``` 1217FFRT_C_API void ffrt_queue_wait (ffrt_task_handle_t handle) 1218``` 1219**Description** 1220Waits until a task in the queue is complete. 1221 1222**Since**: 10 1223 1224**Parameters** 1225 1226| Name| Description| 1227| -------- | -------- | 1228| handle | Task handle. | 1229 1230 1231### ffrt_submit_base() 1232 1233``` 1234FFRT_C_API void ffrt_submit_base (ffrt_function_header_t * f, const ffrt_deps_t * in_deps, const ffrt_deps_t * out_deps, const ffrt_task_attr_t * attr ) 1235``` 1236**Description** 1237Submits a task. 1238 1239**Since**: 10 1240 1241**Parameters** 1242 1243| Name| Description| 1244| -------- | -------- | 1245| f | Pointer to the task execution function. | 1246| in_deps | Pointer to the input dependencies. | 1247| out_deps | Pointer to the output dependencies. | 1248| attr | Pointer to the task attribute. | 1249 1250 1251### ffrt_submit_h_base() 1252 1253``` 1254FFRT_C_API ffrt_task_handle_t ffrt_submit_h_base (ffrt_function_header_t * f, const ffrt_deps_t * in_deps, const ffrt_deps_t * out_deps, const ffrt_task_attr_t * attr ) 1255``` 1256**Description** 1257Submits a task, and obtains the task handle. 1258 1259**Since**: 10 1260 1261**Parameters** 1262 1263| Name| Description| 1264| -------- | -------- | 1265| f | Pointer to the task execution function. | 1266| in_deps | Pointer to the input dependencies. | 1267| out_deps | Pointer to the output dependencies. | 1268| attr | Pointer to the task attribute. | 1269 1270**Returns** 1271 1272Returns a non-null task handle if the task is submitted; returns a null pointer otherwise. 1273 1274 1275### ffrt_task_attr_destroy() 1276 1277``` 1278FFRT_C_API void ffrt_task_attr_destroy (ffrt_task_attr_t * attr) 1279``` 1280**Description** 1281Destroys a task attribute. 1282 1283**Since**: 10 1284 1285**Parameters** 1286 1287| Name| Description| 1288| -------- | -------- | 1289| attr | Pointer to the task attribute. | 1290 1291 1292### ffrt_task_attr_get_delay() 1293 1294``` 1295FFRT_C_API uint64_t ffrt_task_attr_get_delay (const ffrt_task_attr_t * attr) 1296``` 1297**Description** 1298Obtains the task delay time. 1299 1300**Since**: 10 1301 1302**Parameters** 1303 1304| Name| Description| 1305| -------- | -------- | 1306| attr | Pointer to the task attribute. | 1307 1308**Returns** 1309 1310Returns the delay time. 1311 1312 1313### ffrt_task_attr_get_name() 1314 1315``` 1316FFRT_C_API const char* ffrt_task_attr_get_name (const ffrt_task_attr_t * attr) 1317``` 1318**Description** 1319Obtains a task name. 1320 1321**Since**: 10 1322 1323**Parameters** 1324 1325| Name| Description| 1326| -------- | -------- | 1327| attr | Pointer to the task attribute. | 1328 1329**Returns** 1330 1331Returns a non-null pointer to the task name if the name is obtained; returns a null pointer otherwise. 1332 1333 1334### ffrt_task_attr_get_qos() 1335 1336``` 1337FFRT_C_API ffrt_qos_t ffrt_task_attr_get_qos (const ffrt_task_attr_t * attr) 1338``` 1339**Description** 1340Obtains the task QoS. 1341 1342**Since**: 10 1343 1344**Parameters** 1345 1346| Name| Description| 1347| -------- | -------- | 1348| attr | Pointer to the task attribute. | 1349 1350**Returns** 1351 1352Returns the QoS, which is **ffrt_qos_default** by default. 1353 1354 1355### ffrt_task_attr_get_queue_priority() 1356 1357``` 1358FFRT_C_API ffrt_queue_priority_t ffrt_task_attr_get_queue_priority (const ffrt_task_attr_t * attr) 1359``` 1360**Description** 1361Obtains the task priority in the queue. 1362 1363**Since**: 12 1364 1365**Parameters** 1366 1367| Name| Description| 1368| -------- | -------- | 1369| attr | Pointer to the task attribute. | 1370 1371**Returns** 1372 1373Returns the task priority. 1374 1375 1376### ffrt_task_attr_get_stack_size() 1377 1378``` 1379FFRT_C_API uint64_t ffrt_task_attr_get_stack_size (const ffrt_task_attr_t * attr) 1380``` 1381**Description** 1382Obtains the task stack size. 1383 1384**Since**: 12 1385 1386**Parameters** 1387 1388| Name| Description| 1389| -------- | -------- | 1390| attr | Pointer to the task attribute. | 1391 1392**Returns** 1393 1394Returns the task stack size, in bytes. 1395 1396 1397### ffrt_task_attr_init() 1398 1399``` 1400FFRT_C_API int ffrt_task_attr_init (ffrt_task_attr_t * attr) 1401``` 1402**Description** 1403Initializes a task attribute. 1404 1405**Since**: 10 1406 1407**Parameters** 1408 1409| Name| Description| 1410| -------- | -------- | 1411| attr | Pointer to the task attribute. | 1412 1413**Returns** 1414 1415Returns **0** if the task attribute is initialized; returns **-1** otherwise. 1416 1417 1418### ffrt_task_attr_set_delay() 1419 1420``` 1421FFRT_C_API void ffrt_task_attr_set_delay (ffrt_task_attr_t * attr, uint64_t delay_us ) 1422``` 1423**Description** 1424Sets the task delay time. 1425 1426**Since**: 10 1427 1428**Parameters** 1429 1430| Name| Description| 1431| -------- | -------- | 1432| attr | Pointer to the task attribute. | 1433| delay_us | Delay time, in microseconds. | 1434 1435 1436### ffrt_task_attr_set_name() 1437 1438``` 1439FFRT_C_API void ffrt_task_attr_set_name (ffrt_task_attr_t * attr, const char * name ) 1440``` 1441**Description** 1442Sets a task name. 1443 1444**Since**: 10 1445 1446**Parameters** 1447 1448| Name| Description| 1449| -------- | -------- | 1450| attr | Pointer to the task attribute. | 1451| name | Pointer to the task name. | 1452 1453 1454### ffrt_task_attr_set_qos() 1455 1456``` 1457FFRT_C_API void ffrt_task_attr_set_qos (ffrt_task_attr_t * attr, ffrt_qos_t qos ) 1458``` 1459**Description** 1460Sets the task QoS. 1461 1462**Since**: 10 1463 1464**Parameters** 1465 1466| Name| Description| 1467| -------- | -------- | 1468| attr | Pointer to the task attribute. | 1469| qos | Task QoS. | 1470 1471 1472### ffrt_task_attr_set_queue_priority() 1473 1474``` 1475FFRT_C_API void ffrt_task_attr_set_queue_priority (ffrt_task_attr_t * attr, ffrt_queue_priority_t priority ) 1476``` 1477**Description** 1478Sets the task priority in the queue. 1479 1480**Since**: 12 1481 1482**Parameters** 1483 1484| Name| Description| 1485| -------- | -------- | 1486| attr | Pointer to the task attribute. | 1487| priority | Task priority. | 1488 1489 1490### ffrt_task_attr_set_stack_size() 1491 1492``` 1493FFRT_C_API void ffrt_task_attr_set_stack_size (ffrt_task_attr_t * attr, uint64_t size ) 1494``` 1495**Description** 1496Sets the task stack size. 1497 1498**Since**: 12 1499 1500**Parameters** 1501 1502| Name| Description| 1503| -------- | -------- | 1504| attr | Pointer to the task attribute. | 1505| size | Size of the task stack, in bytes. | 1506 1507 1508### ffrt_task_handle_dec_ref() 1509 1510``` 1511FFRT_C_API uint32_t ffrt_task_handle_dec_ref (ffrt_task_handle_t handle) 1512``` 1513**Description** 1514Decreases the number of task handle references. 1515 1516**Since**: 12 1517 1518**Parameters** 1519 1520| Name| Description| 1521| -------- | -------- | 1522| handle | Task handle. | 1523 1524**Returns** 1525 1526Returns the original number of task handle references. 1527 1528 1529### ffrt_task_handle_destroy() 1530 1531``` 1532FFRT_C_API void ffrt_task_handle_destroy (ffrt_task_handle_t handle) 1533``` 1534**Description** 1535Destroys a task handle. 1536 1537**Since**: 10 1538 1539**Parameters** 1540 1541| Name| Description| 1542| -------- | -------- | 1543| handle | Task handle. | 1544 1545 1546### ffrt_task_handle_inc_ref() 1547 1548``` 1549FFRT_C_API uint32_t ffrt_task_handle_inc_ref (ffrt_task_handle_t handle) 1550``` 1551**Description** 1552Increases the number of task handle references. 1553 1554**Since**: 12 1555 1556**Parameters** 1557 1558| Name| Description| 1559| -------- | -------- | 1560| handle | Task handle. | 1561 1562**Returns** 1563 1564Returns the original number of task handle references. 1565 1566 1567### ffrt_this_task_get_id() 1568 1569``` 1570FFRT_C_API uint64_t ffrt_this_task_get_id (void ) 1571``` 1572**Description** 1573Obtains the ID of this task. 1574 1575**Since**: 10 1576 1577**Returns** 1578 1579Returns the ID. 1580 1581 1582### ffrt_this_task_get_qos() 1583 1584``` 1585FFRT_C_API ffrt_qos_t ffrt_this_task_get_qos (void ) 1586``` 1587**Description** 1588Obtains the task QoS. 1589 1590**Since**: 12 1591 1592**Returns** 1593 1594Returns the task QoS. 1595 1596 1597### ffrt_this_task_update_qos() 1598 1599``` 1600FFRT_C_API int ffrt_this_task_update_qos (ffrt_qos_t qos) 1601``` 1602**Description** 1603Updates the task QoS. 1604 1605**Since**: 10 1606 1607**Parameters** 1608 1609| Name| Description| 1610| -------- | -------- | 1611| qos | QoS to be updated. | 1612 1613**Returns** 1614 1615Returns **0** if the QoS is updated; returns **-1** otherwise. 1616 1617 1618### ffrt_timer_start() 1619 1620``` 1621FFRT_C_API ffrt_timer_t ffrt_timer_start (ffrt_qos_t qos, uint64_t timeout, void * data, ffrt_timer_cb cb, bool repeat ) 1622``` 1623**Description** 1624Starts the timer. 1625 1626**Since**: 12 1627 1628**Parameters** 1629 1630| Name| Description| 1631| -------- | -------- | 1632| qos | QoS. | 1633| timeout | Timeout duration of the timer. | 1634| data | Pointer to the input parameter in the callback function invoked upon a timeout. | 1635| cb | Callback function invoked upon a timeout. | 1636| repeat | Whether to repeat the timer (not supported yet). | 1637 1638**Returns** 1639 1640Returns the timer handle. 1641 1642 1643### ffrt_timer_stop() 1644 1645``` 1646FFRT_C_API int ffrt_timer_stop (ffrt_qos_t qos, ffrt_timer_t handle ) 1647``` 1648**Description** 1649Stops the timer. 1650 1651**Since**: 12 1652 1653**Parameters** 1654 1655| Name| Description| 1656| -------- | -------- | 1657| qos | QoS. | 1658| handle | Handle to the timer. | 1659 1660**Returns** 1661 1662Returns **0** if the timer is stopped; returns **-1** otherwise. 1663 1664 1665### ffrt_usleep() 1666 1667``` 1668FFRT_C_API int ffrt_usleep (uint64_t usec) 1669``` 1670**Description** 1671Sets the fixed sleep time. 1672 1673**Since**: 10 1674 1675**Parameters** 1676 1677| Name| Description| 1678| -------- | -------- | 1679| usec | Sleep time, in microseconds. | 1680 1681**Returns** 1682 1683Returns **ffrt_success** if the thread is suspended; returns **ffrt_error** otherwise. 1684 1685 1686### ffrt_wait() 1687 1688``` 1689FFRT_C_API void ffrt_wait (void ) 1690``` 1691**Description** 1692Waits until all submitted tasks are complete. 1693 1694**Since**: 10 1695 1696 1697### ffrt_wait_deps() 1698 1699``` 1700FFRT_C_API void ffrt_wait_deps (const ffrt_deps_t * deps) 1701``` 1702**Description** 1703Waits until the dependent tasks are complete. 1704 1705**Since**: 10 1706 1707**Parameters** 1708 1709| Name| Description| 1710| -------- | -------- | 1711| deps | Pointer to the dependencies. | 1712 1713 1714### ffrt_yield() 1715 1716``` 1717FFRT_C_API void ffrt_yield (void ) 1718``` 1719**Description** 1720Passes control to other tasks so that they can be executed. 1721 1722**Since**: 10 1723