use own reentrant mutex implementation
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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_
|
||||
|
||||
Reference in New Issue
Block a user