Use CHECKPOINT and RageThreads.
This commit is contained in:
@@ -40,11 +40,6 @@ int RageSound_DSound::MixerThread_start(void *p)
|
||||
|
||||
void RageSound_DSound::MixerThread()
|
||||
{
|
||||
#ifdef _WINDOWS
|
||||
InitThreadData("Mixer thread");
|
||||
#endif
|
||||
VDCHECKPOINT;
|
||||
|
||||
/* SOUNDMAN will be set once RageSoundManager's ctor returns and
|
||||
* assigns it; we might get here before that happens, though. */
|
||||
while(!SOUNDMAN && !shutdown) Sleep(10);
|
||||
@@ -53,14 +48,14 @@ void RageSound_DSound::MixerThread()
|
||||
LOG->Warn(werr_ssprintf(GetLastError(), "Failed to set sound thread priority"));
|
||||
|
||||
while(!shutdown) {
|
||||
VDCHECKPOINT;
|
||||
CHECKPOINT;
|
||||
|
||||
/* Sleep for the size of one chunk. */
|
||||
const int chunksize_frames = buffersize_frames / num_chunks;
|
||||
float sleep_secs = (float(chunksize_frames) / samplerate);
|
||||
Sleep(int(1000 * sleep_secs));
|
||||
|
||||
VDCHECKPOINT;
|
||||
CHECKPOINT;
|
||||
LockMutex L(SOUNDMAN->lock);
|
||||
for(unsigned i = 0; i < stream_pool.size(); ++i)
|
||||
{
|
||||
@@ -104,7 +99,7 @@ void RageSound_DSound::Update(float delta)
|
||||
* it in the opposite buffer. */
|
||||
bool RageSound_DSound::stream::GetData(bool init)
|
||||
{
|
||||
VDCHECKPOINT;
|
||||
CHECKPOINT;
|
||||
|
||||
char *locked_buf;
|
||||
unsigned len;
|
||||
@@ -196,7 +191,8 @@ RageSound_DSound::RageSound_DSound()
|
||||
/* Set channel volumes. */
|
||||
VolumeChanged();
|
||||
|
||||
MixerThreadPtr = SDL_CreateThread(MixerThread_start, this);
|
||||
MixingThread.SetName("Mixer thread");
|
||||
MixingThread.Create( MixerThread_start, this );
|
||||
}
|
||||
|
||||
RageSound_DSound::~RageSound_DSound()
|
||||
@@ -205,7 +201,7 @@ RageSound_DSound::~RageSound_DSound()
|
||||
shutdown = true;
|
||||
LOG->Trace("Shutting down mixer thread ...");
|
||||
LOG->Flush();
|
||||
SDL_WaitThread(MixerThreadPtr, NULL);
|
||||
MixingThread.Wait();
|
||||
LOG->Trace("Mixer thread shut down.");
|
||||
LOG->Flush();
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#define RAGE_SOUND_DSOUND
|
||||
|
||||
#include "RageSoundDriver.h"
|
||||
#include "SDL_Thread.h"
|
||||
#include "DSoundHelpers.h"
|
||||
#include "RageThreads.h"
|
||||
|
||||
struct IDirectSound;
|
||||
struct IDirectSoundBuffer;
|
||||
@@ -41,7 +41,7 @@ class RageSound_DSound: public RageSoundDriver
|
||||
bool shutdown; /* tells the MixerThread to shut down */
|
||||
static int MixerThread_start(void *p);
|
||||
void MixerThread();
|
||||
SDL_Thread *MixerThreadPtr;
|
||||
RageThread MixingThread;
|
||||
|
||||
/* virtuals: */
|
||||
void StartMixing(RageSound *snd); /* used by RageSound */
|
||||
|
||||
@@ -32,9 +32,6 @@ int RageSound_DSound_Software::MixerThread_start(void *p)
|
||||
|
||||
void RageSound_DSound_Software::MixerThread()
|
||||
{
|
||||
InitThreadData("Mixer thread");
|
||||
VDCHECKPOINT;
|
||||
|
||||
/* SOUNDMAN will be set once RageSoundManager's ctor returns and
|
||||
* assigns it; we might get here before that happens, though. */
|
||||
while(!SOUNDMAN && !shutdown) Sleep(10);
|
||||
@@ -178,16 +175,18 @@ RageSound_DSound_Software::RageSound_DSound_Software()
|
||||
str_ds = new DSoundBuf(ds,
|
||||
DSoundBuf::HW_DONT_CARE,
|
||||
channels, samplerate, 16, buffersize);
|
||||
MixerThreadPtr = SDL_CreateThread(MixerThread_start, this);
|
||||
|
||||
MixingThread.SetName("Mixer thread");
|
||||
MixingThread.Create( MixerThread_start, this );
|
||||
}
|
||||
|
||||
RageSound_DSound_Software::~RageSound_DSound_Software()
|
||||
{
|
||||
/* Signal the mixing thread to quit. */
|
||||
shutdown = true;
|
||||
LOG->Trace("Shutting down mixer thread %p ...", MixerThreadPtr);
|
||||
LOG->Trace("Shutting down mixer thread ...");
|
||||
LOG->Flush();
|
||||
SDL_WaitThread(MixerThreadPtr, NULL);
|
||||
MixingThread.Wait();
|
||||
LOG->Trace("Mixer thread shut down.");
|
||||
LOG->Flush();
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#define RAGE_SOUND_DSOUND_SOFTWARE
|
||||
|
||||
#include "RageSoundDriver.h"
|
||||
#include "SDL_Thread.h"
|
||||
#include "DSoundHelpers.h"
|
||||
#include "RageThreads.h"
|
||||
|
||||
struct IDirectSound;
|
||||
struct IDirectSoundBuffer;
|
||||
@@ -33,7 +33,7 @@ class RageSound_DSound_Software: public RageSoundDriver
|
||||
|
||||
static int MixerThread_start(void *p);
|
||||
void MixerThread();
|
||||
SDL_Thread *MixerThreadPtr;
|
||||
RageThread MixingThread;
|
||||
|
||||
/* virtuals: */
|
||||
void StartMixing(RageSound *snd); /* used by RageSound */
|
||||
|
||||
@@ -44,9 +44,6 @@ int RageSound_WaveOut::MixerThread_start(void *p)
|
||||
|
||||
void RageSound_WaveOut::MixerThread()
|
||||
{
|
||||
InitThreadData("Mixer thread");
|
||||
VDCHECKPOINT;
|
||||
|
||||
/* SOUNDMAN will be set once RageSoundManager's ctor returns and
|
||||
* assigns it; we might get here before that happens, though. */
|
||||
while(!SOUNDMAN && !shutdown) Sleep(10);
|
||||
@@ -204,7 +201,8 @@ RageSound_WaveOut::RageSound_WaveOut()
|
||||
buffers[b].dwFlags |= WHDR_DONE;
|
||||
}
|
||||
|
||||
MixerThreadPtr = SDL_CreateThread(MixerThread_start, this);
|
||||
MixingThread.SetName("Mixer thread");
|
||||
MixingThread.Create( MixerThread_start, this );
|
||||
}
|
||||
|
||||
RageSound_WaveOut::~RageSound_WaveOut()
|
||||
@@ -212,7 +210,7 @@ RageSound_WaveOut::~RageSound_WaveOut()
|
||||
/* Signal the mixing thread to quit. */
|
||||
shutdown = true;
|
||||
LOG->Trace("Shutting down mixer thread ...");
|
||||
SDL_WaitThread(MixerThreadPtr, NULL);
|
||||
MixingThread.Wait();
|
||||
LOG->Trace("Mixer thread shut down.");
|
||||
|
||||
CloseHandle(sound_event);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define RAGE_SOUND_WAVEOUT
|
||||
|
||||
#include "RageSoundDriver.h"
|
||||
#include "SDL_Thread.h"
|
||||
#include "RageThreads.h"
|
||||
#include "Mmsystem.h"
|
||||
|
||||
class RageSound_WaveOut: public RageSoundDriver
|
||||
@@ -28,7 +28,7 @@ class RageSound_WaveOut: public RageSoundDriver
|
||||
|
||||
static int MixerThread_start(void *p);
|
||||
void MixerThread();
|
||||
SDL_Thread *MixerThreadPtr;
|
||||
RageThread MixingThread;
|
||||
|
||||
bool GetData();
|
||||
void Update(float delta);
|
||||
|
||||
Reference in New Issue
Block a user