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 /platform/haiku | |
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 'platform/haiku')
-rw-r--r-- | platform/haiku/audio_driver_media_kit.cpp | 11 | ||||
-rw-r--r-- | platform/haiku/audio_driver_media_kit.h | 2 |
2 files changed, 3 insertions, 10 deletions
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 <SoundPlayer.h> class AudioDriverMediaKit : public AudioDriver { - Mutex *mutex; + Mutex mutex; BSoundPlayer *player; static int32_t *samples_in; |