openharmony 鸿蒙 capi-queue-h

2026-08-25 浏览 (1)

queue.h

Overview

The queue.h file declares the queue APIs in C.

File to include: <ffrt/queue.h>

Library: libffrt.z.so

System capability: SystemCapability.Resourceschedule.Ffrt.Core

Since: 10

Related module: FFRT

Summary

Structs

NameDescription
ffrt_queue_tQueue handle.

Enums

Nametypedef KeywordDescription
ffrt_queue_type_tffrt_queue_type_tEnumerates the queue types.

Function

NameDescription
FFRT_C_API int ffrt_queue_attr_init(ffrt_queue_attr_t* attr)Initializes the queue attribute.
FFRT_C_API void ffrt_queue_attr_destroy(ffrt_queue_attr_t* attr)Destroys the queue attribute.
FFRT_C_API void ffrt_queue_attr_set_qos(ffrt_queue_attr_t* attr, ffrt_qos_t qos)Sets the queue QoS.
FFRT_C_API ffrt_qos_t ffrt_queue_attr_get_qos(const ffrt_queue_attr_t* attr)Obtains the queue QoS.
FFRT_C_API void ffrt_queue_attr_set_timeout(ffrt_queue_attr_t* attr, uint64_t timeout_us)Sets the queue timeout. The minimum timeout value is 1 ms. Any value set below this threshold will default to 1 ms.
FFRT_C_API uint64_t ffrt_queue_attr_get_timeout(const ffrt_queue_attr_t* attr)Obtains the queue timeout.
FFRT_C_API void ffrt_queue_attr_set_callback(ffrt_queue_attr_t* attr, ffrt_function_header_t* f)Sets a callback that is invoked when a queue task times out.
You are not advised to call the exit function in f. Otherwise, undefined behavior may occur.
FFRT_C_API ffrt_function_header_t* ffrt_queue_attr_get_callback(const ffrt_queue_attr_t* attr)Obtains the callback that is invoked when a queue task times out.
FFRT_C_API void ffrt_queue_attr_set_max_concurrency(ffrt_queue_attr_t* attr, const int max_concurrency)Sets the maximum concurrency for a queue, which must be a concurrent queue.
FFRT_C_API int ffrt_queue_attr_get_max_concurrency(const ffrt_queue_attr_t* attr)Obtains the maximum concurrency of a queue, which must be a concurrent queue.
FFRT_C_API void ffrt_queue_attr_set_thread_mode(ffrt_queue_attr_t* attr, bool mode)Sets the running mode of tasks in the queue. By default, the coroutine mode is used.
FFRT_C_API bool ffrt_queue_attr_get_thread_mode(const ffrt_queue_attr_t* attr)Obtains the running mode of tasks in the queue.
FFRT_C_API ffrt_queue_t ffrt_queue_create(ffrt_queue_type_t type, const char* name, const ffrt_queue_attr_t* attr)Creates a queue.
FFRT_C_API void ffrt_queue_destroy(ffrt_queue_t queue)Destroys a queue.
FFRT_C_API void ffrt_queue_submit(ffrt_queue_t queue, ffrt_function_header_t* f, const ffrt_task_attr_t* attr)Submits a task to a queue.
FFRT_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)Submits a task to a queue, and obtains the task handle.
FFRT_C_API void ffrt_queue_submit_f(ffrt_queue_t queue, ffrt_function_t func, void* arg, const ffrt_task_attr_t* attr)Submits a task to a queue. It is a simplified wrapper of ffrt_queue_submit. This API assumes that the callback function does not need to be destroyed. The task function and parameters are encapsulated into a queue task structure, which is then passed to ffrt_queue_submit along with other parameters.
FFRT_C_API ffrt_task_handle_t ffrt_queue_submit_h_f(ffrt_queue_t queue, ffrt_function_t func, void* arg, const ffrt_task_attr_t* attr)Submits a task to a queue, and obtains the task handle. It is a simplified wrapper of ffrt_queue_submit_h. This API assumes that the callback function does not need to be destroyed. The task function and parameters are encapsulated into a queue task structure, which is then passed to ffrt_queue_submit_h along with other parameters.
FFRT_C_API void ffrt_queue_wait(ffrt_task_handle_t handle)Waits until a task in the queue is complete.
FFRT_C_API int ffrt_queue_cancel(ffrt_task_handle_t handle)Cancels a task in the queue.
FFRT_C_API ffrt_queue_t ffrt_get_main_queue(void)Obtains the main thread queue.
FFRT_C_API ffrt_queue_t ffrt_get_current_queue(void)Obtains the ArkTS Worker thread queue. (It is deprecated since API version 18.)

Enum Description

ffrt_queue_type_t

enum ffrt_queue_type_t

Description

Enumerates the queue types.

Since: 12

Enum ItemDescription
ffrt_queue_serialSerial queue.
ffrt_queue_concurrentConcurrent queue.
ffrt_queue_maxInvalid queue type.

Function Description

ffrt_queue_attr_init()

FFRT_C_API int ffrt_queue_attr_init(ffrt_queue_attr_t* attr)

Description

