Jamoma API  0.6.0.a19
TTMutex.h
1 /*
2  * TTBlue Class that maintains a mutual exclusion lock
3  * Copyright © 2008, Timothy Place
4  *
5  * License: This code is licensed under the terms of the "New BSD License"
6  * http://creativecommons.org/licenses/BSD/
7  */
8 
9 #ifndef __TT_MUTEX_H__
10 #define __TT_MUTEX_H__
11 
12 #include "TTBase.h"
13 #include <mutex>
14 
15 #if defined(TT_PLATFORM_WIN)
16 bool TTFOUNDATION_EXPORT TTIsWindows8OrGreater();
17 #endif
18 
19 class TTMutex{
20 // Ugly hack, one should do a make_mutex template that generates the correct type but this
21 // involves changing every mutex creation in Jamoma
22  std::mutex mutex;
23  std::recursive_mutex rmutex;
24  const bool recursive;
25 
26  public:
27  TTMutex(bool isRecursive):
28  recursive(isRecursive)
29  {
30  }
31 
32  void lock()
33  {
34 #if defined(TT_PLATFORM_WIN)
35  if(TTIsWindows8OrGreater())
36 #endif
37  recursive ? rmutex.lock() : mutex.lock();
38  }
39 
40  void unlock()
41  {
42 #if defined(TT_PLATFORM_WIN)
43  if(TTIsWindows8OrGreater())
44 #endif
45  recursive ? rmutex.unlock() : mutex.unlock();
46  }
47 
48 };
49 
50 typedef TTMutex* TTMutexPtr;
51 typedef TTMutex& TTMutexRef;
52 
53 #endif // __TT_MUTEX_H__
Jamoma's lowest-level base class and related infrastructure.