cAudio  2.3.0
3d Audio Engine
 All Classes Namespaces Functions Variables Enumerations Pages
cMutex.h
1 // Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
2 // This file is part of the "cAudio Engine"
3 // For conditions of distribution and use, see copyright notice in cAudio.h
4 
5 #pragma once
6 
7 #include "cAudioDefines.h"
8 
9 #if CAUDIO_MAKE_THREAD_SAFE == 1
10  #ifndef CAUDIO_PLATFORM_WIN
11  #include <pthread.h> //Assumed linux system
12  #endif
13 #endif
14 
15 namespace cAudio
16 {
17 #if CAUDIO_MAKE_THREAD_SAFE == 1
18  class cAudioMutex
20  {
21  public:
22  cAudioMutex();
23  ~cAudioMutex();
24 
25  void lock();
26  void unlock();
27  private:
28  void initialize();
29  #ifdef CAUDIO_PLATFORM_WIN
30  CRITICAL_SECTION criticalSection;
31  #else
32  pthread_mutex_t Mutex;
33  #endif
34  bool Initialized;
35  };
36 #else
37  //Dud class to disable the mutex
39  {
40  public:
41  cAudioMutex() {}
42  ~cAudioMutex() {}
43  void lock() {}
44  void unlock() {}
45  };
46 #endif
47 
49  {
50  public:
51  cAudioMutexBasicLock(cAudioMutex& mutex) : Mutex(&mutex)
52  {
53  Mutex->lock();
54  }
56  {
57  Mutex->unlock();
58  }
59  protected:
60  cAudioMutex* Mutex;
61  };
62 };