|
PatchworkOS
|
Read-Write Mutex. More...
Data Structures | |
| struct | rwmutex_t |
| Read-Write Mutex structure. More... | |
Macros | |
| #define | RWMUTEX_READ_SCOPE(mutex) |
| Acquires a rwmutex for reading for the reminder of the current scope. | |
| #define | RWMUTEX_WRITE_SCOPE(mutex) |
| Acquires a rwmutex for writing for the reminder of the current scope. | |
Functions | |
| void | rwmutex_init (rwmutex_t *mtx) |
| Initializes a rwmutex. | |
| void | rwmutex_deinit (rwmutex_t *mtx) |
| Deinitializes a rwmutex. | |
| void | rwmutex_read_acquire (rwmutex_t *mtx) |
| Acquires a rwmutex for reading, blocking until it is available. | |
| uint64_t | rwmutex_read_try_acquire (rwmutex_t *mtx) |
| Tries to acquire a rwmutex for reading. | |
| void | rwmutex_read_release (rwmutex_t *mtx) |
| Releases a rwmutex from reading. | |
| void | rwmutex_write_acquire (rwmutex_t *mtx) |
| Acquires a rwmutex for writing, blocking until it is available. | |
| uint64_t | rwmutex_write_try_acquire (rwmutex_t *mtx) |
| Tries to acquire a rwmutex for writing. | |
| void | rwmutex_write_release (rwmutex_t *mtx) |
| Releases a rwmutex from writing. | |
| static void | rwmutex_read_cleanup (rwmutex_t **mutex) |
| static void | rwmutex_write_cleanup (rwmutex_t **mutex) |
Read-Write Mutex.
| #define RWMUTEX_READ_SCOPE | ( | mutex | ) |
Acquires a rwmutex for reading for the reminder of the current scope.
| mutex | Pointer to the rwmutex to acquire. |
| #define RWMUTEX_WRITE_SCOPE | ( | mutex | ) |
Acquires a rwmutex for writing for the reminder of the current scope.
| mutex | Pointer to the rwmutex to acquire. |
| void rwmutex_deinit | ( | rwmutex_t * | mtx | ) |
Deinitializes a rwmutex.
| mtx | Pointer to the rwmutex to deinitialize. |
Definition at line 20 of file rwmutex.c.
References rwmutex_t::activeReaders, assert, rwmutex_t::hasWriter, rwmutex_t::lock, LOCK_SCOPE, rwmutex_t::readerQueue, wait_queue_deinit(), rwmutex_t::waitingWriters, and rwmutex_t::writerQueue.
Referenced by socket_free(), and socket_new().
| void rwmutex_init | ( | rwmutex_t * | mtx | ) |
Initializes a rwmutex.
| mtx | Pointer to the rwmutex to initialize. |
Definition at line 10 of file rwmutex.c.
References rwmutex_t::activeReaders, rwmutex_t::hasWriter, rwmutex_t::lock, lock_init(), rwmutex_t::readerQueue, wait_queue_init(), rwmutex_t::waitingWriters, and rwmutex_t::writerQueue.
Referenced by socket_new().
| void rwmutex_read_acquire | ( | rwmutex_t * | mtx | ) |
Acquires a rwmutex for reading, blocking until it is available.
| mtx | Pointer to the rwmutex to acquire. |
Definition at line 30 of file rwmutex.c.
References rwmutex_t::activeReaders, ERR, rwmutex_t::hasWriter, rwmutex_t::lock, LOCK_SCOPE, NULL, rwmutex_t::readerQueue, WAIT_BLOCK_LOCK, and rwmutex_t::waitingWriters.
|
inlinestatic |
Definition at line 116 of file rwmutex.h.
References mutex, and rwmutex_read_release().
| void rwmutex_read_release | ( | rwmutex_t * | mtx | ) |
Releases a rwmutex from reading.
| mtx | Pointer to the rwmutex to release. |
Definition at line 67 of file rwmutex.c.
References rwmutex_t::activeReaders, assert, EOK, rwmutex_t::lock, LOCK_SCOPE, NULL, wait_unblock(), rwmutex_t::waitingWriters, and rwmutex_t::writerQueue.
Referenced by rwmutex_read_cleanup().
Tries to acquire a rwmutex for reading.
If the rwmutex is owned by another thread for writing or a writer is waiting, this function will fail with EWOULDBLOCK.
If the function succeeds, rwmutex_read_release() must be called to release the rwmutex.
| mtx | Pointer to the rwmutex to acquire. |
0. On error, ERR and errno is set. Definition at line 47 of file rwmutex.c.
References rwmutex_t::activeReaders, EINVAL, ERR, errno, EWOULDBLOCK, rwmutex_t::hasWriter, rwmutex_t::lock, LOCK_SCOPE, NULL, and rwmutex_t::waitingWriters.
| void rwmutex_write_acquire | ( | rwmutex_t * | mtx | ) |
Acquires a rwmutex for writing, blocking until it is available.
| mtx | Pointer to the rwmutex to acquire. |
Definition at line 85 of file rwmutex.c.
References rwmutex_t::activeReaders, ERR, rwmutex_t::hasWriter, rwmutex_t::lock, LOCK_SCOPE, NULL, WAIT_BLOCK_LOCK, rwmutex_t::waitingWriters, and rwmutex_t::writerQueue.
Referenced by socket_start_transition().
|
inlinestatic |
Definition at line 121 of file rwmutex.h.
References mutex, and rwmutex_write_release().
| void rwmutex_write_release | ( | rwmutex_t * | mtx | ) |
Releases a rwmutex from writing.
| mtx | Pointer to the rwmutex to release. |
Definition at line 124 of file rwmutex.c.
References EOK, rwmutex_t::hasWriter, rwmutex_t::lock, LOCK_SCOPE, NULL, rwmutex_t::readerQueue, WAIT_ALL, wait_unblock(), rwmutex_t::waitingWriters, and rwmutex_t::writerQueue.
Referenced by rwmutex_write_cleanup(), socket_end_transition(), and socket_start_transition().
Tries to acquire a rwmutex for writing.
If the function succeeds, rwmutex_write_release() must be called to release the rwmutex.
| mtx | Pointer to the rwmutex to acquire. |
0. On error, ERR and errno is set. Definition at line 104 of file rwmutex.c.
References rwmutex_t::activeReaders, EINVAL, ERR, errno, EWOULDBLOCK, rwmutex_t::hasWriter, rwmutex_t::lock, LOCK_SCOPE, and NULL.