Files
pstrace/framework/mutex.h
T
2020-01-04 14:28:08 +04:00

41 lines
708 B
C++

#ifndef MUTEX_H_
#define MUTEX_H_
#include <pthread.h>
#include <sys/time.h>
class SC_Mutex {
public:
SC_Mutex() {
pthread_mutex_init(&m, NULL);
}
SC_Mutex(SC_Mutex const&) {
pthread_mutex_init(&m, NULL);
}
SC_Mutex& operator=(SC_Mutex const& rhs) {
if (&rhs != this) {
pthread_mutex_init(&m, NULL);
}
return *this;
}
~SC_Mutex() {
pthread_mutex_destroy(&m);
}
void Lock() {
pthread_mutex_lock(&m);
}
void Unlock() {
pthread_mutex_unlock(&m);
}
bool Trylock() {
return (pthread_mutex_trylock(&m) == 0);
}
private:
pthread_mutex_t m;
};
#endif /* MUTEX_H_ */