From 4d18a805d49ee01901517c13720bb4a9597351f4 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 27 Nov 2020 17:57:45 +0100 Subject: Use std::mutex --- src/AlsaDriver.cpp | 5 +++-- src/AlsaDriver.hpp | 3 ++- src/JackDriver.cpp | 9 ++++++--- src/JackDriver.hpp | 5 +++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index 8666137..af7d5e4 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -541,7 +541,7 @@ AlsaDriver::_refresh_main() while (snd_seq_event_input(_seq, &ev) > 0) { assert(ev); - Glib::Mutex::Lock lock(_events_mutex); + std::lock_guard lock{_events_mutex}; switch (ev->type) { case SND_SEQ_EVENT_PORT_SUBSCRIBED: @@ -604,7 +604,8 @@ AlsaDriver::_refresh_main() void AlsaDriver::process_events(Patchage* app) { - Glib::Mutex::Lock lock(_events_mutex); + std::lock_guard lock{_events_mutex}; + while (!_events.empty()) { PatchageEvent& ev = _events.front(); ev.execute(app); diff --git a/src/AlsaDriver.hpp b/src/AlsaDriver.hpp index 94dd101..45eb3db 100644 --- a/src/AlsaDriver.hpp +++ b/src/AlsaDriver.hpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -83,7 +84,7 @@ private: snd_seq_t* _seq; pthread_t _refresh_thread; - Glib::Mutex _events_mutex; + std::mutex _events_mutex; std::queue _events; struct SeqAddrComparator diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index e916f80..dfe2a1c 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -100,7 +100,8 @@ JackDriver::attach(bool launch_daemon) void JackDriver::detach() { - Glib::Mutex::Lock lock(_shutdown_mutex); + std::lock_guard lock{_shutdown_mutex}; + if (_client) { jack_deactivate(_client); jack_client_close(_client); @@ -277,7 +278,7 @@ JackDriver::refresh() // Jack can take _client away from us at any time throughout here :/ // Shortest locks possible is the best solution I can figure out - Glib::Mutex::Lock lock(_shutdown_mutex); + std::lock_guard lock{_shutdown_mutex}; if (_client == nullptr) { shutdown(); @@ -538,7 +539,9 @@ JackDriver::jack_shutdown_cb(void* jack_driver) assert(jack_driver); auto* me = reinterpret_cast(jack_driver); me->_app->info_msg("Jack: Shutdown."); - Glib::Mutex::Lock lock(me->_shutdown_mutex); + + std::lock_guard lock{me->_shutdown_mutex}; + me->_client = nullptr; me->_is_activated = false; me->signal_detached.emit(); diff --git a/src/JackDriver.hpp b/src/JackDriver.hpp index 5649950..6a404a7 100644 --- a/src/JackDriver.hpp +++ b/src/JackDriver.hpp @@ -1,5 +1,5 @@ /* This file is part of Patchage. - * Copyright 2007-2014 David Robillard + * Copyright 2007-2020 David Robillard * * Patchage is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free @@ -23,6 +23,7 @@ #include #include +#include #include class Patchage; @@ -96,7 +97,7 @@ private: Queue _events; - Glib::Mutex _shutdown_mutex; + std::mutex _shutdown_mutex; jack_position_t _last_pos; jack_nframes_t _buffer_size; -- cgit v1.2.1