From 18fbdbb456c07a56b358bea2e392765fbcbb3283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Wed, 26 Feb 2020 11:28:13 +0100 Subject: Reimplement Mutex with C++'s Main: - It's now implemented thanks to ``. 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`. --- platform/haiku/audio_driver_media_kit.cpp | 11 ++--------- platform/haiku/audio_driver_media_kit.h | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) (limited to 'platform/haiku') diff --git a/platform/haiku/audio_driver_media_kit.cpp b/platform/haiku/audio_driver_media_kit.cpp index b7f6b57244..0a5df14743 100644 --- a/platform/haiku/audio_driver_media_kit.cpp +++ b/platform/haiku/audio_driver_media_kit.cpp @@ -67,7 +67,6 @@ Error AudioDriverMediaKit::init() { ERR_FAIL_COND_V(player == NULL, ERR_CANT_OPEN); } - mutex = Mutex::create(); player->Start(); return OK; @@ -108,14 +107,14 @@ void AudioDriverMediaKit::lock() { if (!mutex) return; - mutex->lock(); + mutex.lock(); } void AudioDriverMediaKit::unlock() { if (!mutex) return; - mutex->unlock(); + mutex.unlock(); } void AudioDriverMediaKit::finish() { @@ -124,15 +123,9 @@ void AudioDriverMediaKit::finish() { if (samples_in) { memdelete_arr(samples_in); }; - - if (mutex) { - memdelete(mutex); - mutex = NULL; - } } AudioDriverMediaKit::AudioDriverMediaKit() { - mutex = NULL; player = NULL; } diff --git a/platform/haiku/audio_driver_media_kit.h b/platform/haiku/audio_driver_media_kit.h index 06a362a89e..8272780fa7 100644 --- a/platform/haiku/audio_driver_media_kit.h +++ b/platform/haiku/audio_driver_media_kit.h @@ -40,7 +40,7 @@ #include class AudioDriverMediaKit : public AudioDriver { - Mutex *mutex; + Mutex mutex; BSoundPlayer *player; static int32_t *samples_in; -- cgit v1.2.3