Initializes the queue attribute.

Since: 10

Parameters

NameDescription
ffrt_queue_attr_t* attrPointer to the queue attribute.

Returns

TypeDescription
FFRT_C_API intReturns 0 if the queue attribute is initialized;
returns -1 otherwise.

ffrt_queue_attr_destroy()

FFRT_C_API void ffrt_queue_attr_destroy(ffrt_queue_attr_t* attr)

Description

Destroys the queue attribute.

Since: 10

Parameters

NameDescription
ffrt_queue_attr_t* attrPointer to the queue attribute.

ffrt_queue_attr_set_qos()

FFRT_C_API void ffrt_queue_attr_set_qos(ffrt_queue_attr_t* attr, ffrt_qos_t qos)

Description

Sets the queue QoS.

Since: 10

Parameters

NameDescription
ffrt_queue_attr_t* attrPointer to the queue attribute.
ffrt_qos_t qosQoS.

ffrt_queue_attr_get_qos()

FFRT_C_API ffrt_qos_t ffrt_queue_attr_get_qos(const ffrt_queue_attr_t* attr)

Description

Obtains the queue QoS.

Since: 10

Parameters

NameDescription
const ffrt_queue_attr_t* attrPointer to the queue attribute.

Returns

TypeDescription
FFRT_C_API ffrt_qos_tReturns the queue QoS.

ffrt_queue_attr_set_timeout()

FFRT_C_API void ffrt_queue_attr_set_timeout(ffrt_queue_attr_t* attr, uint64_t timeout_us)

Description

Sets the serial queue timeout. The minimum timeout value is 1 ms. Any value set below this threshold will default to 1 ms.

Since: 10

Parameters

NameDescription
ffrt_queue_attr_t* attrPointer to the serial queue attribute.
uint64_t timeout_usSerial queue timeout, in microseconds.

ffrt_queue_attr_get_timeout()

FFRT_C_API uint64_t ffrt_queue_attr_get_timeout(const ffrt_queue_attr_t* attr)

Description

Obtains the serial queue timeout.

Since: 10

Parameters

NameDescription
const ffrt_queue_attr_t* attrPointer to the serial queue attribute.

Returns

TypeDescription
FFRT_C_API uint64_tReturns the serial queue timeout.

ffrt_queue_attr_set_callback()

FFRT_C_API void ffrt_queue_attr_set_callback(ffrt_queue_attr_t* attr, ffrt_function_header_t* f)

Description

Sets a callback that is invoked when a queue task times out.

You are not advised to call the exit function in f. Otherwise, undefined behavior may occur.

Since: 10

Parameters

NameDescription
ffrt_queue_attr_t* attrPointer to the serial queue attribute.
ffrt_function_header_t* fPointer to the callback function invoked upon a timeout.

ffrt_queue_attr_get_callback()

FFRT_C_API ffrt_function_header_t* ffrt_queue_attr_get_callback(const ffrt_queue_attr_t* attr)

Description

Obtains the callback that is invoked when a queue task times out.

Since: 10

Parameters

NameDescription
const ffrt_queue_attr_t* attrPointer to the serial queue attribute.

Returns

TypeDescription
FFRT_C_API ffrt_function_header_t*Returns the callback.

ffrt_queue_attr_set_max_concurrency()

FFRT_C_API void ffrt_queue_attr_set_max_concurrency(ffrt_queue_attr_t* attr, const int max_concurrency)

Description

Sets the maximum concurrency for a concurrent queue.

Since: 12

Parameters

NameDescription
ffrt_queue_attr_t* attrPointer to the queue attribute.
const int max_concurrencyMaximum concurrency.

ffrt_queue_attr_get_max_concurrency()

FFRT_C_API int ffrt_queue_attr_get_max_concurrency(const ffrt_queue_attr_t* attr)

Description

Obtains the maximum concurrency of a concurrent queue.

Since: 12

Parameters

NameDescription
const ffrt_queue_attr_t* attrPointer to the queue attribute.

Returns

TypeDescription
FFRT_C_API intReturns the maximum concurrency.

ffrt_queue_attr_set_thread_mode()

FFRT_C_API void ffrt_queue_attr_set_thread_mode(ffrt_queue_attr_t* attr, bool mode)

Description

Sets the running mode of tasks in the queue. By default, the coroutine mode is used.

Since: 20

Parameters

NameDescription
ffrt_queue_attr_t* attrPointer to the queue attribute.
bool modeSets the running mode of the queue task. The value true indicates the thread mode, and the value false indicates the coroutine mode.

ffrt_queue_attr_get_thread_mode()

FFRT_C_API bool ffrt_queue_attr_get_thread_mode(const ffrt_queue_attr_t* attr)

Description

Obtains the running mode of tasks in the queue.

Since: 20

Parameters

NameDescription
const ffrt_queue_attr_t* attrPointer to the queue attribute.

Returns

TypeDescription
FFRT_C_API boolThe value true indicates the thread mode, and the value false indicates the coroutine mode.

ffrt_queue_create()

FFRT_C_API ffrt_queue_t ffrt_queue_create(ffrt_queue_type_t type, const char* name, const ffrt_queue_attr_t* attr)

