mirror of
https://github.com/ksherlock/TwoTerm.git
synced 2024-12-22 07:30:40 +00:00
32 lines
371 B
C++
32 lines
371 B
C++
#ifndef __LOCK_H__
|
|
#define __LOCK_H__
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
class Lock {
|
|
public:
|
|
Lock();
|
|
~Lock();
|
|
|
|
void lock();
|
|
void unlock();
|
|
|
|
bool tryLock();
|
|
|
|
private:
|
|
pthread_mutex_t _mutex;
|
|
};
|
|
|
|
class Locker {
|
|
public:
|
|
Locker(Lock& lock) : _lock(lock) { _lock.lock(); }
|
|
~Locker() { _lock.unlock(); }
|
|
private:
|
|
Lock &_lock;
|
|
};
|
|
|
|
|
|
#endif
|