Implementation of a fair, POSIX conforming reader/writer lock.
More...
Implementation of a fair, POSIX conforming reader/writer lock.
- Note
- Do not include this header file directly, but pthread.h.
Definition in file pthread_rwlock.h.
#include "priority_queue.h"
#include "thread.h"
#include <errno.h>
#include <stdbool.h>
Go to the source code of this file.
◆ __pthread_rwlock_blocked_readingly()
Internal function to determine of the lock can be acquired for reading.
- Parameters
-
- Returns
false if locking for reading is possible without blocking.
◆ __pthread_rwlock_blocked_writingly()
Internal function to determine of the lock can be acquired for writing.
- Parameters
-
- Returns
false if locking for writing is possible without blocking.
◆ pthread_rwlock_destroy()
Destroy a reader/writer lock.
This is a no-op. Destroying a reader/writer lock while a thread holds it, or there are threads waiting for it causes undefined behavior. Datum must be reinitialized before using it again.
- Parameters
-
| [in] | rwlock | Lock to destroy. |
- Returns
0 on success. EINVAL if rwlock == NULL. EBUSY if the lock was in use.
◆ pthread_rwlock_init()
Initialize a reader/writer lock.
A zeroed out datum is initialized.
- Parameters
-
| [in,out] | rwlock | Lock to initialize. |
| [in] | attr | Unused. |
- Returns
0 on success. EINVAL if rwlock == NULL.
◆ pthread_rwlock_rdlock()
Lock a reader/writer lock for reading.
This function may block.
- Parameters
-
| [in] | rwlock | Lock to acquire for reading. |
- Returns
0 if the lock could be acquired. EINVAL if rwlock == NULL.
◆ pthread_rwlock_timedrdlock()
| int pthread_rwlock_timedrdlock |
( |
pthread_rwlock_t * |
rwlock, |
|
|
const struct timespec * |
abstime |
|
) |
| |
Try to acquire a read lock in a given timeframe.
- Parameters
-
| [in] | rwlock | Lock to acquire for reading. |
| [in] | abstime | Maximum timestamp when to wakeup, absolute. |
- Returns
0 if the lock could be acquired. EDEADLK if the lock could not be acquired in the given timeframe. EINVAL if rwlock == NULL.
◆ pthread_rwlock_timedwrlock()
| int pthread_rwlock_timedwrlock |
( |
pthread_rwlock_t * |
rwlock, |
|
|
const struct timespec * |
abstime |
|
) |
| |
Try to acquire a write lock in a given timeframe.
- Parameters
-
| [in] | rwlock | Lock to acquire for writing. |
| [in] | abstime | Maximum timestamp when to wakeup, absolute. |
- Returns
0 if the lock could be acquired. EDEADLK if the lock could not be acquired in the given timeframe. EINVAL if rwlock == NULL.
◆ pthread_rwlock_tryrdlock()
Try to lock a reader/writer lock for reader.
This function won't block.
- Parameters
-
| [in] | rwlock | Lock to acquire for reading. |
- Returns
0 if the lock could be acquired. EBUSY if acquiring the lock cannot be done without blocking. EINVAL if rwlock == NULL.
◆ pthread_rwlock_trywrlock()
Try to lock a reader/writer lock for writing.
This function won't block.
- Parameters
-
| [in] | rwlock | Lock to acquire for writing. |
- Returns
0 if the lock could be acquired. EBUSY if acquiring the lock cannot be done without blocking. EINVAL if rwlock == NULL.
◆ pthread_rwlock_unlock()
Unlock the reader/writer lock.
Must only be used if the lock is currently held. You may release the lock out of another thread, but the lock, operate, unlock logic must not be broken.
- Parameters
-
| [in] | rwlock | Lock to release |
- Returns
0 on success. EPERM if the lock was not held for any operation. EINVAL if rwlock == NULL.
◆ pthread_rwlock_wrlock()
Lock a reader/writer lock for writing.
This function may block.
- Parameters
-
| [in] | rwlock | Lock to acquire for writing. |
- Returns
0 if the lock could be acquired. EINVAL if rwlock == NULL.