From 843d59675dbb4baecbc09712e5c020dfcc5f09df Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 14 Oct 2016 21:48:08 -0400 Subject: Fix occasionally stuck event queue --- src/server/PreProcessor.cpp | 21 +++++++++++++-------- src/server/PreProcessor.hpp | 1 - 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/server/PreProcessor.cpp b/src/server/PreProcessor.cpp index 1fd02cf3..c23c99d6 100644 --- a/src/server/PreProcessor.cpp +++ b/src/server/PreProcessor.cpp @@ -38,7 +38,6 @@ PreProcessor::PreProcessor(Engine& engine) : _engine(engine) , _sem(0) , _head(NULL) - , _prepared_back(NULL) , _tail(NULL) , _block_state(BlockState::UNBLOCKED) , _exit_flag(false) @@ -76,10 +75,6 @@ PreProcessor::event(Event* const ev, Event::Mode mode) _tail = ev; } - if (!_prepared_back.load()) { - _prepared_back = ev; - } - _sem.post(); } @@ -169,14 +164,24 @@ PreProcessor::run() _engine.world()->uri_map(), _engine.world()->uris(), redo_stack); ThreadManager::set_flag(THREAD_PRE_PROCESS); + + Event* back = NULL; while (!_exit_flag) { if (!_sem.timed_wait(1000)) { continue; } - Event* const ev = _prepared_back.load(); + if (!back) { + // Ran off end, find new unprepared back + back = _head; + while (back && back->is_prepared()) { + back = back->next(); + } + } + + Event* const ev = back; if (!ev) { - return; + continue; } assert(!ev->is_prepared()); @@ -214,7 +219,7 @@ PreProcessor::run() _block_state = BlockState::PRE_UNBLOCKED; } - _prepared_back = (Event*)ev->next(); + back = (Event*)ev->next(); } } diff --git a/src/server/PreProcessor.hpp b/src/server/PreProcessor.hpp index 5dc7bef0..61598ee0 100644 --- a/src/server/PreProcessor.hpp +++ b/src/server/PreProcessor.hpp @@ -69,7 +69,6 @@ private: std::mutex _mutex; Raul::Semaphore _sem; std::atomic _head; - std::atomic _prepared_back; std::atomic _tail; std::atomic _block_state; bool _exit_flag; -- cgit v1.2.1