fix lock ordering
all sounds are now deleted in the main thread
This commit is contained in:
@@ -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. */
|
/* Indicate that a block of audio data has been written to the device. */
|
||||||
void RageSound::CommitPlayingPosition( int64_t frameno, int pos, int got_frames )
|
void RageSound::CommitPlayingPosition( int64_t frameno, int pos, int got_frames )
|
||||||
{
|
{
|
||||||
|
m_Mutex.Lock();
|
||||||
pos_map.Insert( frameno, pos, got_frames );
|
pos_map.Insert( frameno, pos, got_frames );
|
||||||
|
m_Mutex.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called by the mixer: return a block of sound data.
|
/* Called by the mixer: return a block of sound data.
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define RAGE_SOUND_OBJ_H
|
#define RAGE_SOUND_OBJ_H
|
||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
#include "RageThreads.h"
|
||||||
#include "RageTimer.h"
|
#include "RageTimer.h"
|
||||||
#include "RageUtil_CircularBuffer.h"
|
#include "RageUtil_CircularBuffer.h"
|
||||||
#include "RageSoundPosMap.h"
|
#include "RageSoundPosMap.h"
|
||||||
|
|||||||
@@ -161,9 +161,7 @@ void RageSoundManager::CommitPlayingPosition( int ID, int64_t frameno, int pos,
|
|||||||
|
|
||||||
RageSound *RageSoundManager::GetSoundByID( int ID )
|
RageSound *RageSoundManager::GetSoundByID( int ID )
|
||||||
{
|
{
|
||||||
/* You must lock this mutex before calling this function. If you don't,
|
LockMut( g_SoundManMutex );
|
||||||
* from any thread, the returned sound may be invalidated. */
|
|
||||||
ASSERT( g_SoundManMutex.IsLockedByThisThread() );
|
|
||||||
|
|
||||||
/* Find the sound with p.ID. */
|
/* Find the sound with p.ID. */
|
||||||
set<RageSound *>::iterator it;
|
set<RageSound *>::iterator it;
|
||||||
@@ -176,10 +174,6 @@ RageSound *RageSoundManager::GetSoundByID( int ID )
|
|||||||
/* This is only called by RageSoundManager::Update. */
|
/* This is only called by RageSoundManager::Update. */
|
||||||
void RageSoundManager::FlushPosMapQueue()
|
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;
|
queued_pos_map_t p;
|
||||||
|
|
||||||
/* We don't need to lock to access pos_map_queue. */
|
/* We don't need to lock to access pos_map_queue. */
|
||||||
@@ -260,6 +254,18 @@ set<RageSound *> RageSoundManager::GetPlayingSounds() const
|
|||||||
return playing_sounds;
|
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()
|
void RageSoundManager::StopPlayingSoundsForThisThread()
|
||||||
{
|
{
|
||||||
/* Lock to make sure sounds don't become invalidated below before we get to them. */
|
/* 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 */
|
g_SoundManMutex.Lock(); /* lock for access to all_sounds */
|
||||||
set<RageSound *> sounds = 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();
|
RageSound *parent = snd.GetOriginal();
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,10 @@ public:
|
|||||||
int GetDriverSampleRate( int rate ) const;
|
int GetDriverSampleRate( int rate ) const;
|
||||||
set<RageSound *> GetPlayingSounds() 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 );
|
void PlayOnce( CString sPath );
|
||||||
|
|
||||||
RageSound *PlaySound( RageSound &snd, const RageSoundParams *params );
|
RageSound *PlaySound( RageSound &snd, const RageSoundParams *params );
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ struct MusicPlaying
|
|||||||
|
|
||||||
~MusicPlaying()
|
~MusicPlaying()
|
||||||
{
|
{
|
||||||
delete m_Music;
|
SOUNDMAN->DeleteSound( m_Music );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user