From a3559623ed6d4d11936db8ee9fc59ec7592942e1 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Tue, 22 Jun 2010 03:20:28 +0000 Subject: [PATCH] added mutex around m_active_sounds git-svn-id: svn://anubis/anaglym/trunk@283 99a6e188-d820-4881-8870-2d33a10e2619 --- AV.cc | 8 ++++++++ AV.h | 1 + 2 files changed, 9 insertions(+) diff --git a/AV.cc b/AV.cc index e57d061..0936425 100644 --- a/AV.cc +++ b/AV.cc @@ -60,10 +60,14 @@ AV::AV() cerr << "SDL_OpenAudio() error." << endl; exit(3); } + + m_active_sounds_mutex = SDL_CreateMutex(); } AV::~AV() { + SDL_PauseAudio(1); + SDL_DestroyMutex(m_active_sounds_mutex); SDL_CloseAudio(); Sound_Quit(); SDL_Quit(); @@ -134,13 +138,16 @@ refptr AV::createSound() void AV::playSound(AV::Sound * s) { + SDL_mutexP(m_active_sounds_mutex); m_active_sounds.insert(s); + SDL_mutexV(m_active_sounds_mutex); SDL_PauseAudio(0); } void AV::playCallback(Uint8 * stream, int len) { memset(stream, 0, len); + SDL_mutexP(m_active_sounds_mutex); for (std::set::iterator it = m_active_sounds.begin(); it != m_active_sounds.end(); it++) @@ -154,6 +161,7 @@ void AV::playCallback(Uint8 * stream, int len) { SDL_PauseAudio(1); } + SDL_mutexV(m_active_sounds_mutex); } AV::Sound::Sound(AV & av) diff --git a/AV.h b/AV.h index 149543c..b420bfb 100644 --- a/AV.h +++ b/AV.h @@ -77,6 +77,7 @@ class AV std::set< refptr > m_sounds; #endif std::set< Sound * > m_active_sounds; + SDL_mutex * m_active_sounds_mutex; }; #endif