openharmony 鸿蒙 capi-shared-mutex-h

2026-08-25 浏览 (1)

shared_mutex.h

Overview

The shared_mutex.h file declares read-write lock APIs in C.

File to include: <ffrt/shared_mutex.h>

Library: libffrt.z.so

System capability: SystemCapability.Resourceschedule.Ffrt.Core

Since: 18

Related module: FFRT

Summary

Function

NameDescription
FFRT_C_API int ffrt_rwlock_init(ffrt_rwlock_t* rwlock, const ffrt_rwlockattr_t* attr)Initializes a read-write lock.
FFRT_C_API int ffrt_rwlock_wrlock(ffrt_rwlock_t* rwlock)Obtains a write lock.
FFRT_C_API int ffrt_rwlock_trywrlock(ffrt_rwlock_t* rwlock)Attempts to obtain a write lock.
FFRT_C_API int ffrt_rwlock_rdlock(ffrt_rwlock_t* rwlock)Obtains a read lock.
FFRT_C_API int ffrt_rwlock_tryrdlock(ffrt_rwlock_t* rwlock)Attempts to obtain a read lock.
FFRT_C_API int ffrt_rwlock_unlock(ffrt_rwlock_t* rwlock)Releases the read-write lock.
FFRT_C_API int ffrt_rwlock_destroy(ffrt_rwlock_t* rwlock)Destroys the read-write lock.

Function Description

ffrt_rwlock_init()

FFRT_C_API int ffrt_rwlock_init(ffrt_rwlock_t* rwlock, const ffrt_rwlockattr_t* attr)

Description

Initializes a read-write lock.

Since: 18

Parameters

NameDescription
ffrt_rwlock_t* rwlockPointer to the read-write lock.
const ffrt_rwlockattr_t* attrPointer to the rwlock property. Only the default value (null) is supported.

Returns

TypeDescription
FFRT_C_API intIf rwlock is not empty and attr is empty, the initialization is successful, and ffrt_success is returned. Otherwise, the rwlock fails to be initialized, and ffrt_error_inval is returned.

ffrt_rwlock_wrlock()

FFRT_C_API int ffrt_rwlock_wrlock(ffrt_rwlock_t* rwlock)

Description

Obtains a write lock.

Since: 18

Parameters

NameDescription
ffrt_rwlock_t* rwlockPointer to the read-write lock.

Returns

TypeDescription
FFRT_C_API intReturns ffrt_success if the write lock is successfully obtained; returns ffrt_error_inval or blocks the task otherwise.

ffrt_rwlock_trywrlock()

FFRT_C_API int ffrt_rwlock_trywrlock(ffrt_rwlock_t* rwlock)

Description

Attempts to obtain a write lock.

Since: 18

Parameters

NameDescription
ffrt_rwlock_t* rwlockPointer to the read-write lock.

Returns

TypeDescription
FFRT_C_API intReturns ffrt_success if the write lock is successfully obtained; returns ffrt_error_inval or ffrt_error_busy otherwise.

ffrt_rwlock_rdlock()

FFRT_C_API int ffrt_rwlock_rdlock(ffrt_rwlock_t* rwlock)

Description

Obtains a read lock.

Since: 18

Parameters

NameDescription
ffrt_rwlock_t* rwlockPointer to the read-write lock.

Returns

TypeDescription
FFRT_C_API intReturns ffrt_success if the read lock is successfully obtained; returns ffrt_error_inval or blocks the task otherwise.

ffrt_rwlock_tryrdlock()

FFRT_C_API int ffrt_rwlock_tryrdlock(ffrt_rwlock_t* rwlock)

Description

Attempts to obtain a read lock.

Since: 18

Parameters

NameDescription
ffrt_rwlock_t* rwlockPointer to the read-write lock.

Returns

TypeDescription
FFRT_C_API intReturns ffrt_success if the read lock is successfully obtained; returns ffrt_error_inval or ffrt_error_busy otherwise.

ffrt_rwlock_unlock()

FFRT_C_API int ffrt_rwlock_unlock(ffrt_rwlock_t* rwlock)

Description

Releases the read-write lock.

Since: 18

Parameters

NameDescription
ffrt_rwlock_t* rwlockPointer to the read-write lock.

Returns

TypeDescription
FFRT_C_API intReturns ffrt_success if the read-write lock is successfully released; returns ffrt_error_inval otherwise.

ffrt_rwlock_destroy()

FFRT_C_API int ffrt_rwlock_destroy(ffrt_rwlock_t* rwlock)

Description

Destroys the read-write lock.

Since: 18

Parameters

NameDescription
ffrt_rwlock_t* rwlockPointer to the read-write lock.

Returns

TypeDescription
FFRT_C_API intReturns ffrt_success if the read-write lock 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-ffrt-ffrt-queue-attr-t

openharmony 鸿蒙 capi-ffrt

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

openharmony 鸿蒙 capi-ffrt-ffrt-task-handle-t

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