#pragma once
#include <pthread.h>
namespace Extralib
{
namespace Thread
{
/*
* 利用对象生存周期自动加解锁,比较安全
*/
class AutoLock
{
public:
pthread_mutex_t& m_locker;
public:
AutoLock( pthread_mutex_t& locker ):m_locker(locker)
{
::pthread_mutex_lock(&m_locker );
};
AutoLock( pthread_mutex_t* locker ):m_locker(*locker)
{
pthread_mutex_lock(&m_locker );
};
~AutoLock( )
{
pthread_mutex_unlock(&m_locker );
};
};
}
}