diff options
author | JP Cimalando <jpcima@users.noreply.github.com> | 2019-02-24 11:02:33 +0100 |
---|---|---|
committer | JP Cimalando <jpcima@users.noreply.github.com> | 2019-02-24 11:02:33 +0100 |
commit | 2e61743ff0092032c2f2590b8333cea55758fd13 (patch) | |
tree | 152c59035a986baa5488c23b6ac4844ff9eb95d5 /src/chips/dosbox | |
parent | 48751ca040600d80e92deecbabe61804e01a8ae7 (diff) | |
download | libADLMIDI-2e61743ff0092032c2f2590b8333cea55758fd13.tar.gz libADLMIDI-2e61743ff0092032c2f2590b8333cea55758fd13.tar.bz2 libADLMIDI-2e61743ff0092032c2f2590b8333cea55758fd13.zip |
javaopl3: thread safe initialization and cleanup
Diffstat (limited to 'src/chips/dosbox')
-rw-r--r-- | src/chips/dosbox/dbopl.cpp | 44 |
1 files changed, 9 insertions, 35 deletions
diff --git a/src/chips/dosbox/dbopl.cpp b/src/chips/dosbox/dbopl.cpp index 5260c37..d1ab82f 100644 --- a/src/chips/dosbox/dbopl.cpp +++ b/src/chips/dosbox/dbopl.cpp @@ -40,6 +40,7 @@ #include <vector> #include <memory> #include "dbopl.h" +#include "../common/mutex.hpp" #if defined(__GNUC__) && __GNUC__ > 3 #define INLINE inline __attribute__((__always_inline__)) @@ -83,37 +84,6 @@ #endif -struct NoCopy { - NoCopy() {} -private: - NoCopy(const NoCopy &); - NoCopy &operator=(const NoCopy &); -}; -#if !defined(_WIN32) -#include <pthread.h> -struct Mutex : NoCopy { - Mutex() { pthread_mutex_init(&m, NULL);} - ~Mutex() { pthread_mutex_destroy(&m); } - void lock() { pthread_mutex_lock(&m); } - void unlock() { pthread_mutex_unlock(&m); } - pthread_mutex_t m; -}; -#else -#include <windows.h> -struct Mutex : NoCopy { - Mutex() { InitializeCriticalSection(&m); } - ~Mutex() { DeleteCriticalSection(&m); } - void lock() { EnterCriticalSection(&m); } - void unlock() { LeaveCriticalSection(&m); } - CRITICAL_SECTION m; -}; -#endif -struct MutexHolder : NoCopy { - explicit MutexHolder(Mutex &m) : m(m) { m.lock(); } - ~MutexHolder() { m.unlock(); } - Mutex &m; -}; - namespace DBOPL { #define OPLRATE ((double)(14318180.0 / 288.0)) @@ -1344,10 +1314,14 @@ struct CacheEntry { Bit32u linearRates[76]; Bit32u attackRates[76]; }; -struct Cache : NoCopy { - ~Cache(); - Mutex mutex; - std::vector<CacheEntry *> entries; +struct Cache { + Cache() {} + ~Cache(); + Mutex mutex; + std::vector<CacheEntry *> entries; +private: + Cache(const Cache &); + Cache &operator=(const Cache &); }; static Cache cache; |