mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 21:07:13 +02:00
something
This commit is contained in:
26
slsDetectorSoftware/threadFiles/Mutex.cpp
Normal file
26
slsDetectorSoftware/threadFiles/Mutex.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "Mutex.h"
|
||||
|
||||
Mutex::Mutex() {
|
||||
pthread_mutex_init(&m_lock, NULL);
|
||||
is_locked = false;
|
||||
}
|
||||
|
||||
Mutex::~Mutex() {
|
||||
while(is_locked);
|
||||
unlock(); // Unlock Mutex after shared resource is safe
|
||||
pthread_mutex_destroy(&m_lock);
|
||||
}
|
||||
|
||||
void Mutex::lock() {
|
||||
pthread_mutex_lock(&m_lock);
|
||||
is_locked = true;
|
||||
}
|
||||
|
||||
void Mutex::unlock() {
|
||||
is_locked = false; // do it BEFORE unlocking to avoid race condition
|
||||
pthread_mutex_unlock(&m_lock);
|
||||
}
|
||||
|
||||
pthread_mutex_t* Mutex::get_mutex_ptr(){
|
||||
return &m_lock;
|
||||
}
|
Reference in New Issue
Block a user