• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# FFRT
2
3
4## 概述
5
6FFRT(Function Flow运行时)是支持Function Flow编程模型的软件运行时库,用于调度执行开发者基于Function Flow编程模型开发的应用。
7
8**系统能力:** SystemCapability.Resourceschedule.Ffrt.Core
9
10**起始版本:** 10
11
12
13## 汇总
14
15
16### 文件
17
18| 名称 | 描述 |
19| -------- | -------- |
20| [condition_variable.h](condition__variable_8h.md) | 声明条件变量提供的C接口. |
21| [mutex.h](mutex_8h.md) | 声明mutex提供的C接口. |
22| [queue.h](queue_8h.md) | 声明串行队列提供的C接口. |
23| [sleep.h](sleep_8h.md) | 声明sleep和yield C接口. |
24| [task.h](task_8h.md) | 声明任务提供的C接口. |
25| [type_def.h](type__def_8h.md) | 定义通用类型. |
26
27
28### 结构体
29
30| 名称 | 描述 |
31| -------- | -------- |
32| struct  [ffrt_function_header_t](ffrt__function__header__t.md) | 任务执行体. |
33| struct  [ffrt_dependence_t](ffrt__dependence__t.md) | 依赖数据结构. |
34| struct  [ffrt_deps_t](ffrt__deps__t.md) | 依赖结构定义. |
35| struct  [ffrt_task_attr_t](ffrt__task__attr__t.md) | 并行任务属性结构. |
36| struct  [ffrt_queue_attr_t](ffrt__queue__attr__t.md) | 串行队列属性结构. |
37| struct  [ffrt_condattr_t](ffrt__condattr__t.md) | FFRT条件变量属性结构. |
38| struct  [ffrt_mutexattr_t](ffrt__mutexattr__t.md) | FFRT锁属性结构. |
39| struct  [ffrt_mutex_t](ffrt__mutex__t.md) | FFRT互斥锁结构. |
40| struct  [ffrt_cond_t](ffrt__cond__t.md) | FFRT条件变量结构. |
41
42
43### 类型定义
44
45| 名称 | 描述 |
46| -------- | -------- |
47| typedef void \* ffrt_queue_t | 队列句柄. |
48| typedef int ffrt_qos_t | qos类型. |
49| typedef void(\* ffrt_function_t ) (void \*) | 任务执行函数指针类型. |
50| typedef void \* ffrt_task_handle_t | 并行任务句柄. |
51
52
53### 枚举
54
55| 名称 | 描述 |
56| -------- | -------- |
57| [ffrt_queue_type_t](#ffrt_queue_type_t) { ffrt_queue_serial, **ffrt_queue_max** } | 队列类型. |
58| [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/>} | 任务的qos类型. |
59| [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/>} | 多种类型数据结构分配大小定义. |
60| [ffrt_function_kind_t](#ffrt_function_kind_t) { ffrt_function_kind_general, ffrt_function_kind_queue } | 任务类型. |
61| [ffrt_dependence_type_t](#ffrt_dependence_type_t) { ffrt_dependence_data, ffrt_dependence_task } | 依赖类型. |
62| [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/>} | FFRT错误码. |
63
64
65### 函数
66
67| 名称 | 描述 |
68| -------- | -------- |
69| 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) | 初始化条件变量. |
70| FFRT_C_API int [ffrt_cond_signal](#ffrt_cond_signal) ([ffrt_cond_t](ffrt__cond__t.md) \*cond) | 唤醒阻塞在条件变量上的一个任务. |
71| FFRT_C_API int [ffrt_cond_broadcast](#ffrt_cond_broadcast) ([ffrt_cond_t](ffrt__cond__t.md) \*cond) | 唤醒阻塞在条件变量上的所有任务. |
72| 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) | 条件变量等待函数,条件变量不满足时阻塞当前任务. |
73| 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) | 条件变量超时等待函数,条件变量不满足时阻塞当前任务,超时等待返回. |
74| FFRT_C_API int [ffrt_cond_destroy](#ffrt_cond_destroy) ([ffrt_cond_t](ffrt__cond__t.md) \*cond) | 销毁掉件变量. |
75| 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) | 初始化mutex. |
76| FFRT_C_API int [ffrt_mutex_lock](#ffrt_mutex_lock) ([ffrt_mutex_t](ffrt__mutex__t.md) \*mutex) | 获取mutex. |
77| FFRT_C_API int [ffrt_mutex_unlock](#ffrt_mutex_unlock) ([ffrt_mutex_t](ffrt__mutex__t.md) \*mutex) | 释放mutex. |
78| FFRT_C_API int [ffrt_mutex_trylock](#ffrt_mutex_trylock) ([ffrt_mutex_t](ffrt__mutex__t.md) \*mutex) | 尝试获取mutex. |
79| FFRT_C_API int [ffrt_mutex_destroy](#ffrt_mutex_destroy) ([ffrt_mutex_t](ffrt__mutex__t.md) \*mutex) | 销毁mutex. |
80| FFRT_C_API int [ffrt_queue_attr_init](#ffrt_queue_attr_init) ([ffrt_queue_attr_t](ffrt__queue__attr__t.md) \*attr) | 初始化串行队列属性. |
81| FFRT_C_API void [ffrt_queue_attr_destroy](#ffrt_queue_attr_destroy) ([ffrt_queue_attr_t](ffrt__queue__attr__t.md) \*attr) | 销毁串行队列属性. |
82| 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) | 设置串行队列qos属性. |
83| 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) | 获取串行队列qos属性. |
84| 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) | 设置串行队列timeout属性. |
85| 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) | 获取串行队列任务执行的timeout时间. |
86| 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) | 设置串行队列超时回调方法. |
87| 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) | 获取串行队列超时回调方法. |
88| 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) | 创建队列. |
89| FFRT_C_API void [ffrt_queue_destroy](#ffrt_queue_destroy) (ffrt_queue_t queue) | 销毁队列. |
90| 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) | 提交一个任务到队列中调度执行. |
91| 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) | 提交一个任务到队列中调度执行,并返回任务句柄. |
92| FFRT_C_API void [ffrt_queue_wait](#ffrt_queue_wait) (ffrt_task_handle_t handle) | 等待队列中一个任务执行完成. |
93| FFRT_C_API int [ffrt_queue_cancel](#ffrt_queue_cancel) (ffrt_task_handle_t handle) | 取消队列中一个任务. |
94| FFRT_C_API int [ffrt_usleep](#ffrt_usleep) (uint64_t usec) | 延迟usec微秒. |
95| FFRT_C_API void [ffrt_yield](#ffrt_yield) (void) | 当前任务主动放权,让其他任务有机会调度执行. |
96| FFRT_C_API int [ffrt_task_attr_init](#ffrt_task_attr_init) ([ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr) | 初始化任务属性. |
97| 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) | 设置任务名字. |
98| 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) | 获取任务名字. |
99| FFRT_C_API void [ffrt_task_attr_destroy](#ffrt_task_attr_destroy) ([ffrt_task_attr_t](ffrt__task__attr__t.md) \*attr) | 销毁任务属性. |
100| 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) | 设置任务qos. |
101| 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) | 获取任务qos. |
102| 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) | 设置任务延迟时间. |
103| 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) | 获取任务延迟时间. |
104| FFRT_C_API int [ffrt_this_task_update_qos](#ffrt_this_task_update_qos) (ffrt_qos_t qos) | 更新任务qos. |
105| FFRT_C_API uint64_t [ffrt_this_task_get_id](#ffrt_this_task_get_id) (void) | 获取任务id. |
106| 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) | 申请函数执行结构的内存. |
107| 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) | 提交任务调度执行. |
108| 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) | 提交任务调度执行并返回任务句柄. |
109| FFRT_C_API void [ffrt_task_handle_destroy](#ffrt_task_handle_destroy) (ffrt_task_handle_t handle) | 销毁任务句柄. |
110| FFRT_C_API void [ffrt_wait_deps](#ffrt_wait_deps) (const [ffrt_deps_t](ffrt__deps__t.md) \*deps) | 等待依赖的任务完成,当前任务开始执行. |
111| FFRT_C_API void [ffrt_wait](#ffrt_wait) (void) | 等待之前所有提交任务完成,当前任务开始执行. |
112
113
114### 变量
115
116| 名称 | 描述 |
117| -------- | -------- |
118| ffrt_function_t[ffrt_function_header_t::exec](#exec) | 任务执行函数 |
119| ffrt_function_t[ffrt_function_header_t::destroy](#destroy) | 任务销毁函数 |
120| uint64_t [ffrt_function_header_t::reserve](#reserve) [2] | 保留位. |
121| [ffrt_dependence_type_t](#ffrt_dependence_type_t)[ffrt_dependence_t::type](#type) | 依赖类型 |
122| const void \* [ffrt_dependence_t::ptr](#ptr) | 依赖数据地址 |
123| uint32_t [ffrt_deps_t::len](#len) | 依赖数量 |
124| const [ffrt_dependence_t](ffrt__dependence__t.md) \* [ffrt_deps_t::items](#items) | 依赖数据 |
125| uint32_t [ffrt_task_attr_t::storage](#storage-46) [(ffrt_task_attr_storage_size+sizeof(uint32_t) - 1)/sizeof(uint32_t)] | 任务属性所占空间 |
126| uint32_t [ffrt_queue_attr_t::storage](#storage-36) [(ffrt_queue_attr_storage_size+sizeof(uint32_t) - 1)/sizeof(uint32_t)] | 串行队列属性所占空间 |
127| long [ffrt_condattr_t::storage](#storage-56) | FFRT条件变量属性所占空间 |
128| long [ffrt_mutexattr_t::storage](#storage-66) | FFRT锁属性所占空间 |
129| uint32_t [ffrt_mutex_t::storage](#storage-26) [(ffrt_mutex_storage_size+sizeof(uint32_t) - 1)/sizeof(uint32_t)] | FFRT互斥锁所占空间 |
130| uint32_t [ffrt_cond_t::storage](#storage-16) [(ffrt_cond_storage_size+sizeof(uint32_t) - 1)/sizeof(uint32_t)] | FFRT条件变量所占空间 |
131
132
133## 枚举类型说明
134
135
136### ffrt_dependence_type_t
137
138```
139enum ffrt_dependence_type_t
140```
141
142**描述**
143
144依赖类型.
145
146| 枚举值 | 描述 |
147| -------- | -------- |
148| ffrt_dependence_data | 数据依赖类型 |
149| ffrt_dependence_task | 任务依赖类型 |
150
151
152### ffrt_error_t
153
154```
155enum ffrt_error_t
156```
157
158**描述**
159
160FFRT错误码.
161
162| 枚举值 | 描述 |
163| -------- | -------- |
164| ffrt_error | 失败 |
165| ffrt_success | 成功 |
166| ffrt_error_nomem | 内存不足 |
167| ffrt_error_timedout | 超时 |
168| ffrt_error_busy | 重新尝试 |
169| ffrt_error_inval | 值无效 |
170
171
172### ffrt_function_kind_t
173
174```
175enum ffrt_function_kind_t
176```
177
178**描述**
179
180任务类型.
181
182| 枚举值 | 描述 |
183| -------- | -------- |
184| ffrt_function_kind_general | 通用任务类型 |
185| ffrt_function_kind_queue | 队列任务类型 |
186
187
188### ffrt_qos_default_t
189
190```
191enum ffrt_qos_default_t
192```
193
194**描述**
195
196任务的qos类型.
197
198| 枚举值 | 描述 |
199| -------- | -------- |
200| ffrt_qos_inherit | 继承当前任务qos属性 |
201| ffrt_qos_background | 后台任务 |
202| ffrt_qos_utility | 实时工具 |
203| ffrt_qos_default | 默认类型 |
204| ffrt_qos_user_initiated | 用户期望 |
205
206
207### ffrt_queue_type_t
208
209```
210enum ffrt_queue_type_t
211```
212
213**描述**
214
215队列类型.
216
217| 枚举值 | 描述 |
218| -------- | -------- |
219| ffrt_queue_serial | 串行队列类型 |
220
221
222### ffrt_storage_size_t
223
224```
225enum ffrt_storage_size_t
226```
227
228**描述**
229
230多种类型数据结构分配大小定义.
231
232| 枚举值 | 描述 |
233| -------- | -------- |
234| ffrt_task_attr_storage_size | 任务属性 |
235| ffrt_auto_managed_function_storage_size | 任务执行体 |
236| ffrt_mutex_storage_size | 互斥锁 |
237| ffrt_cond_storage_size | 条件变量 |
238| ffrt_queue_attr_storage_size | 队列属性 |
239
240
241## 函数说明
242
243
244### ffrt_alloc_auto_managed_function_storage_base()
245
246```
247FFRT_C_API void* ffrt_alloc_auto_managed_function_storage_base (ffrt_function_kind_t kind)
248```
249
250**描述**
251
252申请函数执行结构的内存.
253
254**起始版本:** 10
255
256**参数:**
257
258| 名称 | 描述 |
259| -------- | -------- |
260| kind | 函数执行结构类型,支持通用和队列函数执行结构类型. |
261
262**返回:**
263
264申请函数执行结构成功返回非空指针, 申请函数执行结构失败返回空指针.
265
266
267### ffrt_cond_broadcast()
268
269```
270FFRT_C_API int ffrt_cond_broadcast (ffrt_cond_t * cond)
271```
272
273**描述**
274
275唤醒阻塞在条件变量上的所有任务.
276
277**起始版本:** 10
278
279**参数:**
280
281| 名称 | 描述 |
282| -------- | -------- |
283| cond | 条件变量指针. |
284
285**返回:**
286
287唤醒成功返回ffrt_thrd_success, 唤醒失败返回ffrt_thrd_error.
288
289
290### ffrt_cond_destroy()
291
292```
293FFRT_C_API int ffrt_cond_destroy (ffrt_cond_t * cond)
294```
295
296**描述**
297
298销毁掉件变量.
299
300**起始版本:** 10
301
302**参数:**
303
304| 名称 | 描述 |
305| -------- | -------- |
306| cond | 条件变量指针. |
307
308**返回:**
309
310销毁条件变量成功返回ffrt_thrd_success, 销毁条件变量失败返回ffrt_thrd_error.
311
312
313### ffrt_cond_init()
314
315```
316FFRT_C_API int ffrt_cond_init (ffrt_cond_t * cond, const ffrt_condattr_t * attr )
317```
318
319**描述**
320
321初始化条件变量.
322
323**起始版本:** 10
324
325**参数:**
326
327| 名称 | 描述 |
328| -------- | -------- |
329| cond | 条件变量指针. |
330| attr | 条件变量属性指针. |
331
332**返回:**
333
334初始化条件变量成功返回ffrt_thrd_success, 初始化条件变量失败返回ffrt_thrd_error.
335
336
337### ffrt_cond_signal()
338
339```
340FFRT_C_API int ffrt_cond_signal (ffrt_cond_t * cond)
341```
342
343**描述**
344
345唤醒阻塞在条件变量上的一个任务.
346
347**起始版本:** 10
348
349**参数:**
350
351| 名称 | 描述 |
352| -------- | -------- |
353| cond | 条件变量指针. |
354
355**返回:**
356
357唤醒成功返回ffrt_thrd_success, 唤醒失败返回ffrt_thrd_error.
358
359
360### ffrt_cond_timedwait()
361
362```
363FFRT_C_API int ffrt_cond_timedwait (ffrt_cond_t * cond, ffrt_mutex_t * mutex, const struct timespec * time_point )
364```
365
366**描述**
367
368条件变量超时等待函数,条件变量不满足时阻塞当前任务,超时等待返回.
369
370**起始版本:** 10
371
372**参数:**
373
374| 名称 | 描述 |
375| -------- | -------- |
376| cond | 条件变量指针. |
377| mutex | mutex指针. |
378| time_point | 最大等待到的时间点,超过这个时间点等待返回. |
379
380**返回:**
381
382等待后被成功唤醒返回ffrt_thrd_success, 等待超时返回ffrt_thrd_timedout. 等待失败ffrt_thrd_error.
383
384
385### ffrt_cond_wait()
386
387```
388FFRT_C_API int ffrt_cond_wait (ffrt_cond_t * cond, ffrt_mutex_t * mutex )
389```
390
391**描述**
392
393条件变量等待函数,条件变量不满足时阻塞当前任务.
394
395**起始版本:** 10
396
397**参数:**
398
399| 名称 | 描述 |
400| -------- | -------- |
401| cond | 条件变量指针. |
402| mutex | mutex指针. |
403
404**返回:**
405
406等待后被成功唤醒返回ffrt_thrd_success, 等待失败返回ffrt_thrd_error.
407
408
409### ffrt_mutex_destroy()
410
411```
412FFRT_C_API int ffrt_mutex_destroy (ffrt_mutex_t * mutex)
413```
414
415**描述**
416
417销毁mutex.
418
419**起始版本:** 10
420
421**参数:**
422
423| 名称 | 描述 |
424| -------- | -------- |
425| mutex | mutex指针. |
426
427**返回:**
428
429销毁mutex成功返回ffrt_thrd_success, 销毁mutex失败返回ffrt_thrd_error.
430
431
432### ffrt_mutex_init()
433
434```
435FFRT_C_API int ffrt_mutex_init (ffrt_mutex_t * mutex, const ffrt_mutexattr_t * attr )
436```
437
438**描述**
439
440初始化mutex.
441
442**起始版本:** 10
443
444**参数:**
445
446| 名称 | 描述 |
447| -------- | -------- |
448| mutex | mutex指针. |
449| attr | mutex属性. |
450
451**返回:**
452
453初始化mutex成功返回ffrt_thrd_success, 初始化mutex失败返回ffrt_thrd_error.
454
455
456### ffrt_mutex_lock()
457
458```
459FFRT_C_API int ffrt_mutex_lock (ffrt_mutex_t * mutex)
460```
461
462**描述**
463
464获取mutex.
465
466**起始版本:** 10
467
468**参数:**
469
470| 名称 | 描述 |
471| -------- | -------- |
472| mutex | mutex指针. |
473
474**返回:**
475
476获取mutex成功返回ffrt_thrd_success, 获取mutex失败返回ffrt_thrd_error,或者阻塞当前任务.
477
478
479### ffrt_mutex_trylock()
480
481```
482FFRT_C_API int ffrt_mutex_trylock (ffrt_mutex_t * mutex)
483```
484
485**描述**
486
487尝试获取mutex.
488
489**起始版本:** 10
490
491**参数:**
492
493| 名称 | 描述 |
494| -------- | -------- |
495| mutex | mutex指针. |
496
497**返回:**
498
499获取mutex成功返回ffrt_thrd_success, 获取mutex失败返回ffrt_thrd_error或ffrt_thrd_busy.
500
501
502### ffrt_mutex_unlock()
503
504```
505FFRT_C_API int ffrt_mutex_unlock (ffrt_mutex_t * mutex)
506```
507
508**描述**
509
510释放mutex.
511
512**起始版本:** 10
513
514**参数:**
515
516| 名称 | 描述 |
517| -------- | -------- |
518| mutex | mutex指针. |
519
520**返回:**
521
522释放mutex成功返回ffrt_thrd_success, 释放mutex失败返回ffrt_thrd_error.
523
524
525### ffrt_queue_attr_destroy()
526
527```
528FFRT_C_API void ffrt_queue_attr_destroy (ffrt_queue_attr_t * attr)
529```
530
531**描述**
532
533销毁串行队列属性.
534
535**起始版本:** 10
536
537**参数:**
538
539| 名称 | 描述 |
540| -------- | -------- |
541| attr | 串行队列属性指针. |
542
543
544### ffrt_queue_attr_get_callback()
545
546```
547FFRT_C_API ffrt_function_header_t* ffrt_queue_attr_get_callback (const ffrt_queue_attr_t * attr)
548```
549
550**描述**
551
552获取串行队列超时回调方法.
553
554**起始版本:** 10
555
556**参数:**
557
558| 名称 | 描述 |
559| -------- | -------- |
560| attr | 串行队列属性指针. |
561
562**返回:**
563
564返回串行队列超时回调方法.
565
566
567### ffrt_queue_attr_get_qos()
568
569```
570FFRT_C_API ffrt_qos_t ffrt_queue_attr_get_qos (const ffrt_queue_attr_t * attr)
571```
572
573**描述**
574
575获取串行队列qos属性.
576
577**起始版本:** 10
578
579**参数:**
580
581| 名称 | 描述 |
582| -------- | -------- |
583| attr | 串行队列属性指针. |
584
585**返回:**
586
587返回串行队列的qos属性.
588
589
590### ffrt_queue_attr_get_timeout()
591
592```
593FFRT_C_API uint64_t ffrt_queue_attr_get_timeout (const ffrt_queue_attr_t * attr)
594```
595
596**描述**
597
598获取串行队列任务执行的timeout时间.
599
600**起始版本:** 10
601
602**参数:**
603
604| 名称 | 描述 |
605| -------- | -------- |
606| attr | 串行队列属性指针. |
607
608**返回:**
609
610返回串行队列任务执行的timeout时间.
611
612
613### ffrt_queue_attr_init()
614
615```
616FFRT_C_API int ffrt_queue_attr_init (ffrt_queue_attr_t * attr)
617```
618
619**描述**
620
621初始化串行队列属性.
622
623**起始版本:** 10
624
625**参数:**
626
627| 名称 | 描述 |
628| -------- | -------- |
629| attr | 串行队列属性指针. |
630
631**返回:**
632
633执行成功时返回0, 执行成功时返回-1.
634
635
636### ffrt_queue_attr_set_callback()
637
638```
639FFRT_C_API void ffrt_queue_attr_set_callback (ffrt_queue_attr_t * attr, ffrt_function_header_t * f )
640```
641
642**描述**
643
644设置串行队列超时回调方法.
645
646**起始版本:** 10
647
648**参数:**
649
650| 名称 | 描述 |
651| -------- | -------- |
652| attr | 串行队列属性指针. |
653| f | 超时回调方法执行体. |
654
655
656### ffrt_queue_attr_set_qos()
657
658```
659FFRT_C_API void ffrt_queue_attr_set_qos (ffrt_queue_attr_t * attr, ffrt_qos_t qos )
660```
661
662**描述**
663
664设置串行队列qos属性.
665
666**起始版本:** 10
667
668**参数:**
669
670| 名称 | 描述 |
671| -------- | -------- |
672| attr | 串行队列属性指针. |
673| qos | qos属性值. |
674
675
676### ffrt_queue_attr_set_timeout()
677
678```
679FFRT_C_API void ffrt_queue_attr_set_timeout (ffrt_queue_attr_t * attr, uint64_t timeout_us )
680```
681
682**描述**
683
684设置串行队列timeout属性.
685
686**起始版本:** 10
687
688**参数:**
689
690| 名称 | 描述 |
691| -------- | -------- |
692| attr | 串行队列属性指针. |
693| timeout_us | 串行队列任务执行的timeout时间. |
694
695
696### ffrt_queue_cancel()
697
698```
699FFRT_C_API int ffrt_queue_cancel (ffrt_task_handle_t handle)
700```
701
702**描述**
703
704取消队列中一个任务.
705
706**起始版本:** 10
707
708**参数:**
709
710| 名称 | 描述 |
711| -------- | -------- |
712| handle | 任务句柄. |
713
714**返回:**
715
716取消任务成功返回0 取消任务失败返回-1
717
718
719### ffrt_queue_create()
720
721```
722FFRT_C_API ffrt_queue_t ffrt_queue_create (ffrt_queue_type_t type, const char * name, const ffrt_queue_attr_t * attr )
723```
724
725**描述**
726
727创建队列.
728
729**起始版本:** 10
730
731**参数:**
732
733| 名称 | 描述 |
734| -------- | -------- |
735| type | 队列类型. |
736| name | 队列名字. |
737| attr | 队列属性. |
738
739**返回:**
740
741创建队列成功返回非空队列句柄 创建队列失败返回空指针
742
743
744### ffrt_queue_destroy()
745
746```
747FFRT_C_API void ffrt_queue_destroy (ffrt_queue_t queue)
748```
749
750**描述**
751
752销毁队列.
753
754**起始版本:** 10
755
756**参数:**
757
758| 名称 | 描述 |
759| -------- | -------- |
760| queue | 队列句柄. |
761
762
763### ffrt_queue_submit()
764
765```
766FFRT_C_API void ffrt_queue_submit (ffrt_queue_t queue, ffrt_function_header_t * f, const ffrt_task_attr_t * attr )
767```
768
769**描述**
770
771提交一个任务到队列中调度执行.
772
773**起始版本:** 10
774
775**参数:**
776
777| 名称 | 描述 |
778| -------- | -------- |
779| queue | 队列句柄. |
780| f | 任务的执行体. |
781| attr | 任务属性. |
782
783
784### ffrt_queue_submit_h()
785
786```
787FFRT_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 )
788```
789
790**描述**
791
792提交一个任务到队列中调度执行,并返回任务句柄.
793
794**起始版本:** 10
795
796**参数:**
797
798| 名称 | 描述 |
799| -------- | -------- |
800| queue | 队列句柄. |
801| f | 任务的执行体. |
802| attr | 任务属性. |
803
804**返回:**
805
806提交成功返回非空任务句柄; 提交失败返回空指针
807
808
809### ffrt_queue_wait()
810
811```
812FFRT_C_API void ffrt_queue_wait (ffrt_task_handle_t handle)
813```
814
815**描述**
816
817等待队列中一个任务执行完成.
818
819**起始版本:** 10
820
821**参数:**
822
823| 名称 | 描述 |
824| -------- | -------- |
825| handle | 任务句柄. |
826
827
828### ffrt_submit_base()
829
830```
831FFRT_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 )
832```
833
834**描述**
835
836提交任务调度执行.
837
838**起始版本:** 10
839
840**参数:**
841
842| 名称 | 描述 |
843| -------- | -------- |
844| f | 任务执行体封装的指针. |
845| in_deps | 输入依赖指针. |
846| out_deps | 输出依赖指针. |
847| attr | 任务属性. |
848
849
850### ffrt_submit_h_base()
851
852```
853FFRT_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 )
854```
855
856**描述**
857
858提交任务调度执行并返回任务句柄.
859
860**起始版本:** 10
861
862**参数:**
863
864| 名称 | 描述 |
865| -------- | -------- |
866| f | 任务执行体封装的指针. |
867| in_deps | 输入依赖指针. |
868| out_deps | 输出依赖指针. |
869| attr | 任务属性. |
870
871**返回:**
872
873提交任务成功返回非空任务句柄, 提交任务失败返回空指针.
874
875
876### ffrt_task_attr_destroy()
877
878```
879FFRT_C_API void ffrt_task_attr_destroy (ffrt_task_attr_t * attr)
880```
881
882**描述**
883
884销毁任务属性.
885
886**起始版本:** 10
887
888**参数:**
889
890| 名称 | 描述 |
891| -------- | -------- |
892| attr | 任务属性指针. |
893
894
895### ffrt_task_attr_get_delay()
896
897```
898FFRT_C_API uint64_t ffrt_task_attr_get_delay (const ffrt_task_attr_t * attr)
899```
900
901**描述**
902
903获取任务延迟时间.
904
905**起始版本:** 10
906
907**参数:**
908
909| 名称 | 描述 |
910| -------- | -------- |
911| attr | 任务属性指针. |
912
913**返回:**
914
915返回任务的延迟时间
916
917
918### ffrt_task_attr_get_name()
919
920```
921FFRT_C_API const char* ffrt_task_attr_get_name (const ffrt_task_attr_t * attr)
922```
923
924**描述**
925
926获取任务名字.
927
928**起始版本:** 10
929
930**参数:**
931
932| 名称 | 描述 |
933| -------- | -------- |
934| attr | 任务属性指针. |
935
936**返回:**
937
938获取任务名字成功返回非空指针, 获取任务名字失败返回空指针.
939
940
941### ffrt_task_attr_get_qos()
942
943```
944FFRT_C_API ffrt_qos_t ffrt_task_attr_get_qos (const ffrt_task_attr_t * attr)
945```
946
947**描述**
948
949获取任务qos.
950
951**起始版本:** 10
952
953**参数:**
954
955| 名称 | 描述 |
956| -------- | -------- |
957| attr | 任务属性指针. |
958
959**返回:**
960
961返回任务的qos,默认返回ffrt_qos_default
962
963
964### ffrt_task_attr_init()
965
966```
967FFRT_C_API int ffrt_task_attr_init (ffrt_task_attr_t * attr)
968```
969
970**描述**
971
972初始化任务属性.
973
974**起始版本:** 10
975
976**参数:**
977
978| 名称 | 描述 |
979| -------- | -------- |
980| attr | 任务属性指针. |
981
982**返回:**
983
984初始化任务属性成功返回0, 初始化任务属性失败返回-1.
985
986
987### ffrt_task_attr_set_delay()
988
989```
990FFRT_C_API void ffrt_task_attr_set_delay (ffrt_task_attr_t * attr, uint64_t delay_us )
991```
992
993**描述**
994
995设置任务延迟时间.
996
997**起始版本:** 10
998
999**参数:**
1000
1001| 名称 | 描述 |
1002| -------- | -------- |
1003| attr | 任务属性指针. |
1004| delay_us | 任务延迟时间,单位微秒. |
1005
1006
1007### ffrt_task_attr_set_name()
1008
1009```
1010FFRT_C_API void ffrt_task_attr_set_name (ffrt_task_attr_t * attr, const char * name )
1011```
1012
1013**描述**
1014
1015设置任务名字.
1016
1017**起始版本:** 10
1018
1019**参数:**
1020
1021| 名称 | 描述 |
1022| -------- | -------- |
1023| attr | 任务属性指针. |
1024| name | 任务名字. |
1025
1026
1027### ffrt_task_attr_set_qos()
1028
1029```
1030FFRT_C_API void ffrt_task_attr_set_qos (ffrt_task_attr_t * attr, ffrt_qos_t qos )
1031```
1032
1033**描述**
1034
1035设置任务qos.
1036
1037**起始版本:** 10
1038
1039**参数:**
1040
1041| 名称 | 描述 |
1042| -------- | -------- |
1043| attr | 任务属性指针. |
1044| qos | 任务qos类型. |
1045
1046
1047### ffrt_task_handle_destroy()
1048
1049```
1050FFRT_C_API void ffrt_task_handle_destroy (ffrt_task_handle_t handle)
1051```
1052
1053**描述**
1054
1055销毁任务句柄.
1056
1057**起始版本:** 10
1058
1059**参数:**
1060
1061| 名称 | 描述 |
1062| -------- | -------- |
1063| handle | 任务句柄. |
1064
1065
1066### ffrt_this_task_get_id()
1067
1068```
1069FFRT_C_API uint64_t ffrt_this_task_get_id (void )
1070```
1071
1072**描述**
1073
1074获取任务id.
1075
1076**起始版本:** 10
1077
1078**返回:**
1079
1080返回当前任务的id
1081
1082
1083### ffrt_this_task_update_qos()
1084
1085```
1086FFRT_C_API int ffrt_this_task_update_qos (ffrt_qos_t qos)
1087```
1088
1089**描述**
1090
1091更新任务qos.
1092
1093**起始版本:** 10
1094
1095**参数:**
1096
1097| 名称 | 描述 |
1098| -------- | -------- |
1099| qos | 更新的qos,更新当前任务的qos. |
1100
1101**返回:**
1102
1103更新任务qos成功返回0, 更新任务qos成功返回-1.
1104
1105
1106### ffrt_usleep()
1107
1108```
1109FFRT_C_API int ffrt_usleep (uint64_t usec)
1110```
1111
1112**描述**
1113
1114延迟usec微秒.
1115
1116**起始版本:** 10
1117
1118**参数:**
1119
1120| 名称 | 描述 |
1121| -------- | -------- |
1122| usec延迟时间,单位微秒. |  |
1123
1124**返回:**
1125
1126执行成功时返回ffrt_thrd_success, 执行成功时返回ffrt_thrd_error.
1127
1128
1129### ffrt_wait()
1130
1131```
1132FFRT_C_API void ffrt_wait (void )
1133```
1134
1135**描述**
1136
1137等待之前所有提交任务完成,当前任务开始执行.
1138
1139**起始版本:** 10
1140
1141
1142### ffrt_wait_deps()
1143
1144```
1145FFRT_C_API void ffrt_wait_deps (const ffrt_deps_t * deps)
1146```
1147
1148**描述**
1149
1150等待依赖的任务完成,当前任务开始执行.
1151
1152**起始版本:** 10
1153
1154**参数:**
1155
1156| 名称 | 描述 |
1157| -------- | -------- |
1158| deps | 依赖的指针. |
1159
1160
1161### ffrt_yield()
1162
1163```
1164FFRT_C_API void ffrt_yield (void )
1165```
1166
1167**描述**
1168
1169当前任务主动放权,让其他任务有机会调度执行.
1170
1171**起始版本:** 10
1172
1173
1174## 变量说明
1175
1176
1177### destroy
1178
1179```
1180ffrt_function_t ffrt_function_header_t::destroy
1181```
1182
1183**描述**
1184
1185任务销毁函数
1186
1187
1188### exec
1189
1190```
1191ffrt_function_t ffrt_function_header_t::exec
1192```
1193
1194**描述**
1195
1196任务执行函数
1197
1198
1199### items
1200
1201```
1202const ffrt_dependence_t* ffrt_deps_t::items
1203```
1204
1205**描述**
1206
1207依赖数据
1208
1209
1210### len
1211
1212```
1213uint32_t ffrt_deps_t::len
1214```
1215
1216**描述**
1217
1218依赖数量
1219
1220
1221### ptr
1222
1223```
1224const void* ffrt_dependence_t::ptr
1225```
1226
1227**描述**
1228
1229依赖数据地址
1230
1231
1232### reserve
1233
1234```
1235uint64_t ffrt_function_header_t::reserve[2]
1236```
1237
1238**描述**
1239
1240保留位.
1241
1242
1243### storage [1/6]
1244
1245```
1246uint32_t ffrt_cond_t::storage[(ffrt_cond_storage_size+sizeof(uint32_t) - 1)/sizeof(uint32_t)]
1247```
1248
1249**描述**
1250
1251FFRT条件变量所占空间
1252
1253
1254### storage [2/6]
1255
1256```
1257uint32_t ffrt_mutex_t::storage[(ffrt_mutex_storage_size+sizeof(uint32_t) - 1)/sizeof(uint32_t)]
1258```
1259
1260**描述**
1261
1262FFRT互斥锁所占空间
1263
1264
1265### storage [3/6]
1266
1267```
1268uint32_t ffrt_queue_attr_t::storage[(ffrt_queue_attr_storage_size+sizeof(uint32_t) - 1)/sizeof(uint32_t)]
1269```
1270
1271**描述**
1272
1273串行队列属性所占空间
1274
1275
1276### storage [4/6]
1277
1278```
1279uint32_t ffrt_task_attr_t::storage[(ffrt_task_attr_storage_size+sizeof(uint32_t) - 1)/sizeof(uint32_t)]
1280```
1281
1282**描述**
1283
1284任务属性所占空间
1285
1286
1287### storage [5/6]
1288
1289```
1290long ffrt_condattr_t::storage
1291```
1292
1293**描述**
1294
1295FFRT条件变量属性所占空间
1296
1297
1298### storage [6/6]
1299
1300```
1301long ffrt_mutexattr_t::storage
1302```
1303
1304**描述**
1305
1306FFRT锁属性所占空间
1307
1308
1309### type
1310
1311```
1312ffrt_dependence_type_t ffrt_dependence_t::type
1313```
1314
1315**描述**
1316
1317依赖类型
1318