mirror of https://gitlab.com/cppit/jucipp
3 changed files with 50 additions and 31 deletions
@ -0,0 +1,39 @@
|
||||
#include "mutex.hpp" |
||||
|
||||
#if defined(__clang__) && (!defined(SWIG)) |
||||
#pragma GCC diagnostic ignored "-Wthread-safety" |
||||
#endif |
||||
|
||||
void Mutex::lock() { |
||||
mutex.lock(); |
||||
} |
||||
|
||||
bool Mutex::try_lock() { |
||||
return mutex.try_lock(); |
||||
} |
||||
|
||||
void Mutex::unlock() { |
||||
mutex.unlock(); |
||||
} |
||||
|
||||
const Mutex &Mutex::operator!() const { return *this; } |
||||
|
||||
LockGuard::LockGuard(Mutex &mutex_) : mutex(mutex_) { |
||||
mutex.lock(); |
||||
locked = true; |
||||
} |
||||
|
||||
void LockGuard::lock() { |
||||
mutex.lock(); |
||||
locked = true; |
||||
} |
||||
|
||||
void LockGuard::unlock() { |
||||
mutex.unlock(); |
||||
locked = false; |
||||
} |
||||
|
||||
LockGuard::~LockGuard() { |
||||
if(locked) |
||||
mutex.unlock(); |
||||
} |
||||
Loading…
Reference in new issue