use own reentrant mutex implementation

This commit is contained in:
john30
2017-08-27 14:58:23 +02:00
parent 20c38b3a2c
commit 125cbcd661
4 changed files with 57 additions and 9 deletions
+21
View File
@@ -105,4 +105,25 @@ bool WaitThread::Wait(int seconds) {
return isRunning();
}
Mutex::Mutex() {
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&m_mutex, &attr);
pthread_mutexattr_destroy(&attr);
}
Mutex::~Mutex() {
pthread_mutex_destroy(&m_mutex);
}
void Mutex::lock() {
pthread_mutex_lock(&m_mutex);
}
void Mutex::unlock() {
pthread_mutex_unlock(&m_mutex);
}
} // namespace ebusd
+31
View File
@@ -142,6 +142,37 @@ class WaitThread : public Thread {
pthread_cond_t m_cond;
};
/**
* A simple mutex.
*/
class Mutex {
public:
/**
* Constructor.
*/
Mutex();
/**
* Destructor.
*/
virtual ~Mutex();
/**
* Lock this mutex.
*/
void lock();
/**
* Unlock this mutex.
*/
void unlock();
private:
/** the mutex for waiting. */
pthread_mutex_t m_mutex;
};
} // namespace ebusd
#endif // LIB_UTILS_THREAD_H_