diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2011-01-27 20:47:58 +0000 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2011-01-27 20:47:58 +0000 |
| commit | 2c05c49a04aa838047417825c289958efb59ee3c (patch) | |
| tree | 2731699f2223276c60b6b403d3a080d75f99bf74 /Source/Core/AudioCommon | |
| parent | 0371f15c23bf9fb64941e3adbc72b80f955e2ff5 (diff) | |
Replaced Common::Thread with a partial implementation of std::thread. (rvalue references are used if available, <thread> is used if possible) Eliminates the need to use dynamic memory allocation for threads, so it's impossible to forget to delete a thread or set a pointer to NULL. Enables use of type-safe thread functions, no need to cast to and from void*. I've made sure the code compiles in vs08 and tested the functionality of "StdThread.h" on Linux so I'm hoping everything will work :p. In the future "StdThread.h" can be removed (maybe when OS X ships with gcc 4.4 and vs2015 is released :p).
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6933 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core/AudioCommon')
| -rw-r--r-- | Source/Core/AudioCommon/Src/AOSoundStream.cpp | 10 | ||||
| -rw-r--r-- | Source/Core/AudioCommon/Src/AOSoundStream.h | 2 | ||||
| -rw-r--r-- | Source/Core/AudioCommon/Src/DSoundStream.cpp | 10 | ||||
| -rw-r--r-- | Source/Core/AudioCommon/Src/DSoundStream.h | 2 | ||||
| -rw-r--r-- | Source/Core/AudioCommon/Src/OpenALStream.cpp | 11 | ||||
| -rw-r--r-- | Source/Core/AudioCommon/Src/OpenALStream.h | 4 |
6 files changed, 16 insertions, 23 deletions
diff --git a/Source/Core/AudioCommon/Src/AOSoundStream.cpp b/Source/Core/AudioCommon/Src/AOSoundStream.cpp index cff38d1c7f..a1bc0e0a76 100644 --- a/Source/Core/AudioCommon/Src/AOSoundStream.cpp +++ b/Source/Core/AudioCommon/Src/AOSoundStream.cpp @@ -54,10 +54,9 @@ void AOSound::SoundLoop() } } -void *soundThread(void *args) +void soundThread(AOSound *aosound) { - ((AOSound *)args)->SoundLoop(); - return NULL; + aosound->SoundLoop(); } bool AOSound::Start() @@ -66,7 +65,7 @@ bool AOSound::Start() soundSyncEvent.Init(); - thread = new Common::Thread(soundThread, (void *)this); + thread = std::thread(soundThread, this); return true; } @@ -81,8 +80,7 @@ void AOSound::Stop() soundSyncEvent.Set(); soundCriticalSection.Enter(); - delete thread; - thread = NULL; + thread.join(); if (device) ao_close(device); diff --git a/Source/Core/AudioCommon/Src/AOSoundStream.h b/Source/Core/AudioCommon/Src/AOSoundStream.h index afba7b363f..57a883aa83 100644 --- a/Source/Core/AudioCommon/Src/AOSoundStream.h +++ b/Source/Core/AudioCommon/Src/AOSoundStream.h @@ -29,7 +29,7 @@ class AOSound : public SoundStream { #if defined(HAVE_AO) && HAVE_AO - Common::Thread *thread; + std::thread thread; Common::CriticalSection soundCriticalSection; Common::Event soundSyncEvent; diff --git a/Source/Core/AudioCommon/Src/DSoundStream.cpp b/Source/Core/AudioCommon/Src/DSoundStream.cpp index 3ebfa15659..7b17431cbc 100644 --- a/Source/Core/AudioCommon/Src/DSoundStream.cpp +++ b/Source/Core/AudioCommon/Src/DSoundStream.cpp @@ -91,10 +91,9 @@ bool DSound::WriteDataToBuffer(DWORD dwOffset, // Our own write } // The audio thread. -THREAD_RETURN soundThread(void* args) +void soundThread(DSound* dsound) { - (reinterpret_cast<DSound *>(args))->SoundLoop(); - return 0; + dsound->SoundLoop(); } void DSound::SoundLoop() @@ -138,7 +137,7 @@ bool DSound::Start() dsBuffer->Lock(0, bufferSize, (void* *)&p1, &num1, 0, 0, 0); memset(p1, 0, num1); dsBuffer->Unlock(p1, num1, 0, 0); - thread = new Common::Thread(soundThread, (void *)this); + thread = std::thread(soundThread, this); return true; } @@ -179,8 +178,7 @@ void DSound::Stop() // kick the thread if it's waiting soundSyncEvent.Set(); - delete thread; - thread = NULL; + thread.join(); dsBuffer->Stop(); dsBuffer->Release(); ds->Release(); diff --git a/Source/Core/AudioCommon/Src/DSoundStream.h b/Source/Core/AudioCommon/Src/DSoundStream.h index adbeaeb468..73d6fcbae3 100644 --- a/Source/Core/AudioCommon/Src/DSoundStream.h +++ b/Source/Core/AudioCommon/Src/DSoundStream.h @@ -31,7 +31,7 @@ class DSound : public SoundStream { #ifdef _WIN32 - Common::Thread *thread; + std::thread thread; Common::EventEx soundSyncEvent; void *hWnd; diff --git a/Source/Core/AudioCommon/Src/OpenALStream.cpp b/Source/Core/AudioCommon/Src/OpenALStream.cpp index e92d1cdc27..908f1c0099 100644 --- a/Source/Core/AudioCommon/Src/OpenALStream.cpp +++ b/Source/Core/AudioCommon/Src/OpenALStream.cpp @@ -44,8 +44,7 @@ bool OpenALStream::Start() if (pContext) { alcMakeContextCurrent(pContext); - thread = new Common::Thread( - OpenALStream::ThreadFunc, (void *)this); + thread = std::thread(OpenALStream::ThreadFunc, this); bReturn = true; } else @@ -75,8 +74,7 @@ void OpenALStream::Stop() // kick the thread if it's waiting soundSyncEvent.Set(); - delete thread; - thread = NULL; + thread.join(); alSourceStop(uiSource); alSourcei(uiSource, AL_BUFFER, 0); @@ -123,10 +121,9 @@ void OpenALStream::Clear(bool mute) } } -THREAD_RETURN OpenALStream::ThreadFunc(void* args) +void OpenALStream::ThreadFunc(OpenALStream* alstream) { - (reinterpret_cast<OpenALStream *>(args))->SoundLoop(); - return 0; + alstream->SoundLoop(); } void OpenALStream::SoundLoop() diff --git a/Source/Core/AudioCommon/Src/OpenALStream.h b/Source/Core/AudioCommon/Src/OpenALStream.h index 82a1eca1eb..7475fcfe83 100644 --- a/Source/Core/AudioCommon/Src/OpenALStream.h +++ b/Source/Core/AudioCommon/Src/OpenALStream.h @@ -58,10 +58,10 @@ public: virtual bool usesMixer() const { return true; } virtual void Update(); - static THREAD_RETURN ThreadFunc(void* args); + static void ThreadFunc(OpenALStream* args); private: - Common::Thread *thread; + std::thread thread; Common::EventEx soundSyncEvent; short realtimeBuffer[OAL_MAX_SAMPLES * 2]; |
