diff options
author | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2020-02-26 11:28:13 +0100 |
---|---|---|
committer | Pedro J. Estébanez <pedrojrulez@gmail.com> | 2020-02-26 20:40:10 +0100 |
commit | 18fbdbb456c07a56b358bea2e392765fbcbb3283 (patch) | |
tree | 737363d20493afe45e75d932e0c1957dd9a79589 /drivers/xaudio2 | |
parent | 1e57b558f215dd4920768e9567b6f55825877c89 (diff) |
Reimplement Mutex with C++'s <mutex>
Main:
- It's now implemented thanks to `<mutex>`. No more platform-specific implementations.
- `BinaryMutex` (non-recursive) is added, as an alternative for special cases.
- Doesn't need allocation/deallocation anymore. It can live in the stack and be part of other classes.
- Because of that, it's methods are now `const` and the inner mutex is `mutable` so it can be easily used in `const` contexts.
- A no-op implementation is provided if `NO_THREADS` is defined. No more need to add `#ifdef NO_THREADS` just for this.
- `MutexLock` now takes a reference. At this point the cases of null `Mutex`es are rare. If you ever need that, just don't use `MutexLock`.
- Thread-safe utilities are therefore simpler now.
Misc.:
- `ScopedMutexLock` is dropped and replaced by `MutexLock`, because they were pretty much the same.
- Every case of lock, do-something, unlock is replaced by `MutexLock` (complex cases where it's not straightfoward are kept as as explicit lock and unlock).
- `ShaderRD` contained an `std::mutex`, which has been replaced by `Mutex`.
Diffstat (limited to 'drivers/xaudio2')
-rw-r--r-- | drivers/xaudio2/audio_driver_xaudio2.cpp | 12 | ||||
-rw-r--r-- | drivers/xaudio2/audio_driver_xaudio2.h | 2 |
2 files changed, 5 insertions, 9 deletions
diff --git a/drivers/xaudio2/audio_driver_xaudio2.cpp b/drivers/xaudio2/audio_driver_xaudio2.cpp index 85e505009b..9c7cb4f0f3 100644 --- a/drivers/xaudio2/audio_driver_xaudio2.cpp +++ b/drivers/xaudio2/audio_driver_xaudio2.cpp @@ -79,7 +79,6 @@ 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) + "."); - mutex = Mutex::create(); thread = Thread::create(AudioDriverXAudio2::thread_func, this); return OK; @@ -158,15 +157,15 @@ float AudioDriverXAudio2::get_latency() { void AudioDriverXAudio2::lock() { - if (!thread || !mutex) + if (!thread) return; - mutex->lock(); + mutex.lock(); } void AudioDriverXAudio2::unlock() { - if (!thread || !mutex) + if (!thread) return; - mutex->unlock(); + mutex.unlock(); } void AudioDriverXAudio2::finish() { @@ -194,14 +193,11 @@ void AudioDriverXAudio2::finish() { mastering_voice->DestroyVoice(); memdelete(thread); - if (mutex) - memdelete(mutex); thread = NULL; } AudioDriverXAudio2::AudioDriverXAudio2() : thread(NULL), - mutex(NULL), current_buffer(0) { wave_format = { 0 }; for (int i = 0; i < AUDIO_BUFFERS; i++) { diff --git a/drivers/xaudio2/audio_driver_xaudio2.h b/drivers/xaudio2/audio_driver_xaudio2.h index 98950851d0..108891a288 100644 --- a/drivers/xaudio2/audio_driver_xaudio2.h +++ b/drivers/xaudio2/audio_driver_xaudio2.h @@ -65,7 +65,7 @@ class AudioDriverXAudio2 : public AudioDriver { }; Thread *thread; - Mutex *mutex; + Mutex mutex; int32_t *samples_in; int16_t *samples_out[AUDIO_BUFFERS]; |