O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
mutex.h File Reference

Provide a convenient RAII-style mechanism to access mutex-protected resources. More...

#include <pthread.h>

Go to the source code of this file.

Macros

#define O2sLockGuard
 Automatically unlock the mutex at the end of the current scope.

Functions

pthread_mutex_t * o2s_mutex_lock (pthread_mutex_t *mutex)
 Lock the mutex, logging any error.
void o2s_mutex_unlock (pthread_mutex_t *const *mutex)
 Unlock the mutex, logging any error.

Detailed Description

Provide a convenient RAII-style mechanism to access mutex-protected resources.

Author
Antoine GAGNIERE

Definition in file mutex.h.

Macro Definition Documentation

◆ O2sLockGuard

#define O2sLockGuard

Automatically unlock the mutex at the end of the current scope.

In a situation where one wants to declare a mutex in a local scope, this "typedef" can be used for that mutex to be unlocked automatically when the variable goes out of scope.

It means this "typedef" can only be used like this:

{
O2sLockGuard my_mutex = o2s_mutex_lock(...);
...
} // <- the mutex will be unlocked at that point
pthread_mutex_t * o2s_mutex_lock(pthread_mutex_t *mutex)
Lock the mutex, logging any error.
Definition mutex.c:25
#define O2sLockGuard
Automatically unlock the mutex at the end of the current scope.
Definition mutex.h:38

Definition at line 38 of file mutex.h.