summaryrefslogtreecommitdiff
path: root/drivers/xaudio2
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2021-01-19 13:29:41 +0100
committerPedro J. Estébanez <pedrojrulez@gmail.com>2021-01-29 12:02:13 +0100
commit99fe462452be44efa618e83ad9bbecd722ae6ecd (patch)
tree9bd84bc560b2c8049234d92d217396d21e68ba28 /drivers/xaudio2
parent6ddfc8e7187bd2b25b5caa61dee8fdca05af6298 (diff)
Modernize Thread
- Based on C++11's `thread` and `thread_local` - No more need to allocate-deallocate or check for null - No pointer anymore, just a member variable - Platform-specific implementations no longer needed (except for the few cases of non-portable functions) - Simpler for `NO_THREADS` - Thread ids are now the same across platforms (main is 1; others follow)
Diffstat (limited to 'drivers/xaudio2')
-rw-r--r--drivers/xaudio2/audio_driver_xaudio2.cpp14
-rw-r--r--drivers/xaudio2/audio_driver_xaudio2.h2
2 files changed, 3 insertions, 13 deletions
diff --git a/drivers/xaudio2/audio_driver_xaudio2.cpp b/drivers/xaudio2/audio_driver_xaudio2.cpp
index 3b3c3481b6..1bb8da769b 100644
--- a/drivers/xaudio2/audio_driver_xaudio2.cpp
+++ b/drivers/xaudio2/audio_driver_xaudio2.cpp
@@ -78,7 +78,7 @@ Error AudioDriverXAudio2::init() {
hr = xaudio->CreateSourceVoice(&source_voice, &wave_format, 0, XAUDIO2_MAX_FREQ_RATIO, &voice_callback);
ERR_FAIL_COND_V_MSG(hr != S_OK, ERR_UNAVAILABLE, "Error creating XAudio2 source voice. Error code: " + itos(hr) + ".");
- thread = Thread::create(AudioDriverXAudio2::thread_func, this);
+ thread.start(AudioDriverXAudio2::thread_func, this);
return OK;
}
@@ -146,23 +146,16 @@ float AudioDriverXAudio2::get_latency() {
}
void AudioDriverXAudio2::lock() {
- if (!thread)
- return;
mutex.lock();
}
void AudioDriverXAudio2::unlock() {
- if (!thread)
- return;
mutex.unlock();
}
void AudioDriverXAudio2::finish() {
- if (!thread)
- return;
-
exit_thread = true;
- Thread::wait_to_finish(thread);
+ thread.wait_to_finish();
if (source_voice) {
source_voice->Stop(0);
@@ -179,9 +172,6 @@ void AudioDriverXAudio2::finish() {
}
mastering_voice->DestroyVoice();
-
- memdelete(thread);
- thread = nullptr;
}
AudioDriverXAudio2::AudioDriverXAudio2() {
diff --git a/drivers/xaudio2/audio_driver_xaudio2.h b/drivers/xaudio2/audio_driver_xaudio2.h
index e3c2d3a326..d3938a19d0 100644
--- a/drivers/xaudio2/audio_driver_xaudio2.h
+++ b/drivers/xaudio2/audio_driver_xaudio2.h
@@ -62,7 +62,7 @@ class AudioDriverXAudio2 : public AudioDriver {
void STDMETHODCALLTYPE OnVoiceError(void *pBufferContext, HRESULT Error) {}
};
- Thread *thread = nullptr;
+ Thread thread;
Mutex mutex;
int32_t *samples_in = nullptr;