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`.
This commit is contained in:
@ -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;
|
||||
|
||||
@ -44,7 +44,7 @@
|
||||
class MIDIDriverALSAMidi : public MIDIDriver {
|
||||
|
||||
Thread *thread;
|
||||
Mutex *mutex;
|
||||
Mutex mutex;
|
||||
|
||||
Vector<snd_rawmidi_t *> connected_inputs;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user