We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

condition_variable.h

Phone12+PC/2in113+Tablet12+TV19+Wearable18+

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

Expand
Name Description
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()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
FFRT_C_API int ffrt_cond_init(ffrt_cond_t* cond, const ffrt_condattr_t* attr)

Description

Initializes a condition variable.

Since: 10

Parameters

Expand
Name Description
ffrt_cond_t* cond Pointer to the condition variable.
const ffrt_condattr_t* attr Pointer to the condition variable attribute.

Returns

Expand
Type Description
FFRT_C_API int Returns ffrt_success if the condition variable is initialized; returns ffrt_error_inval otherwise.

ffrt_cond_signal()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
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

Expand
Name Description
ffrt_cond_t* cond Pointer to the condition variable.

Returns

Expand
Type Description
FFRT_C_API int Returns ffrt_success if at least one of the threads is unblocked; returns ffrt_error_inval otherwise.

ffrt_cond_broadcast()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
FFRT_C_API int ffrt_cond_broadcast(ffrt_cond_t* cond)

Description

Unblocks all threads currently blocked on a condition variable.

Since: 10

Parameters

Expand
Name Description
ffrt_cond_t* cond Pointer to the condition variable.

Returns

Expand
Type Description
FFRT_C_API int Returns ffrt_success if all threads are unblocked successfully; returns ffrt_error_inval otherwise.

ffrt_cond_wait()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
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

Expand
Name Description
ffrt_cond_t* cond Pointer to the condition variable.
ffrt_mutex_t* mutex Pointer to the mutex.

Returns

Expand
Type Description
FFRT_C_API int Returns ffrt_success if the thread is unblocked after being blocked; returns ffrt_error_inval otherwise.

ffrt_cond_timedwait()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
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

Expand
Name Description
ffrt_cond_t* cond Pointer to the condition variable.
ffrt_mutex_t* mutex Pointer to the mutex.
const struct timespec* time_point Pointer to the maximum duration that the thread is blocked.

Returns

Expand
Type Description
FFRT_C_API int Returns 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()

Phone12+PC/2in113+Tablet12+TV19+Wearable18+
FFRT_C_API int ffrt_cond_destroy(ffrt_cond_t* cond)

Description

Destroys a condition variable.

Since: 10

Parameters

Expand
Name Description
ffrt_cond_t* cond Pointer to the condition variable.

Returns

Expand
Type Description
FFRT_C_API int Returns ffrt_success if the condition variable is destroyed successfully; returns ffrt_error_inval otherwise.