hlswmaster-ng (now in c++)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

35 lines
588 B

#ifndef _MUTEX_H_
#define _MUTEX_H_
#include <pthread.h>
class Mutex {
public:
Mutex() { pthread_mutex_init(&m, 0); }
~Mutex() { pthread_mutex_destroy(&m); }
void lock() { pthread_mutex_lock(&m); }
void unlock() { pthread_mutex_unlock(&m); }
protected:
Mutex(const Mutex& m);
Mutex& operator=(const Mutex& m);
private:
pthread_mutex_t m;
};
class AutoMutex {
public:
AutoMutex(Mutex& x) : m(x) { m.lock(); }
~AutoMutex() { m.unlock(); }
protected:
AutoMutex(const AutoMutex& am);
AutoMutex& operator=(const AutoMutex& am);
private:
Mutex& m;
};
#endif //_MUTEX_H_