17 #ifndef DISTRHO_MUTEX_HPP_INCLUDED 
   18 #define DISTRHO_MUTEX_HPP_INCLUDED 
   20 #include "../DistrhoUtils.hpp" 
   22 #ifdef DISTRHO_OS_WINDOWS 
   23 # include <winsock2.h> 
   29 START_NAMESPACE_DISTRHO
 
   42         pthread_mutex_init(&fMutex, 
nullptr);
 
   50         pthread_mutex_destroy(&fMutex);
 
   56     void lock() 
const noexcept
 
   58         pthread_mutex_lock(&fMutex);
 
   65     bool tryLock() 
const noexcept
 
   67         return (pthread_mutex_trylock(&fMutex) == 0);
 
   73     void unlock() 
const noexcept
 
   75         pthread_mutex_unlock(&fMutex);
 
   79     mutable pthread_mutex_t fMutex;
 
   81     DISTRHO_PREVENT_HEAP_ALLOCATION
 
   82     DISTRHO_DECLARE_NON_COPY_CLASS(
Mutex)
 
   96 #ifdef DISTRHO_OS_WINDOWS 
   97         InitializeCriticalSection(&fSection);
 
   99         pthread_mutexattr_t atts;
 
  100         pthread_mutexattr_init(&atts);
 
  101         pthread_mutexattr_settype(&atts, PTHREAD_MUTEX_RECURSIVE);
 
  102         pthread_mutex_init(&fMutex, &atts);
 
  103         pthread_mutexattr_destroy(&atts);
 
  112 #ifdef DISTRHO_OS_WINDOWS 
  113         DeleteCriticalSection(&fSection);
 
  115         pthread_mutex_destroy(&fMutex);
 
  122     void lock() 
const noexcept
 
  124 #ifdef DISTRHO_OS_WINDOWS 
  125         EnterCriticalSection(&fSection);
 
  127         pthread_mutex_lock(&fMutex);
 
  135     bool tryLock() 
const noexcept
 
  137 #ifdef DISTRHO_OS_WINDOWS 
  138         return (TryEnterCriticalSection(&fSection) != FALSE);
 
  140         return (pthread_mutex_trylock(&fMutex) == 0);
 
  147     void unlock() 
const noexcept
 
  149 #ifdef DISTRHO_OS_WINDOWS 
  150         LeaveCriticalSection(&fSection);
 
  152         pthread_mutex_unlock(&fMutex);
 
  157 #ifdef DISTRHO_OS_WINDOWS 
  158     mutable CRITICAL_SECTION fSection;
 
  160     mutable pthread_mutex_t fMutex;
 
  163     DISTRHO_PREVENT_HEAP_ALLOCATION
 
  170 template <
class Mutex>
 
  188     DISTRHO_PREVENT_HEAP_ALLOCATION
 
  195 template <
class Mutex>
 
  213     DISTRHO_PREVENT_HEAP_ALLOCATION
 
  228 END_NAMESPACE_DISTRHO
 
  230 #endif // DISTRHO_MUTEX_HPP_INCLUDED 
Definition: d_mutex.hpp:88
Definition: d_mutex.hpp:196
Definition: d_mutex.hpp:34
Definition: d_mutex.hpp:171