Group PJ_RW_MUTEX

group PJ_RW_MUTEX

Reader/writer mutex is a classic synchronization object where multiple readers can acquire the mutex, but only a single writer can acquire the mutex.

Typedefs

typedef struct pj_rwmutex_t pj_rwmutex_t

Opaque declaration for reader/writer mutex. Reader/writer mutex is a classic synchronization object where multiple readers can acquire the mutex, but only a single writer can acquire the mutex.

Functions

pj_status_t pj_rwmutex_create(pj_pool_t *pool, const char *name, pj_rwmutex_t **mutex)

Create reader/writer mutex.

Parameters
  • pool – Pool to allocate memory for the mutex.

  • name – Name to be assigned to the mutex.

  • mutex – Pointer to receive the newly created mutex.

Returns

PJ_SUCCESS on success, or the error code.

pj_status_t pj_rwmutex_lock_read(pj_rwmutex_t *mutex)

Lock the mutex for reading.

Parameters

mutex – The mutex.

Returns

PJ_SUCCESS on success, or the error code.

pj_status_t pj_rwmutex_lock_write(pj_rwmutex_t *mutex)

Lock the mutex for writing.

Parameters

mutex – The mutex.

Returns

PJ_SUCCESS on success, or the error code.

pj_status_t pj_rwmutex_unlock_read(pj_rwmutex_t *mutex)

Release read lock.

Parameters

mutex – The mutex.

Returns

PJ_SUCCESS on success, or the error code.

pj_status_t pj_rwmutex_unlock_write(pj_rwmutex_t *mutex)

Release write lock.

Parameters

mutex – The mutex.

Returns

PJ_SUCCESS on success, or the error code.

pj_status_t pj_rwmutex_destroy(pj_rwmutex_t *mutex)

Destroy reader/writer mutex.

Parameters

mutex – The mutex.

Returns

PJ_SUCCESS on success, or the error code.