fix lock ordering

all sounds are now deleted in the main thread
This commit is contained in:
Glenn Maynard
2004-04-16 22:28:01 +00:00
parent 63735fe781
commit b925b61654
5 changed files with 22 additions and 9 deletions
+2
View File
@@ -519,7 +519,9 @@ bool RageSound::GetDataToPlay( int16_t *buffer, int size, int &sound_frame, int
/* Indicate that a block of audio data has been written to the device. */
void RageSound::CommitPlayingPosition( int64_t frameno, int pos, int got_frames )
{
m_Mutex.Lock();
pos_map.Insert( frameno, pos, got_frames );
m_Mutex.Unlock();
}
/* Called by the mixer: return a block of sound data.
+1
View File
@@ -2,6 +2,7 @@
#define RAGE_SOUND_OBJ_H
#include <deque>
#include "RageThreads.h"
#include "RageTimer.h"
#include "RageUtil_CircularBuffer.h"
#include "RageSoundPosMap.h"
+14 -8
View File
@@ -161,9 +161,7 @@ void RageSoundManager::CommitPlayingPosition( int ID, int64_t frameno, int pos,
RageSound *RageSoundManager::GetSoundByID( int ID )
{
/* You must lock this mutex before calling this function. If you don't,
* from any thread, the returned sound may be invalidated. */
ASSERT( g_SoundManMutex.IsLockedByThisThread() );
LockMut( g_SoundManMutex );
/* Find the sound with p.ID. */
set<RageSound *>::iterator it;
@@ -176,10 +174,6 @@ RageSound *RageSoundManager::GetSoundByID( int ID )
/* This is only called by RageSoundManager::Update. */
void RageSoundManager::FlushPosMapQueue()
{
/* Lock, to make sure sounds returned by GetSoundByID remain valid until we're
* done with them. */
LockMut(g_SoundManMutex);
queued_pos_map_t p;
/* We don't need to lock to access pos_map_queue. */
@@ -260,6 +254,18 @@ set<RageSound *> RageSoundManager::GetPlayingSounds() const
return playing_sounds;
}
void RageSoundManager::DeleteSound( RageSound *p )
{
/* Stop playing the sound. */
p->StopPlaying();
/* Add it to owned_sounds. It'll be deleted the next time we come around
* to Update(). */
g_SoundManMutex.Lock(); /* lock for access to owned_sounds */
owned_sounds.insert( p );
g_SoundManMutex.Unlock(); /* finished with owned_sounds */
}
void RageSoundManager::StopPlayingSoundsForThisThread()
{
/* Lock to make sure sounds don't become invalidated below before we get to them. */
@@ -295,7 +301,7 @@ void RageSoundManager::GetCopies( RageSound &snd, vector<RageSound *> &snds, boo
g_SoundManMutex.Lock(); /* lock for access to all_sounds */
set<RageSound *> sounds = all_sounds;
g_SoundManMutex.Unlock(); /* finished with owned_sounds */
g_SoundManMutex.Unlock(); /* finished with all_sounds */
RageSound *parent = snd.GetOriginal();
+4
View File
@@ -53,6 +53,10 @@ public:
int GetDriverSampleRate( int rate ) const;
set<RageSound *> GetPlayingSounds() const;
/* When deleting a sound from any thread except the one calling Update(), this
* must be used to prevent race conditions. */
void DeleteSound( RageSound *p );
void PlayOnce( CString sPath );
RageSound *PlaySound( RageSound &snd, const RageSoundParams *params );
+1 -1
View File
@@ -53,7 +53,7 @@ struct MusicPlaying
~MusicPlaying()
{
delete m_Music;
SOUNDMAN->DeleteSound( m_Music );
}
};