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);
219 lck->
lock(file, line);
277 ++count;
return *
this;
292 #define LOCKED(lck) \ 293 for (LockRAIIHelper raii_(lck,__FILE__, __LINE__); raii_; ++raii_) 295 #define LOCK_RAII(lck) \ 296 LockRAII raii_(lck, __FILE__, __LINE__) 300 #endif // __PARA_PTH_LOCK_H__
LockRAII(Lock *l)
Constructor. The constructor calls l->lock() to acquire the lock.
void lock()
Acquire this lock. The function sets the internal file/line (debugging) fields to generic values...
~Lock()
Destroy this lock.
int getCode()
get error code
void lock(char const *f, int l)
Acquire this lock. The function sets the internal file/line (debugging) fields to the values specifie...
LockRAIIHelper(Lock *l, char const *file, int line)
void unlock()
Release this lock.
pthread_mutex_t mtx
The low-level mutex that implements this lock.
LockRAIIHelper & operator++()
int line
Line at which the lock was last acquired (debugging).
Class that implements a lock. The class wraps around pthread_mutex_t and adds some safeguards...
Class to do RAII with a lock. The constructor will acquire the lock and the destructor will delete it...
LockRAII(Lock *l, char const *file, int line)
Constructor. The constructor calls l->lock(file,line) to acquire the lock.
Same as LockRAII but with additional members to implement the LOCKED macro.
Exception that is thrown whenever something goes wrong with a lock.
Lock()
Initialize this lock.
char const * file
File in which the lock was last acquired (debugging).
~LockRAII()
Destructor. Releases the lock that was acquired in the constructor.
LockException(int c=0)
constructor