diff options
author | Joerg Mueller <nexyon@gmail.com> | 2012-04-28 17:37:44 +0400 |
---|---|---|
committer | Joerg Mueller <nexyon@gmail.com> | 2012-04-28 17:37:44 +0400 |
commit | 6e40b8b3cf33980d406bf8b6c405c112159926db (patch) | |
tree | 3fd5c43cf6a10bd6b06b5fc27b5b731f764c6ecd /intern | |
parent | ef3acaedc1eb530b263e9235d83d853f8282a278 (diff) |
Hopefully a fix for [#31097] glibc error when playing sound using BGE
Diffstat (limited to 'intern')
-rw-r--r-- | intern/audaspace/intern/AUD_Reference.h | 18 | ||||
-rw-r--r-- | intern/audaspace/intern/AUD_ReferenceHandler.cpp | 21 |
2 files changed, 39 insertions, 0 deletions
diff --git a/intern/audaspace/intern/AUD_Reference.h b/intern/audaspace/intern/AUD_Reference.h index 2e07417154b..0c9f02c0155 100644 --- a/intern/audaspace/intern/AUD_Reference.h +++ b/intern/audaspace/intern/AUD_Reference.h @@ -31,6 +31,7 @@ #include <map> #include <cstddef> +#include <pthread.h> // #define MEM_DEBUG @@ -49,8 +50,13 @@ private: * Saves the reference counts. */ static std::map<void*, unsigned int> m_references; + static pthread_mutex_t m_mutex; + static bool m_mutex_initialised; public: + + static pthread_mutex_t* getMutex(); + /** * Reference increment. * \param reference The reference. @@ -108,6 +114,7 @@ public: template <class U> AUD_Reference(U* reference) { + pthread_mutex_lock(AUD_ReferenceHandler::getMutex()); m_original = reference; m_reference = dynamic_cast<T*>(reference); AUD_ReferenceHandler::incref(m_original); @@ -115,6 +122,7 @@ public: if(m_reference != NULL) std::cerr << "+" << typeid(*m_reference).name() << std::endl; #endif + pthread_mutex_unlock(AUD_ReferenceHandler::getMutex()); } AUD_Reference() @@ -129,6 +137,7 @@ public: */ AUD_Reference(const AUD_Reference& ref) { + pthread_mutex_lock(AUD_ReferenceHandler::getMutex()); m_original = ref.m_original; m_reference = ref.m_reference; AUD_ReferenceHandler::incref(m_original); @@ -136,11 +145,13 @@ public: if(m_reference != NULL) std::cerr << "+" << typeid(*m_reference).name() << std::endl; #endif + pthread_mutex_unlock(AUD_ReferenceHandler::getMutex()); } template <class U> explicit AUD_Reference(const AUD_Reference<U>& ref) { + pthread_mutex_lock(AUD_ReferenceHandler::getMutex()); m_original = ref.get(); m_reference = dynamic_cast<T*>(ref.get()); AUD_ReferenceHandler::incref(m_original); @@ -148,6 +159,7 @@ public: if(m_reference != NULL) std::cerr << "+" << typeid(*m_reference).name() << std::endl; #endif + pthread_mutex_unlock(AUD_ReferenceHandler::getMutex()); } /** @@ -156,12 +168,14 @@ public: */ ~AUD_Reference() { + pthread_mutex_lock(AUD_ReferenceHandler::getMutex()); #ifdef MEM_DEBUG if(m_reference != NULL) std::cerr << "-" << typeid(*m_reference).name() << std::endl; #endif if(AUD_ReferenceHandler::decref(m_original)) delete m_reference; + pthread_mutex_unlock(AUD_ReferenceHandler::getMutex()); } /** @@ -173,6 +187,8 @@ public: if(&ref == this) return *this; + pthread_mutex_lock(AUD_ReferenceHandler::getMutex()); + #ifdef MEM_DEBUG if(m_reference != NULL) std::cerr << "-" << typeid(*m_reference).name() << std::endl; @@ -188,6 +204,8 @@ public: std::cerr << "+" << typeid(*m_reference).name() << std::endl; #endif + pthread_mutex_unlock(AUD_ReferenceHandler::getMutex()); + return *this; } diff --git a/intern/audaspace/intern/AUD_ReferenceHandler.cpp b/intern/audaspace/intern/AUD_ReferenceHandler.cpp index 24f645df761..3e9f6707262 100644 --- a/intern/audaspace/intern/AUD_ReferenceHandler.cpp +++ b/intern/audaspace/intern/AUD_ReferenceHandler.cpp @@ -29,3 +29,24 @@ #include "AUD_Reference.h" std::map<void*, unsigned int> AUD_ReferenceHandler::m_references; +pthread_mutex_t AUD_ReferenceHandler::m_mutex; +bool AUD_ReferenceHandler::m_mutex_initialised = false; + +pthread_mutex_t *AUD_ReferenceHandler::getMutex() +{ + if(!m_mutex_initialised) + { + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + + pthread_mutex_init(&m_mutex, &attr); + + pthread_mutexattr_destroy(&attr); + + m_mutex_initialised = true; + } + + return &m_mutex; +} + |