diff --git a/src/threading/Manager.cc b/src/threading/Manager.cc index db86caa26f..6a539861be 100644 --- a/src/threading/Manager.cc +++ b/src/threading/Manager.cc @@ -82,6 +82,12 @@ double Manager::NextTimestamp(double* network_time) // If we had something to process last time (or out heartbeat // is due), we want to check for more asap. return timer_mgr->Time(); + + for ( msg_thread_list::iterator i = msg_threads.begin(); i != msg_threads.end(); i++ ) + { + if ( (*i)->MightHaveOut() ) + return timer_mgr->Time(); + } return -1.0; } diff --git a/src/threading/MsgThread.h b/src/threading/MsgThread.h index 28c7690dfa..4220230a71 100644 --- a/src/threading/MsgThread.h +++ b/src/threading/MsgThread.h @@ -261,6 +261,12 @@ private: */ bool HasOut() { return queue_out.Ready(); } + /** + * Returns true if there might be at least one message pending for the main + * thread. + */ + bool MightHaveOut() { return queue_out.MaybeReady(); } + Queue queue_in; Queue queue_out; diff --git a/src/threading/Queue.h b/src/threading/Queue.h index a25f897d23..64d6e7cd93 100644 --- a/src/threading/Queue.h +++ b/src/threading/Queue.h @@ -53,6 +53,11 @@ public: */ bool Ready(); + /** + * Returns true if the next Get() operation might succeed. + */ + bool MaybeReady() { return ( ( read_ptr - write_ptr) != 0 ); } + /** * Returns the number of queued items not yet retrieved. */