feature: add read and write unlock functions for read-write locks
This commit is contained in:
parent
6e44b46020
commit
5de4836e20
1 changed files with 30 additions and 11 deletions
|
|
@ -1,5 +1,4 @@
|
|||
#pragma once
|
||||
#include "error.h"
|
||||
#include "platform.h"
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
|
@ -400,20 +399,40 @@ DRANG_API int drang_rwlock_rdlock(struct drang_rwlock *rwlock);
|
|||
DRANG_API int drang_rwlock_wrlock(struct drang_rwlock *rwlock);
|
||||
|
||||
/**
|
||||
* @brief Releases a previously acquired read or write lock.
|
||||
* @brief Releases a read lock on the read-write lock.
|
||||
*
|
||||
* Releases either a read lock or write lock that was previously acquired by
|
||||
* the calling thread. The type of lock (read or write) is tracked internally.
|
||||
* Releases a read lock that was previously acquired with drang_rwlock_rdlock().
|
||||
* The calling thread must currently hold a read lock on the specified read-write lock.
|
||||
* Other waiting writers may be awakened when the last reader releases their lock.
|
||||
*
|
||||
* @param[in] rwlock Pointer to the read-write lock to unlock.
|
||||
* @param[in] rwlock Pointer to the read-write lock to release the read lock from.
|
||||
* @return 0 on success, negative error code on failure.
|
||||
* @retval 0 Success - lock released.
|
||||
* @retval 0 Success - read lock released.
|
||||
* @retval DRANG_EINVAL Invalid parameter (rwlock is NULL or not initialized).
|
||||
* @retval DRANG_EPERM The calling thread does not hold any lock on this rwlock.
|
||||
* @remarks Only the thread that acquired the lock should release it.
|
||||
* Works for both read and write locks.
|
||||
* Unlocking when no lock is held results in undefined behavior.
|
||||
* @retval DRANG_EPERM The calling thread does not hold a read lock on this lock.
|
||||
* @remarks Only the thread that acquired the read lock should release it.
|
||||
* Releasing a read lock that is not held results in undefined behavior.
|
||||
* When the last reader releases their lock, waiting writers may be awakened.
|
||||
*/
|
||||
DRANG_API int drang_rwlock_unlock(struct drang_rwlock *rwlock);
|
||||
DRANG_API int drang_rwlock_rdunlock(struct drang_rwlock *rwlock);
|
||||
|
||||
/**
|
||||
* @brief Releases a write lock on the read-write lock.
|
||||
*
|
||||
* Releases a write lock that was previously acquired with drang_rwlock_wrlock().
|
||||
* The calling thread must currently hold the write lock on the specified read-write lock.
|
||||
* Waiting readers and writers may be awakened when the write lock is released.
|
||||
*
|
||||
* @param[in] rwlock Pointer to the read-write lock to release the write lock from.
|
||||
* @return 0 on success, negative error code on failure.
|
||||
* @retval 0 Success - write lock released.
|
||||
* @retval DRANG_EINVAL Invalid parameter (rwlock is NULL or not initialized).
|
||||
* @retval DRANG_EPERM The calling thread does not hold the write lock on this lock.
|
||||
* @remarks Only the thread that acquired the write lock should release it.
|
||||
* Releasing a write lock that is not held results in undefined behavior.
|
||||
* When the write lock is released, waiting readers and writers may be awakened.
|
||||
*/
|
||||
DRANG_API int drang_rwlock_wrunlock(struct drang_rwlock *rwlock);
|
||||
|
||||
|
||||
DRANG_END_DECLS
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue