![]() |
C-chat
|
Provides types allowing to synchronize access to resources. More...
Go to the source code of this file.
Classes | |
class | Mutex |
A semaphore allowing mutual exclusion. More... | |
class | ReadWriteLock |
A read/write lock to synchronize resource access. More... | |
Typedefs | |
typedef struct Mutex | Mutex |
typedef struct ReadWriteLock | ReadWriteLock |
Functions | |
Mutex | createMutex () |
Creates a mutex. More... | |
void | acquireMutex (Mutex mutex) |
Acquires the given mutex. More... | |
void | releaseMutex (Mutex mutex) |
Releases the given mutex. More... | |
void | destroyMutex (Mutex mutex) |
Destroys the given mutex. More... | |
ReadWriteLock | createReadWriteLock () |
Creates a read/write lock. More... | |
void | acquireRead (ReadWriteLock lock) |
Acquires read lock on the given read/write lock. More... | |
void | acquireWrite (ReadWriteLock lock) |
Acquires write lock on the given read/write lock. More... | |
void | releaseRead (ReadWriteLock lock) |
Releases read lock on the given read/write lock. More... | |
void | releaseWrite (ReadWriteLock lock) |
Releases write lock on the given read/write lock. More... | |
void | destroyReadWriteLock (ReadWriteLock lock) |
Destroys the given read/write lock. More... | |
Provides types allowing to synchronize access to resources.
void acquireMutex | ( | Mutex | mutex | ) |
Acquires the given mutex.
Once acquired, a mutex MUST be released by the thread which acquired it before any thread can re-acquiring. This is a blocking-call.
mutex | The mutex to acquire |
void acquireRead | ( | ReadWriteLock | lock | ) |
Acquires read lock on the given read/write lock.
This is a blocking call. It waits for the read lock to be available, this one can be unavailable if write lock is acquired.
lock | The read/write lock to acquire read on |
void acquireWrite | ( | ReadWriteLock | lock | ) |
Acquires write lock on the given read/write lock.
This is a blocking call. It wait for the read lock to be available, this one can be unavailable if a thread already acquired write lock or if any thread acquired read lock.
lock | The read/write lock to acquire write on |
Mutex createMutex | ( | ) |
Creates a mutex.
ReadWriteLock createReadWriteLock | ( | ) |
Creates a read/write lock.
A read/write lock allow to protect access to a resource. When acquiring read lock, no thread acquire write lock but all threads can still acquire read lock. When acquiring write lock, no thread can acquire any lock before lock release.
It allows to ensure resources is not read while writing it.
void destroyMutex | ( | Mutex | mutex | ) |
Destroys the given mutex.
WARNING : A mutex MUST NOT be destroyed twice. It would lead to unexpected behavior.
mutex | The mutex to destroy |
void destroyReadWriteLock | ( | ReadWriteLock | lock | ) |
Destroys the given read/write lock.
It frees allocated memory for the given read/write lock.
WARNING: This function MUST NOT be called twice for the same lock. It would lead to unexpected behavior.
lock | The read/write lock to destroy |
void releaseMutex | ( | Mutex | mutex | ) |
Releases the given mutex.
The given mutex MUST be acquired by the current thread before releasing.
mutex | The mutex to release |
void releaseRead | ( | ReadWriteLock | lock | ) |
Releases read lock on the given read/write lock.
The lock MUST have been acquired by this thread before.
lock | The read/write lock to release read of |
void releaseWrite | ( | ReadWriteLock | lock | ) |
Releases write lock on the given read/write lock.
The lock MUST have been acquired by this thread before.
lock | The read/write lock to release write of |