O2S C Library 1.8.2
Provide high-level data-structures and other fundamental tools for C projects
Loading...
Searching...
No Matches
mutex.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* ____ _ _____ ____ _ _ _ _____ _ _ ____ ____ */
3/* / ___| / \ | ___| _ \ / \ | \ | | |_ _| || | | _ \/ ___| */
4/* \___ \ / _ \ | |_ | |_) | / _ \ | \| | | | | || |_| | | \___ \ */
5/* ___) / ___ \| _| | _ < / ___ \| |\ | | | |__ _| |_| |___) | */
6/* |____/_/ \_|_| |_| \_/_/ \_|_| \_| |_| |_| |____/|____/ */
7/* */
14/* ************************************************************************** */
15
16#include "o2s/mutex.h"
17
18#include "o2s/log.h" // log_*
19
20#include <pthread.h> // pthread_*
21
22#include <string.h> // strerror
23
25pthread_mutex_t* o2s_mutex_lock(pthread_mutex_t* mutex)
26{
27 int error = pthread_mutex_lock(mutex);
28
29 if (error != 0)
30 log_error("Unable to lock mutex: %s", strerror(error));
31 return mutex;
32}
33
35void o2s_mutex_unlock(pthread_mutex_t* const* mutex)
36{
37 int error = pthread_mutex_unlock(*mutex);
38
39 if (error != 0)
40 log_error("Unable to unlock mutex: %s", strerror(error));
41}
Simplistic logging utilities.
#define log_error(...)
Report a condition causing the current operation to abort.
Definition log.h:83
void o2s_mutex_unlock(pthread_mutex_t *const *mutex)
Unlock the mutex, logging any error.
Definition mutex.c:35
pthread_mutex_t * o2s_mutex_lock(pthread_mutex_t *mutex)
Lock the mutex, logging any error.
Definition mutex.c:25
Provide a convenient RAII-style mechanism to access mutex-protected resources.
Dynamic string implementation.