openharmony 鸿蒙 capi-condition-variable-h

2026-08-25 浏览 (1)

condition_variable.h

Overview

The condition_variable.h file declares the condition variable APIs in C.

File to include: <ffrt/condition_variable.h>

Library: libffrt.z.so

System capability: SystemCapability.Resourceschedule.Ffrt.Core

Since: 10

Related module: FFRT

Summary

Function

NameDescription
FFRT_C_API int ffrt_cond_init(ffrt_cond_t* cond, const ffrt_condattr_t* attr)Initializes a condition variable.
FFRT_C_API int ffrt_cond_signal(ffrt_cond_t* cond)Unblocks at least one of the threads that are blocked on a condition variable.
FFRT_C_API int ffrt_cond_broadcast(ffrt_cond_t* cond)Unblocks all threads currently blocked on a condition variable.
FFRT_C_API int ffrt_cond_wait(ffrt_cond_t* cond, ffrt_mutex_t* mutex)Blocks the calling thread on a condition variable.
FFRT_C_API int ffrt_cond_timedwait(ffrt_cond_t* cond, ffrt_mutex_t* mutex, const struct timespec* time_point)Blocks the calling thread on a condition variable for a given duration. If 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.
FFRT_C_API int ffrt_cond_destroy(ffrt_cond_t* cond)Destroys a condition variable.

Function Description

ffrt_cond_init()

FFRT_C_API int ffrt_cond_init(ffrt_cond_t* cond, const ffrt_condattr_t* attr)

Description

Initializes a condition variable.

Since: 10

Parameters

NameDescription
ffrt_cond_t* condPointer to the condition variable.
const ffrt_condattr_t* attrPointer to the condition variable attribute.

Returns

TypeDescription
FFRT_C_API intReturns ffrt_success if the condition variable is initialized; returns ffrt_error_inval otherwise.

ffrt_cond_signal()

FFRT_C_API int ffrt_cond_signal(ffrt_cond_t* cond)

Description

Unblocks at least one of the threads that are blocked on a condition variable.

Since: 10

Parameters

NameDescription
ffrt_cond_t* condPointer to the condition variable.

Returns

TypeDescription
FFRT_C_API intReturns ffrt_success if at least one of the threads is unblocked; returns ffrt_error_inval otherwise.

ffrt_cond_broadcast()

FFRT_C_API int ffrt_cond_broadcast(ffrt_cond_t* cond)

Description

Unblocks all threads currently blocked on a condition variable.

Since: 10

Parameters

NameDescription
ffrt_cond_t* condPointer to the condition variable.

Returns

TypeDescription
FFRT_C_API intReturns ffrt_success if all threads are unblocked successfully; returns ffrt_error_inval otherwise.

ffrt_cond_wait()

FFRT_C_API int ffrt_cond_wait(ffrt_cond_t* cond, ffrt_mutex_t* mutex)

Description

Blocks the calling thread on a condition variable.

Since: 10

Parameters

NameDescription
ffrt_cond_t* condPointer to the condition variable.
ffrt_mutex_t* mutexPointer to the mutex.

Returns

TypeDescription
FFRT_C_API intReturns ffrt_success if the thread is unblocked after being blocked; returns ffrt_error_inval otherwise.

ffrt_cond_timedwait()

FFRT_C_API int ffrt_cond_timedwait(ffrt_cond_t* cond, ffrt_mutex_t* mutex, const struct timespec* time_point)

Description

Blocks the calling thread on a condition variable for a given duration. If 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.

Since: 10

Parameters

NameDescription
ffrt_cond_t* condPointer to the condition variable.
ffrt_mutex_t* mutexPointer to the mutex.
const struct timespec* time_pointPointer to the maximum duration that the thread is blocked.

Returns

TypeDescription
FFRT_C_API intReturns ffrt_success if the thread is unblocked after being blocked; returns ffrt_error_timedout if the wait times out; returns ffrt_error_inval if the wait fails.

ffrt_cond_destroy()

FFRT_C_API int ffrt_cond_destroy(ffrt_cond_t* cond)

Description

Destroys a condition variable.

Since: 10

Parameters

NameDescription
ffrt_cond_t* condPointer to the condition variable.

Returns

TypeDescription
FFRT_C_API intReturns ffrt_success if the condition variable is destroyed successfully; returns ffrt_error_inval otherwise.

你可能感兴趣的鸿蒙文章

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/BqKun3g4