From b7341fdcb0f10025b725172d7b95ba5b1294b9d3 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 16 Dec 2017 12:42:04 +0100 Subject: Use unbounded queue for client signals --- ingen/client/ThreadedSigClientInterface.hpp | 46 ++++++++++------------------- 1 file changed, 16 insertions(+), 30 deletions(-) (limited to 'ingen') diff --git a/ingen/client/ThreadedSigClientInterface.hpp b/ingen/client/ThreadedSigClientInterface.hpp index 219fd8d1..96c47374 100644 --- a/ingen/client/ThreadedSigClientInterface.hpp +++ b/ingen/client/ThreadedSigClientInterface.hpp @@ -17,19 +17,18 @@ #ifndef INGEN_CLIENT_THREADEDSIGCLIENTINTERFACE_HPP #define INGEN_CLIENT_THREADEDSIGCLIENTINTERFACE_HPP -#include - +#include +#include #include +#include #undef nil #include -#include #include "ingen/Atom.hpp" #include "ingen/Interface.hpp" #include "ingen/client/SigClientInterface.hpp" #include "ingen/ingen.h" -#include "raul/SRSWQueue.hpp" /** Returns nothing and takes no parameters (because they have all been bound) */ typedef sigc::slot Closure; @@ -52,9 +51,8 @@ namespace Client { class INGEN_API ThreadedSigClientInterface : public SigClientInterface { public: - explicit ThreadedSigClientInterface(uint32_t queue_size) - : _sigs(queue_size) - , response_slot(_signal_response.make_slot()) + ThreadedSigClientInterface() + : response_slot(_signal_response.make_slot()) , error_slot(_signal_error.make_slot()) , put_slot(_signal_put.make_slot()) , connection_slot(_signal_connection.make_slot()) @@ -117,41 +115,29 @@ public: /** Process all queued events - Called from GTK thread to emit signals. */ bool emit_signals() { - // Process a limited number of events, to prevent locking the GTK - // thread indefinitely while processing continually arriving events + // Get pending signals + std::vector sigs; + { + std::lock_guard lock(_mutex); + std::swap(sigs, _sigs); + } - size_t num_processed = 0; - while (!_sigs.empty() && num_processed++ < (_sigs.capacity() * 3 / 4)) { - Closure& ev = _sigs.front(); + for (auto& ev : sigs) { ev(); ev.disconnect(); - _sigs.pop(); } - _mutex.lock(); - _cond.broadcast(); - _mutex.unlock(); - return true; } private: void push_sig(Closure ev) { - bool success = false; - while (!success) { - success = _sigs.push(ev); - if (!success) { - _mutex.lock(); - _cond.wait(_mutex); - _mutex.unlock(); - } - } + std::lock_guard lock(_mutex); + _sigs.push_back(ev); } - Glib::Mutex _mutex; - Glib::Cond _cond; - - Raul::SRSWQueue _sigs; + std::mutex _mutex; + std::vector _sigs; using Graph = Resource::Graph; using Path = Raul::Path; -- cgit v1.2.1