ThreadPool_pthread/include/LockGuard_pthread.h

29 lines
619 B
C++

#ifndef LOCKGUARD_H
#define LOCKGUARD_H
#include "pthread.h"
/**
* @brief The LockGuard class
* Protects against deadlock by forcing unlocks when going out of scope
*
* The mechanism is quite simple. Constructor locks, destructor unlocks,
* and custom locks and unlocks are possible
*/
class LockGuard_pthread
{
pthread_mutex_t& _lock;
bool is_locked;
public:
LockGuard_pthread(pthread_mutex_t& LockRef);
~LockGuard_pthread();
void lock();
void unlock();
private:
LockGuard_pthread(LockGuard_pthread const &);
void operator=(LockGuard_pthread &);
};
#endif // LOCKGUARD_H