4 #ifndef __FRIOS_POSIX_THREADS_MUTEX_HPP__
5 #define __FRIOS_POSIX_THREADS_MUTEX_HPP__
46 int fail = pthread_mutex_init(&_mutex, 0);
56 int fail = pthread_mutex_init(&_mutex, &attributes._attr);
62 : _mutex(std::move(tmp._mutex))
69 pthread_mutex_destroy(&_mutex);
136 pthread_mutex_t* _p_mutex;
145 : _p_mutex(&mutex._mutex)
147 int fail = pthread_mutex_lock(_p_mutex);
152 : _p_mutex(&mutex._mutex)
154 int fail = pthread_mutex_trylock(_p_mutex);
155 if(fail == EBUSY)
throw locked(EBUSY);
162 int fail = pthread_mutex_unlock(_p_mutex);
175 pthread_mutex_t* _p_mutex;
182 : _p_mutex(&mutex._mutex)
184 int fail = pthread_mutex_unlock(_p_mutex);
191 int fail = pthread_mutex_lock(_p_mutex);
217 #endif // include guard
~lock(void)
Unlocks the mutex locked in the constructor.
Definition: mutex.hpp:160
mutex(void)
Default construction.
Definition: mutex.hpp:44
Wraper around POSIX condition variables.
Definition: cond.hpp:18
Exception class for unlocking operation errors.
Definition: mutex.hpp:87
mutex(const mutex_attr &attributes)
Construction from mutex attributes.
Definition: mutex.hpp:54
mutex(mutex &&tmp)
Mutexes are movable.
Definition: mutex.hpp:61
Base class for all POSIX exceptions.
Definition: error.hpp:14
unlock(mutex &mutex)
Unlocks the specified mutex.
Definition: mutex.hpp:181
~mutex(void)
Destructor frees any resources related to the mutex.
Definition: mutex.hpp:66
Class optionally locking a mutex if it is free.
Definition: mutex.hpp:201
Wrapper around POSIX mutexes.
Definition: mutex.hpp:21
Exception class indicating that a mutex is already locked.
Definition: mutex.hpp:99
Class locking a mutex on construction and unlocking on destruction.
Definition: mutex.hpp:133
Declaration of exception classes for POSIX errors.
Exception class for locking operation errors.
Definition: mutex.hpp:76
try_lock(mutex &mutex)
Tries to lock the specified mutex throws if the mutex is locked.
Definition: mutex.hpp:208
Wrapper around POSIX mutex attributes.
~unlock(void)
Locks the mutex unlocked in the constructor.
Definition: mutex.hpp:189
Exception class for mutex initialization errors.
Definition: mutex.hpp:33
error(int error_code)
Construction from POSIX error code.
Definition: error.hpp:26
Class unlocking a mutex on construction and locking on destruction.
Definition: mutex.hpp:172
Wrapper around POSIX condition variable attributes.
Definition: mutex_attr.hpp:18
lock(mutex &mutex)
Locks the specified mutex.
Definition: mutex.hpp:144