diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ingen/main.cpp | 3 | ||||
-rw-r--r-- | src/server/Engine.cpp | 13 | ||||
-rw-r--r-- | src/server/PreProcessor.cpp | 17 | ||||
-rw-r--r-- | src/server/PreProcessor.hpp | 2 |
4 files changed, 18 insertions, 17 deletions
diff --git a/src/ingen/main.cpp b/src/ingen/main.cpp index 86f38119..15cb5f83 100644 --- a/src/ingen/main.cpp +++ b/src/ingen/main.cpp @@ -204,6 +204,9 @@ main(int argc, char** argv) } } + // Sleep for a second to allow event queues to drain + Glib::usleep(1000000); + // Shut down if (world->engine()) world->engine()->deactivate(); diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp index 922935c9..4c258d54 100644 --- a/src/server/Engine.cpp +++ b/src/server/Engine.cpp @@ -100,9 +100,10 @@ Engine::~Engine() // Process all pending events const FrameTime end = std::numeric_limits<FrameTime>::max(); _process_context.locate(_process_context.end(), end - _process_context.end()); + _post_processor->set_end_time(end); + _post_processor->process(); while (!_pre_processor->empty()) { - _post_processor->set_end_time(end); - _pre_processor->process(_process_context, *_post_processor, false); + _pre_processor->process(_process_context, *_post_processor, 1); _post_processor->process(); } @@ -356,15 +357,15 @@ Engine::pending_events() void Engine::enqueue_event(Event* ev) { - if (!_quit_flag) { - _pre_processor->event(ev); - } + _pre_processor->event(ev); } unsigned Engine::process_events() { - return _pre_processor->process(_process_context, *_post_processor); + const size_t MAX_EVENTS_PER_CYCLE = 4;//_process_context.nframes() / 4; + return _pre_processor->process( + _process_context, *_post_processor, MAX_EVENTS_PER_CYCLE); } void diff --git a/src/server/PreProcessor.cpp b/src/server/PreProcessor.cpp index 83215bee..aa4f0b06 100644 --- a/src/server/PreProcessor.cpp +++ b/src/server/PreProcessor.cpp @@ -39,9 +39,11 @@ PreProcessor::PreProcessor() PreProcessor::~PreProcessor() { - _exit_flag = true; - _sem.post(); - _thread.join(); + if (_thread.joinable()) { + _exit_flag = true; + _sem.post(); + _thread.join(); + } } void @@ -71,18 +73,13 @@ PreProcessor::event(Event* const ev) } unsigned -PreProcessor::process(ProcessContext& context, PostProcessor& dest, bool limit) +PreProcessor::process(ProcessContext& context, PostProcessor& dest, size_t limit) { Event* const head = _head.load(); if (!head) { return 0; } - /* Limit the maximum number of events to process each cycle to ensure the - process callback is real-time safe. TODO: Parameterize this and/or - figure out a good default value. */ - const size_t MAX_EVENTS_PER_CYCLE = context.nframes() / 4; - size_t n_processed = 0; Event* ev = head; Event* last = ev; @@ -95,7 +92,7 @@ PreProcessor::process(ProcessContext& context, PostProcessor& dest, bool limit) last = ev; ev = ev->next(); ++n_processed; - if (limit && (n_processed > MAX_EVENTS_PER_CYCLE)) { + if (limit && n_processed >= limit) { break; } } diff --git a/src/server/PreProcessor.hpp b/src/server/PreProcessor.hpp index d8e71428..26f74d78 100644 --- a/src/server/PreProcessor.hpp +++ b/src/server/PreProcessor.hpp @@ -50,7 +50,7 @@ public: */ unsigned process(ProcessContext& context, PostProcessor& dest, - bool limit = true); + size_t limit = 0); protected: void run(); |