summaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Engine.cpp2
-rw-r--r--src/server/PreProcessor.cpp25
-rw-r--r--src/server/PreProcessor.hpp13
-rw-r--r--src/server/Worker.cpp3
4 files changed, 26 insertions, 17 deletions
diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp
index eeb28e5a..c7fef892 100644
--- a/src/server/Engine.cpp
+++ b/src/server/Engine.cpp
@@ -258,7 +258,7 @@ Engine::activate()
void
Engine::deactivate()
{
- _pre_processor->stop();
+ _pre_processor->join();
if (_driver) {
_driver->deactivate();
diff --git a/src/server/PreProcessor.cpp b/src/server/PreProcessor.cpp
index 9db13fd1..13746113 100644
--- a/src/server/PreProcessor.cpp
+++ b/src/server/PreProcessor.cpp
@@ -26,14 +26,14 @@ namespace Ingen {
namespace Server {
PreProcessor::PreProcessor()
- : Raul::Slave("PreProcessor")
+ : Raul::Thread("PreProcessor")
+ , _sem(0)
{
start();
}
PreProcessor::~PreProcessor()
{
- stop();
}
void
@@ -61,7 +61,7 @@ PreProcessor::event(Event* const ev)
_prepared_back = ev;
}
- whip();
+ _sem.post();
}
unsigned
@@ -110,18 +110,21 @@ PreProcessor::process(ProcessContext& context, PostProcessor& dest, bool limit)
/** Pre-process a single event */
void
-PreProcessor::_whipped()
+PreProcessor::_run()
{
ThreadManager::set_flag(THREAD_PRE_PROCESS);
- Event* ev = _prepared_back.get();
- if (!ev)
- return;
+ while (_sem.wait() && !_exit_flag) {
+ Event* const ev = _prepared_back.get();
+ if (!ev) {
+ return;
+ }
- assert(!ev->is_prepared());
- ev->pre_process();
- assert(ev->is_prepared());
+ assert(!ev->is_prepared());
+ ev->pre_process();
+ assert(ev->is_prepared());
- _prepared_back = (Event*)ev->next();
+ _prepared_back = (Event*)ev->next();
+ }
}
} // namespace Server
diff --git a/src/server/PreProcessor.hpp b/src/server/PreProcessor.hpp
index fd886139..9b7fbd44 100644
--- a/src/server/PreProcessor.hpp
+++ b/src/server/PreProcessor.hpp
@@ -20,7 +20,8 @@
#include <glibmm/thread.h>
#include "raul/AtomicPtr.hpp"
-#include "raul/Slave.hpp"
+#include "raul/Semaphore.hpp"
+#include "raul/Thread.hpp"
namespace Ingen {
namespace Server {
@@ -29,13 +30,18 @@ class Event;
class PostProcessor;
class ProcessContext;
-class PreProcessor : public Raul::Slave
+class PreProcessor : public Raul::Thread
{
public:
explicit PreProcessor();
~PreProcessor();
+ virtual void join() {
+ _exit_flag = true;
+ _sem.post();
+ }
+
/** Return true iff no events are enqueued. */
inline bool empty() const { return !_head.get(); }
@@ -52,10 +58,11 @@ public:
bool limit = true);
protected:
- virtual void _whipped(); ///< Prepare 1 event
+ virtual void _run();
private:
Glib::Mutex _mutex;
+ Raul::Semaphore _sem;
Raul::AtomicPtr<Event> _head;
Raul::AtomicPtr<Event> _prepared_back;
Raul::AtomicPtr<Event> _tail;
diff --git a/src/server/Worker.cpp b/src/server/Worker.cpp
index d17482bf..2c1c51a0 100644
--- a/src/server/Worker.cpp
+++ b/src/server/Worker.cpp
@@ -119,8 +119,7 @@ Worker::~Worker()
void
Worker::_run()
{
- while (!_exit_flag) {
- _sem.wait();
+ while (_sem.wait() && !_exit_flag) {
MessageHeader msg;
if (_requests.read_space() > sizeof(msg)) {
if (_requests.read(sizeof(msg), &msg) != sizeof(msg)) {