summaryrefslogtreecommitdiff
path: root/drivers/alsamidi
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 /drivers/alsamidi
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 'drivers/alsamidi')
-rw-r--r--drivers/alsamidi/midi_driver_alsamidi.cpp13
-rw-r--r--drivers/alsamidi/midi_driver_alsamidi.h2
2 files changed, 3 insertions, 12 deletions
diff --git a/drivers/alsamidi/midi_driver_alsamidi.cpp b/drivers/alsamidi/midi_driver_alsamidi.cpp
index 670d7e0a4a..0cecf1de3e 100644
--- a/drivers/alsamidi/midi_driver_alsamidi.cpp
+++ b/drivers/alsamidi/midi_driver_alsamidi.cpp
@@ -148,7 +148,6 @@ Error MIDIDriverALSAMidi::open() {
}
snd_device_name_free_hint(hints);
- mutex = Mutex::create();
exit_thread = false;
thread = Thread::create(MIDIDriverALSAMidi::thread_func, this);
@@ -165,11 +164,6 @@ void MIDIDriverALSAMidi::close() {
thread = NULL;
}
- if (mutex) {
- memdelete(mutex);
- mutex = NULL;
- }
-
for (int i = 0; i < connected_inputs.size(); i++) {
snd_rawmidi_t *midi_in = connected_inputs[i];
snd_rawmidi_close(midi_in);
@@ -179,14 +173,12 @@ void MIDIDriverALSAMidi::close() {
void MIDIDriverALSAMidi::lock() const {
- if (mutex)
- mutex->lock();
+ mutex.lock();
}
void MIDIDriverALSAMidi::unlock() const {
- if (mutex)
- mutex->unlock();
+ mutex.unlock();
}
PackedStringArray MIDIDriverALSAMidi::get_connected_inputs() {
@@ -210,7 +202,6 @@ PackedStringArray MIDIDriverALSAMidi::get_connected_inputs() {
MIDIDriverALSAMidi::MIDIDriverALSAMidi() {
- mutex = NULL;
thread = NULL;
exit_thread = false;
diff --git a/drivers/alsamidi/midi_driver_alsamidi.h b/drivers/alsamidi/midi_driver_alsamidi.h
index 9900d90553..6797c7c138 100644
--- a/drivers/alsamidi/midi_driver_alsamidi.h
+++ b/drivers/alsamidi/midi_driver_alsamidi.h
@@ -44,7 +44,7 @@
class MIDIDriverALSAMidi : public MIDIDriver {
Thread *thread;
- Mutex *mutex;
+ Mutex mutex;
Vector<snd_rawmidi_t *> connected_inputs;