added mutex around m_active_sounds

git-svn-id: svn://anubis/anaglym/trunk@283 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2010-06-22 03:20:28 +00:00
parent f782e5dc77
commit a3559623ed
2 changed files with 9 additions and 0 deletions

8
AV.cc
View File

@ -60,10 +60,14 @@ AV::AV()
cerr << "SDL_OpenAudio() error." << endl; cerr << "SDL_OpenAudio() error." << endl;
exit(3); exit(3);
} }
m_active_sounds_mutex = SDL_CreateMutex();
} }
AV::~AV() AV::~AV()
{ {
SDL_PauseAudio(1);
SDL_DestroyMutex(m_active_sounds_mutex);
SDL_CloseAudio(); SDL_CloseAudio();
Sound_Quit(); Sound_Quit();
SDL_Quit(); SDL_Quit();
@ -134,13 +138,16 @@ refptr<AV::Sound> AV::createSound()
void AV::playSound(AV::Sound * s) void AV::playSound(AV::Sound * s)
{ {
SDL_mutexP(m_active_sounds_mutex);
m_active_sounds.insert(s); m_active_sounds.insert(s);
SDL_mutexV(m_active_sounds_mutex);
SDL_PauseAudio(0); SDL_PauseAudio(0);
} }
void AV::playCallback(Uint8 * stream, int len) void AV::playCallback(Uint8 * stream, int len)
{ {
memset(stream, 0, len); memset(stream, 0, len);
SDL_mutexP(m_active_sounds_mutex);
for (std::set<Sound *>::iterator it = m_active_sounds.begin(); for (std::set<Sound *>::iterator it = m_active_sounds.begin();
it != m_active_sounds.end(); it != m_active_sounds.end();
it++) it++)
@ -154,6 +161,7 @@ void AV::playCallback(Uint8 * stream, int len)
{ {
SDL_PauseAudio(1); SDL_PauseAudio(1);
} }
SDL_mutexV(m_active_sounds_mutex);
} }
AV::Sound::Sound(AV & av) AV::Sound::Sound(AV & av)

1
AV.h
View File

@ -77,6 +77,7 @@ class AV
std::set< refptr<Sound> > m_sounds; std::set< refptr<Sound> > m_sounds;
#endif #endif
std::set< Sound * > m_active_sounds; std::set< Sound * > m_active_sounds;
SDL_mutex * m_active_sounds_mutex;
}; };
#endif #endif