36#ifndef __PARA_PTH_LOCK_H__
37#define __PARA_PTH_LOCK_H__
46# define LOCK_VERBOSE 0
114 int const error = pthread_mutex_init(&
mtx, 0);
125 pthread_mutex_destroy(&
mtx);
149 int const error = pthread_mutex_lock(&
mtx);
155 std::cout <<
"locked:" << &
mtx << std::endl;
165 std::cout <<
"unlocked:" << &
mtx << std::endl;
168 int const error = pthread_mutex_unlock(&
mtx);
277 ++
count;
return *
this;
293 for (LockRAIIHelper raii_(lck,__FILE__, __LINE__); raii_; ++raii_)
295#define LOCK_RAII(lck) \
296 LockRAII raii_(lck, __FILE__, __LINE__)
Same as LockRAII but with additional members to implement the LOCKED macro.
LockRAIIHelper(Lock *l, char const *file, int line)
LockRAIIHelper const & operator=(LockRAIIHelper const &)
LockRAIIHelper(LockRAIIHelper const &)
LockRAIIHelper & operator++()
Class to do RAII with a lock. The constructor will acquire the lock and the destructor will delete it...
LockRAII(Lock *l)
Constructor. The constructor calls l->lock() to acquire the lock.
LockRAII(Lock *l, char const *file, int line)
Constructor. The constructor calls l->lock(file,line) to acquire the lock.
LockRAII(LockRAII const &)
No copying or assignment for instances of this class.
LockRAII const & operator=(LockRAII const &)
~LockRAII()
Destructor. Releases the lock that was acquired in the constructor.
Class that implements a lock. The class wraps around pthread_mutex_t and adds some safeguards.
void lock(char const *f, int l)
Acquire this lock. The function sets the internal file/line (debugging) fields to the values specifie...
pthread_mutex_t mtx
The low-level mutex that implements this lock.
int line
Line at which the lock was last acquired (debugging).
char const * file
File in which the lock was last acquired (debugging).
Lock(Lock const &)
Code like this pthread_mutex_t m1, m2; pthread_mutex_init(&m1, 0); m2 = m1; results in undefined beha...
Lock & operator=(Lock const &)
Lock()
Initialize this lock.
void unlock()
Release this lock.
void lock()
Acquire this lock. The function sets the internal file/line (debugging) fields to generic values.
~Lock()
Destroy this lock.
Exception that is thrown whenever something goes wrong with a lock.
int getCode()
get error code
LockException(int c=0)
constructor