Description

Creates a queue.

Since: 10

Parameters

NameDescription
ffrt_queue_type_t typeQueue type.
const char* namePointer to the queue name.
const ffrt_queue_attr_t* attrPointer to the queue attribute.

Returns

TypeDescription
FFRT_C_API ffrt_queue_tReturns a non-null queue handle if the queue is created;
returns a null pointer otherwise.

ffrt_queue_destroy()

FFRT_C_API void ffrt_queue_destroy(ffrt_queue_t queue)

Description

Destroys a queue.

Since: 10

Parameters

NameDescription
ffrt_queue_t queueQueue handle.

ffrt_queue_submit()

FFRT_C_API void ffrt_queue_submit(ffrt_queue_t queue, ffrt_function_header_t* f, const ffrt_task_attr_t* attr)

Description

Submits a task to a queue.

Since: 10

Parameters

NameDescription
ffrt_queue_t queueQueue handle.
ffrt_function_header_t* fPointer to the task execution function.
const ffrt_task_attr_t* attrPointer to the task attribute.

ffrt_queue_submit_h()

FFRT_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)

Description

Submits a task to a queue, and obtains the task handle.

Since: 10

Parameters

NameDescription
ffrt_queue_t queueQueue handle.
ffrt_function_header_t* fPointer to the task execution function.
const ffrt_task_attr_t* attrPointer to the task attribute.

Returns

TypeDescription
FFRT_C_API ffrt_task_handle_tReturns a non-null task handle if the task is submitted;
returns a null pointer otherwise.

ffrt_queue_submit_f()

FFRT_C_API void ffrt_queue_submit_f(ffrt_queue_t queue, ffrt_function_t func, void* arg, const ffrt_task_attr_t* attr)

Description

Submits a task to a queue. It is a simplified wrapper of ffrt_queue_submit. This API assumes that the callback function does not need to be destroyed. The task function and parameters are encapsulated into a queue task structure, which is then passed to ffrt_queue_submit along with other parameters.

Since: 20

Parameters

NameDescription
ffrt_queue_t queueQueue handle.
ffrt_function_t funcTask function.
void* argPointer to the argument.
const ffrt_task_attr_t* attrPointer to the task attribute.

References

ffrt_queue_submit

ffrt_queue_submit_h_f()

FFRT_C_API ffrt_task_handle_t ffrt_queue_submit_h_f(ffrt_queue_t queue, ffrt_function_t func, void* arg, const ffrt_task_attr_t* attr)

Description

Submits a task to a queue, and obtains the task handle. It is a simplified wrapper of ffrt_queue_submit_h. This API assumes that the callback function does not need to be destroyed. The task function and parameters are encapsulated into a queue task structure, which is then passed to ffrt_queue_submit_h along with other parameters.

Since: 20

Parameters

NameDescription
ffrt_queue_t queueQueue handle.
ffrt_function_t funcTask function.
void* argPointer to the argument.
const ffrt_task_attr_t* attrPointer to the task attribute.

Returns

TypeDescription
FFRT_C_API ffrt_task_handle_tReturns a non-null task handle if the task is submitted;
returns a null pointer otherwise.

References

ffrt_queue_submit_h

ffrt_queue_wait()

FFRT_C_API void ffrt_queue_wait(ffrt_task_handle_t handle)

Description

Waits until a task in the queue is complete.

Since: 10

Parameters

NameDescription
ffrt_task_handle_t handleTask handle.

ffrt_queue_cancel()

FFRT_C_API int ffrt_queue_cancel(ffrt_task_handle_t handle)

Description

Cancels a task in the queue.

Since: 10

Parameters

NameDescription
ffrt_task_handle_t handleTask handle.

Returns

TypeDescription
FFRT_C_API intReturns 0 if the task is canceled;
returns -1 otherwise.

ffrt_get_main_queue()

FFRT_C_API ffrt_queue_t ffrt_get_main_queue(void)

Description

Obtains the main thread queue.

Since: 12

Returns

TypeDescription
FFRT_C_API ffrt_queue_tReturns the handle to the main thread queue.

ffrt_get_current_queue()

FFRT_C_API ffrt_queue_t ffrt_get_current_queue(void)

Description

Obtains the ArkTS Worker thread queue.

Since: 12

Deprecated from: 18

Returns

TypeDescription
FFRT_C_API ffrt_queue_tReturns the handle to the thread queue.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-fiber-h

openharmony 鸿蒙 capi-ffrt-ffrt-mutex-t

openharmony 鸿蒙 capi-ffrt-ffrt-rwlockattr-t

openharmony 鸿蒙 capi-loop-h

openharmony 鸿蒙 Readme-EN

openharmony 鸿蒙 capi-ffrt-ffrt-rwlock-t

openharmony 鸿蒙 capi-shared-mutex-h

openharmony 鸿蒙 capi-ffrt-ffrt-queue-attr-t

openharmony 鸿蒙 capi-ffrt

openharmony 鸿蒙 capi-ffrt-ffrt-fiber-t

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/bppG3jdc