30 lines
467 B
C++
30 lines
467 B
C++
#include "LockGuard_pthread.h"
|
|
|
|
LockGuard_pthread::LockGuard_pthread(pthread_mutex_t &LockRef) : _lock(LockRef), is_locked(false)
|
|
{
|
|
lock();
|
|
}
|
|
|
|
LockGuard_pthread::~LockGuard_pthread()
|
|
{
|
|
unlock();
|
|
}
|
|
|
|
void LockGuard_pthread::lock()
|
|
{
|
|
if(!is_locked)
|
|
{
|
|
pthread_mutex_lock(&_lock);
|
|
is_locked = true;
|
|
}
|
|
}
|
|
|
|
void LockGuard_pthread::unlock()
|
|
{
|
|
if(is_locked)
|
|
{
|
|
pthread_mutex_unlock(&_lock);
|
|
is_locked = false;
|
|
}
|
|
}
|