summaryrefslogtreecommitdiff
path: root/servers/audio
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2020-02-26 11:28:13 +0100
committerPedro J. Estébanez <pedrojrulez@gmail.com>2020-02-26 20:40:10 +0100
commit18fbdbb456c07a56b358bea2e392765fbcbb3283 (patch)
tree737363d20493afe45e75d932e0c1957dd9a79589 /servers/audio
parent1e57b558f215dd4920768e9567b6f55825877c89 (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 'servers/audio')
-rw-r--r--servers/audio/audio_driver_dummy.cpp12
-rw-r--r--servers/audio/audio_driver_dummy.h2
2 files changed, 5 insertions, 9 deletions
diff --git a/servers/audio/audio_driver_dummy.cpp b/servers/audio/audio_driver_dummy.cpp
index 5389c64099..69b098edfc 100644
--- a/servers/audio/audio_driver_dummy.cpp
+++ b/servers/audio/audio_driver_dummy.cpp
@@ -49,7 +49,6 @@ Error AudioDriverDummy::init() {
samples_in = memnew_arr(int32_t, buffer_frames * channels);
- mutex = Mutex::create();
thread = Thread::create(AudioDriverDummy::thread_func, this);
return OK;
@@ -95,16 +94,16 @@ AudioDriver::SpeakerMode AudioDriverDummy::get_speaker_mode() const {
void AudioDriverDummy::lock() {
- if (!thread || !mutex)
+ if (!thread)
return;
- mutex->lock();
+ mutex.lock();
};
void AudioDriverDummy::unlock() {
- if (!thread || !mutex)
+ if (!thread)
return;
- mutex->unlock();
+ mutex.unlock();
};
void AudioDriverDummy::finish() {
@@ -120,14 +119,11 @@ void AudioDriverDummy::finish() {
};
memdelete(thread);
- if (mutex)
- memdelete(mutex);
thread = NULL;
};
AudioDriverDummy::AudioDriverDummy() {
- mutex = NULL;
thread = NULL;
};
diff --git a/servers/audio/audio_driver_dummy.h b/servers/audio/audio_driver_dummy.h
index ba99e5a239..a2cd9b2dc6 100644
--- a/servers/audio/audio_driver_dummy.h
+++ b/servers/audio/audio_driver_dummy.h
@@ -39,7 +39,7 @@
class AudioDriverDummy : public AudioDriver {
Thread *thread;
- Mutex *mutex;
+ Mutex mutex;
int32_t *samples_in;