|
@@ -1,6 +1,6 @@ |
|
|
/* |
|
|
/* |
|
|
* DISTRHO Plugin Framework (DPF) |
|
|
* DISTRHO Plugin Framework (DPF) |
|
|
* Copyright (C) 2012-2016 Filipe Coelho <falktx@falktx.com> |
|
|
|
|
|
|
|
|
* Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com> |
|
|
* |
|
|
* |
|
|
* Permission to use, copy, modify, and/or distribute this software for any purpose with |
|
|
* Permission to use, copy, modify, and/or distribute this software for any purpose with |
|
|
* or without fee is hereby granted, provided that the above copyright notice and this |
|
|
* or without fee is hereby granted, provided that the above copyright notice and this |
|
@@ -39,7 +39,7 @@ public: |
|
|
/* |
|
|
/* |
|
|
* Constructor. |
|
|
* Constructor. |
|
|
*/ |
|
|
*/ |
|
|
Mutex(bool inheritPriority = true) noexcept |
|
|
|
|
|
|
|
|
Mutex(const bool inheritPriority = true) noexcept |
|
|
: fMutex() |
|
|
: fMutex() |
|
|
{ |
|
|
{ |
|
|
pthread_mutexattr_t attr; |
|
|
pthread_mutexattr_t attr; |
|
@@ -61,9 +61,9 @@ public: |
|
|
/* |
|
|
/* |
|
|
* Lock the mutex. |
|
|
* Lock the mutex. |
|
|
*/ |
|
|
*/ |
|
|
void lock() const noexcept |
|
|
|
|
|
|
|
|
bool lock() const noexcept |
|
|
{ |
|
|
{ |
|
|
pthread_mutex_lock(&fMutex); |
|
|
|
|
|
|
|
|
return (pthread_mutex_lock(&fMutex) == 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
@@ -86,7 +86,6 @@ public: |
|
|
private: |
|
|
private: |
|
|
mutable pthread_mutex_t fMutex; |
|
|
mutable pthread_mutex_t fMutex; |
|
|
|
|
|
|
|
|
DISTRHO_PREVENT_HEAP_ALLOCATION |
|
|
|
|
|
DISTRHO_DECLARE_NON_COPY_CLASS(Mutex) |
|
|
DISTRHO_DECLARE_NON_COPY_CLASS(Mutex) |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@@ -133,12 +132,13 @@ public: |
|
|
/* |
|
|
/* |
|
|
* Lock the mutex. |
|
|
* Lock the mutex. |
|
|
*/ |
|
|
*/ |
|
|
void lock() const noexcept |
|
|
|
|
|
|
|
|
bool lock() const noexcept |
|
|
{ |
|
|
{ |
|
|
#ifdef DISTRHO_OS_WINDOWS |
|
|
#ifdef DISTRHO_OS_WINDOWS |
|
|
EnterCriticalSection(&fSection); |
|
|
EnterCriticalSection(&fSection); |
|
|
|
|
|
return true; |
|
|
#else |
|
|
#else |
|
|
pthread_mutex_lock(&fMutex); |
|
|
|
|
|
|
|
|
return (pthread_mutex_lock(&fMutex) == 0); |
|
|
#endif |
|
|
#endif |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -174,7 +174,6 @@ private: |
|
|
mutable pthread_mutex_t fMutex; |
|
|
mutable pthread_mutex_t fMutex; |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
DISTRHO_PREVENT_HEAP_ALLOCATION |
|
|
|
|
|
DISTRHO_DECLARE_NON_COPY_CLASS(RecursiveMutex) |
|
|
DISTRHO_DECLARE_NON_COPY_CLASS(RecursiveMutex) |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@@ -295,6 +294,10 @@ public: |
|
|
: fMutex(mutex), |
|
|
: fMutex(mutex), |
|
|
fLocked(mutex.tryLock()) {} |
|
|
fLocked(mutex.tryLock()) {} |
|
|
|
|
|
|
|
|
|
|
|
ScopeTryLocker(const Mutex& mutex, const bool forceLock) noexcept |
|
|
|
|
|
: fMutex(mutex), |
|
|
|
|
|
fLocked(forceLock ? mutex.lock() : mutex.tryLock()) {} |
|
|
|
|
|
|
|
|
~ScopeTryLocker() noexcept |
|
|
~ScopeTryLocker() noexcept |
|
|
{ |
|
|
{ |
|
|
if (fLocked) |
|
|
if (fLocked) |
|
|