From 32e81d2bbc1a4457838cfbddfeb53305fecda867 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 5 Aug 2003 01:32:51 +0000 Subject: [PATCH] Use CHECKPOINT and RageThreads. --- .../InputHandler/InputHandler_DirectInput.cpp | 29 +++++++++---------- .../InputHandler/InputHandler_DirectInput.h | 8 ++--- .../InputHandler/InputHandler_Win32_Pump.cpp | 28 +++++++++--------- .../InputHandler/InputHandler_Win32_Pump.h | 6 ++-- .../src/arch/Sound/RageSoundDriver_DSound.cpp | 16 ++++------ .../src/arch/Sound/RageSoundDriver_DSound.h | 4 +-- .../Sound/RageSoundDriver_DSound_Software.cpp | 11 ++++--- .../Sound/RageSoundDriver_DSound_Software.h | 4 +-- .../arch/Sound/RageSoundDriver_WaveOut.cpp | 8 ++--- .../src/arch/Sound/RageSoundDriver_WaveOut.h | 4 +-- 10 files changed, 53 insertions(+), 65 deletions(-) diff --git a/stepmania/src/arch/InputHandler/InputHandler_DirectInput.cpp b/stepmania/src/arch/InputHandler/InputHandler_DirectInput.cpp index 224798e5da..f29a85d5c3 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_DirectInput.cpp +++ b/stepmania/src/arch/InputHandler/InputHandler_DirectInput.cpp @@ -116,28 +116,27 @@ InputHandler_DInput::InputHandler_DInput() Devices[i].buffered? "buffered": "unbuffered" ); } - InputThreadPtr = NULL; StartThread(); } void InputHandler_DInput::StartThread() { - ASSERT( InputThreadPtr == NULL ); + ASSERT( !InputThread.IsCreated() ); if( PREFSMAN->m_bThreadedInput ) - InputThreadPtr = SDL_CreateThread(InputThread_Start, this); - else - InputThreadPtr = NULL; + { + InputThread.SetName( "DirectInput thread" ); + InputThread.Create( InputThread_Start, this ); + } } void InputHandler_DInput::ShutdownThread() { - if( InputThreadPtr == NULL ) + if( !InputThread.IsCreated() ) return; shutdown = true; LOG->Trace("Shutting down DirectInput thread ..."); - SDL_WaitThread(InputThreadPtr, NULL); - InputThreadPtr = NULL; + InputThread.Wait(); LOG->Trace("DirectInput thread shut down."); shutdown = false; } @@ -427,7 +426,7 @@ void InputHandler_DInput::Update(float fDeltaTime) { if( !Devices[i].buffered ) UpdatePolled( Devices[i], zero ); - else if( InputThreadPtr == NULL ) + else if( !InputThread.IsCreated() ) { /* If we have an input thread, it'll handle buffered devices. */ UpdateBuffered( Devices[i], zero ); @@ -438,10 +437,8 @@ void InputHandler_DInput::Update(float fDeltaTime) } -void InputHandler_DInput::InputThread() +void InputHandler_DInput::InputThreadMain() { - InitThreadData("DirectInput thread"); - VDCHECKPOINT; if(!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST)) LOG->Warn(werr_ssprintf(GetLastError(), "Failed to set DirectInput thread priority")); @@ -467,7 +464,7 @@ void InputHandler_DInput::InputThread() while(!shutdown) { - VDCHECKPOINT; + CHECKPOINT; if( BufferedDevices.size() ) { /* Update buffered devices. */ @@ -487,14 +484,14 @@ void InputHandler_DInput::InputThread() UpdateBuffered( *BufferedDevices[i], now ); } } - VDCHECKPOINT; + CHECKPOINT; /* If we have no buffered devices, we didn't delay at WaitForMultipleObjectsEx. */ if( BufferedDevices.size() == 0 ) SDL_Delay( 50 ); - VDCHECKPOINT; + CHECKPOINT; } - VDCHECKPOINT; + CHECKPOINT; for( i = 0; i < Devices.size(); ++i ) { diff --git a/stepmania/src/arch/InputHandler/InputHandler_DirectInput.h b/stepmania/src/arch/InputHandler/InputHandler_DirectInput.h index 4f1988194a..4d2bf889be 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_DirectInput.h +++ b/stepmania/src/arch/InputHandler/InputHandler_DirectInput.h @@ -2,20 +2,20 @@ #define INPUTHANDLER_DIRECTINPUT_H #include "InputHandler.h" -#include "SDL_Thread.h" +#include "RageThreads.h" struct DIDevice; class InputHandler_DInput: public InputHandler { - SDL_Thread *InputThreadPtr; + RageThread InputThread; bool shutdown; void UpdatePolled(DIDevice &device, const RageTimer &tm); void UpdateBuffered(DIDevice &device, const RageTimer &tm); void PollAndAcquireDevices(); - static int InputThread_Start( void *p ) { ((InputHandler_DInput *) p)->InputThread(); return 0; } - void InputThread(); + static int InputThread_Start( void *p ) { ((InputHandler_DInput *) p)->InputThreadMain(); return 0; } + void InputThreadMain(); void StartThread(); void ShutdownThread(); diff --git a/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.cpp b/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.cpp index d8361eeff2..46245aa15d 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.cpp +++ b/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.cpp @@ -26,18 +26,19 @@ InputHandler_Win32_Pump::InputHandler_Win32_Pump() /* Don't start a thread if we have no pads. */ if( FoundOnePad && PREFSMAN->m_bThreadedInput ) - InputThreadPtr = SDL_CreateThread(InputThread_Start, this); - else - InputThreadPtr = NULL; + { + InputThread.SetName("Pump thread"); + InputThread.Create( InputThread_Start, this ); + } } InputHandler_Win32_Pump::~InputHandler_Win32_Pump() { - if( InputThreadPtr ) + if( InputThread.IsCreated() ) { shutdown = true; LOG->Trace("Shutting down Pump thread ..."); - SDL_WaitThread(InputThreadPtr, NULL); + InputThread.Wait(); LOG->Trace("Pump thread shut down."); } @@ -59,7 +60,7 @@ void InputHandler_Win32_Pump::HandleInput( int devno, int event ) DeviceInput dev(id, butno); /* If we're in a thread, our timestamp is accurate. */ - if( InputThreadPtr ) + if( InputThread.IsCreated() ) dev.ts.Touch(); ButtonPressed(dev, !(event & bits[butno])); @@ -80,15 +81,12 @@ void InputHandler_Win32_Pump::GetDevicesAndDescriptions(vector& vDe int InputHandler_Win32_Pump::InputThread_Start( void *p ) { - ((InputHandler_Win32_Pump *) p)->InputThread(); + ((InputHandler_Win32_Pump *) p)->InputThreadMain(); return 0; } -void InputHandler_Win32_Pump::InputThread() +void InputHandler_Win32_Pump::InputThreadMain() { - InitThreadData("Pump thread"); - VDCHECKPOINT; - vector sources; int i; for(i = 0; i < NUM_PUMPS; ++i) @@ -99,23 +97,23 @@ void InputHandler_Win32_Pump::InputThread() while(!shutdown) { - VDCHECKPOINT; + CHECKPOINT; int actual = 0, val = 0; int ret = WindowsFileIO::read_several(sources, &val, actual, 0.100f); - VDCHECKPOINT; + CHECKPOINT; if(ret <= 0) continue; /* no event */ HandleInput( actual, val ); InputHandler::UpdateTimer(); } - VDCHECKPOINT; + CHECKPOINT; } void InputHandler_Win32_Pump::Update(float fDeltaTime) { - if( InputThreadPtr == NULL ) + if( !InputThread.IsCreated() ) { for(int i = 0; i < NUM_PUMPS; ++i) { diff --git a/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.h b/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.h index 8671e8a2cd..27551daab7 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.h +++ b/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.h @@ -2,17 +2,17 @@ #define INPUT_HANDLER_WIN32_PUMP_H 1 #include "InputHandler.h" -#include "SDL_Thread.h" +#include "RageThreads.h" class USBDevice; class InputHandler_Win32_Pump: public InputHandler { USBDevice *dev; - SDL_Thread *InputThreadPtr; + RageThread InputThread; bool shutdown; static int InputThread_Start( void *p ); - void InputThread(); + void InputThreadMain(); void HandleInput( int devno, int event ); diff --git a/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp b/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp index ed333a9663..25f344fe2c 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_DSound.cpp @@ -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(); diff --git a/stepmania/src/arch/Sound/RageSoundDriver_DSound.h b/stepmania/src/arch/Sound/RageSoundDriver_DSound.h index f01cace0f5..f6d4b433d5 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_DSound.h +++ b/stepmania/src/arch/Sound/RageSoundDriver_DSound.h @@ -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 */ diff --git a/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.cpp b/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.cpp index a043200246..7a1297ebd9 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.cpp @@ -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(); diff --git a/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.h b/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.h index 525ba7dfe8..f71a21be98 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.h +++ b/stepmania/src/arch/Sound/RageSoundDriver_DSound_Software.h @@ -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 */ diff --git a/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.cpp b/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.cpp index a5f082d499..2d8a1e07ca 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.cpp +++ b/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.cpp @@ -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); diff --git a/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.h b/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.h index 9073790dcd..f71e62a21a 100644 --- a/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.h +++ b/stepmania/src/arch/Sound/RageSoundDriver_WaveOut.h @@ -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);