summaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-08-16 00:59:35 +0000
committerDavid Robillard <d@drobilla.net>2012-08-16 00:59:35 +0000
commitda4c1fcad194f4f3f399f6a4a731df34567c95ef (patch)
tree22c875232a4639f0f80d818e3a399e16c4ffe6ad /src/server
parentd64815e24c043ac87b1504c5f02e93b11c4d8285 (diff)
downloadingen-da4c1fcad194f4f3f399f6a4a731df34567c95ef.tar.gz
ingen-da4c1fcad194f4f3f399f6a4a731df34567c95ef.tar.bz2
ingen-da4c1fcad194f4f3f399f6a4a731df34567c95ef.zip
Remove Raul::Slave class.
Merge Thread::stop() and Thread::join(). Clean thread shut down without the use of pthread_cancel(). git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4708 a436a847-0d15-0410-975c-d299462d15a1
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)) {