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