From e16206982d074e62956de00eeef611478f01c430 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 19 Aug 2008 18:51:06 +0000 Subject: Preliminary connecting via HTTP in Gtk client. Better handling of overflowed client event receive buffer. Store fixes, complain only once about orphans, don't request an orphan parent over and over. git-svn-id: http://svn.drobilla.net/lad/ingen@1447 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/client/ThreadedSigClientInterface.cpp | 32 +++++++++++++------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/libs/client/ThreadedSigClientInterface.cpp') diff --git a/src/libs/client/ThreadedSigClientInterface.cpp b/src/libs/client/ThreadedSigClientInterface.cpp index 3b7af80c..ef95133b 100644 --- a/src/libs/client/ThreadedSigClientInterface.cpp +++ b/src/libs/client/ThreadedSigClientInterface.cpp @@ -17,7 +17,8 @@ #include "ThreadedSigClientInterface.hpp" #include -using std::cerr; using std::endl; + +using namespace std; namespace Ingen { namespace Client { @@ -28,23 +29,19 @@ namespace Client { void ThreadedSigClientInterface::push_sig(Closure ev) { + _attached = true; if (!_enabled) return; bool success = false; - bool first = true; - - // (Very) slow busy-wait if the queue is full - // FIXME: Make this wait on a signal from process_sigs iff this happens while (!success) { - //printf("push %zu\n", _sigs.fill()); success = _sigs.push(ev); if (!success) { - if (first) { - cerr << "[ThreadedSigClientInterface] WARNING: (Client) event queue full. Waiting to try again..." << endl; - first = false; - } - usleep(200000); // 100 milliseconds (2* rate process_sigs is called) + cerr << "WARNING: Client event queue full. Waiting..." << endl; + _mutex.lock(); + _cond.wait(_mutex); + _mutex.unlock(); + cerr << "Queue drained, continuing" << endl; } } } @@ -58,18 +55,21 @@ ThreadedSigClientInterface::push_sig(Closure ev) bool ThreadedSigClientInterface::emit_signals() { - // Process a maximum of queue-size events, to prevent locking the GTK + // Process a limited number of events, to prevent locking the GTK // thread indefinitely while processing continually arriving events - const size_t limit = _sigs.capacity(); + size_t num_processed = 0; - while (!_sigs.empty() && num_processed++ < limit) { - //printf("emit %zu\n", _sigs.fill()); + while (!_sigs.empty() && num_processed++ < (_sigs.capacity() * 3 / 4)) { Closure& ev = _sigs.front(); - _sigs.pop(); ev(); ev.disconnect(); + _sigs.pop(); } + _mutex.lock(); + _cond.broadcast(); + _mutex.unlock(); + return true; } -- cgit v1.2.1