summaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-02-04 00:54:25 +0000
committerDavid Robillard <d@drobilla.net>2013-02-04 00:54:25 +0000
commit46c3a486eee4b2ef69d9cc4f9e2701082c64d7c8 (patch)
treeecf7a89fb1c28a619106dd78ccd257a1ff52c70a /src/server
parent69f98d63f5bd22c82208fef5fbc2a61613541bd7 (diff)
downloadingen-46c3a486eee4b2ef69d9cc4f9e2701082c64d7c8.tar.gz
ingen-46c3a486eee4b2ef69d9cc4f9e2701082c64d7c8.tar.bz2
ingen-46c3a486eee4b2ef69d9cc4f9e2701082c64d7c8.zip
Replace Raul::thread with std::thread.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@5047 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/server')
-rw-r--r--src/server/Broadcaster.cpp11
-rw-r--r--src/server/Broadcaster.hpp7
-rw-r--r--src/server/BufferFactory.hpp6
-rw-r--r--src/server/Engine.cpp4
-rw-r--r--src/server/InternalPlugin.hpp6
-rw-r--r--src/server/PreProcessor.cpp17
-rw-r--r--src/server/PreProcessor.hpp18
-rw-r--r--src/server/ThreadManager.hpp2
-rw-r--r--src/server/Worker.cpp12
-rw-r--r--src/server/Worker.hpp9
-rw-r--r--src/server/ingen_lv2.cpp54
11 files changed, 63 insertions, 83 deletions
diff --git a/src/server/Broadcaster.cpp b/src/server/Broadcaster.cpp
index 8e53164f..fa8624df 100644
--- a/src/server/Broadcaster.cpp
+++ b/src/server/Broadcaster.cpp
@@ -15,7 +15,6 @@
*/
#include <utility>
-#include <glibmm/thread.h>
#include "ingen/Interface.hpp"
@@ -33,7 +32,7 @@ Broadcaster::Broadcaster()
Broadcaster::~Broadcaster()
{
- Glib::Mutex::Lock lock(_clients_mutex);
+ std::lock_guard<std::mutex> lock(_clients_mutex);
_clients.clear();
_broadcastees.clear();
}
@@ -44,7 +43,7 @@ void
Broadcaster::register_client(const Raul::URI& uri,
SPtr<Interface> client)
{
- Glib::Mutex::Lock lock(_clients_mutex);
+ std::lock_guard<std::mutex> lock(_clients_mutex);
_clients[uri] = client;
}
@@ -55,7 +54,7 @@ Broadcaster::register_client(const Raul::URI& uri,
bool
Broadcaster::unregister_client(const Raul::URI& uri)
{
- Glib::Mutex::Lock lock(_clients_mutex);
+ std::lock_guard<std::mutex> lock(_clients_mutex);
const size_t erased = _clients.erase(uri);
_broadcastees.erase(uri);
return (erased > 0);
@@ -78,7 +77,7 @@ Broadcaster::set_broadcast(const Raul::URI& client, bool broadcast)
SPtr<Interface>
Broadcaster::client(const Raul::URI& uri)
{
- Glib::Mutex::Lock lock(_clients_mutex);
+ std::lock_guard<std::mutex> lock(_clients_mutex);
Clients::iterator i = _clients.find(uri);
if (i != _clients.end()) {
return (*i).second;
@@ -90,7 +89,7 @@ Broadcaster::client(const Raul::URI& uri)
void
Broadcaster::send_plugins(const BlockFactory::Plugins& plugins)
{
- Glib::Mutex::Lock lock(_clients_mutex);
+ std::lock_guard<std::mutex> lock(_clients_mutex);
for (const auto& c : _clients) {
send_plugins_to(c.second.get(), plugins);
}
diff --git a/src/server/Broadcaster.hpp b/src/server/Broadcaster.hpp
index ba471bc2..3a7eaf44 100644
--- a/src/server/Broadcaster.hpp
+++ b/src/server/Broadcaster.hpp
@@ -20,11 +20,10 @@
#include <atomic>
#include <list>
#include <map>
+#include <mutex>
#include <set>
#include <string>
-#include <glibmm/thread.h>
-
#include "ingen/Interface.hpp"
#include "ingen/types.hpp"
@@ -85,7 +84,7 @@ public:
void send_plugins_to(Interface*, const BlockFactory::Plugins& plugin_list);
#define BROADCAST(msg, ...) \
- Glib::Mutex::Lock lock(_clients_mutex); \
+ std::lock_guard<std::mutex> lock(_clients_mutex); \
for (const auto& c : _clients) \
c.second->msg(__VA_ARGS__)
@@ -147,7 +146,7 @@ private:
typedef std::map< Raul::URI, SPtr<Interface> > Clients;
- Glib::Mutex _clients_mutex;
+ std::mutex _clients_mutex;
Clients _clients;
std::set<Raul::URI> _broadcastees;
std::atomic<bool> _must_broadcast;
diff --git a/src/server/BufferFactory.hpp b/src/server/BufferFactory.hpp
index fc9c5515..3bbc542e 100644
--- a/src/server/BufferFactory.hpp
+++ b/src/server/BufferFactory.hpp
@@ -19,9 +19,7 @@
#include <atomic>
#include <map>
-
-#undef nil
-#include <glibmm/thread.h>
+#include <mutex>
#include "ingen/Forge.hpp"
#include "ingen/URIs.hpp"
@@ -88,7 +86,7 @@ private:
std::atomic<Buffer*> _free_sequence;
std::atomic<Buffer*> _free_object;
- Glib::Mutex _mutex;
+ std::mutex _mutex;
Engine& _engine;
URIs& _uris;
uint32_t _seq_size;
diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp
index 3d76a032..ce253b75 100644
--- a/src/server/Engine.cpp
+++ b/src/server/Engine.cpp
@@ -192,8 +192,6 @@ Engine::activate()
_buffer_factory->set_block_length(_driver->block_length());
_options->set(*this);
- _pre_processor->start();
-
const Ingen::URIs& uris = world()->uris();
Forge& forge = world()->forge();
@@ -283,8 +281,6 @@ Engine::activate()
void
Engine::deactivate()
{
- _pre_processor->join();
-
if (_driver) {
_driver->deactivate();
}
diff --git a/src/server/InternalPlugin.hpp b/src/server/InternalPlugin.hpp
index 5bd842dd..fc5537bf 100644
--- a/src/server/InternalPlugin.hpp
+++ b/src/server/InternalPlugin.hpp
@@ -17,10 +17,8 @@
#ifndef INGEN_ENGINE_INTERNALPLUGIN_HPP
#define INGEN_ENGINE_INTERNALPLUGIN_HPP
-#include <cstdlib>
-
-#include <boost/utility.hpp>
-#include <glibmm/module.h>
+#include "raul/Symbol.hpp"
+#include "raul/URI.hpp"
#include "PluginImpl.hpp"
diff --git a/src/server/PreProcessor.cpp b/src/server/PreProcessor.cpp
index d62fdab3..83215bee 100644
--- a/src/server/PreProcessor.cpp
+++ b/src/server/PreProcessor.cpp
@@ -14,6 +14,9 @@
along with Ingen. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <stdexcept>
+#include <iostream>
+
#include "Event.hpp"
#include "PostProcessor.hpp"
#include "PreProcessor.hpp"
@@ -26,19 +29,19 @@ namespace Ingen {
namespace Server {
PreProcessor::PreProcessor()
- : Raul::Thread()
- , _sem(0)
+ : _sem(0)
, _head(NULL)
, _prepared_back(NULL)
, _tail(NULL)
-{
- start();
-}
+ , _exit_flag(false)
+ , _thread(&PreProcessor::run, this)
+{}
PreProcessor::~PreProcessor()
{
_exit_flag = true;
_sem.post();
+ _thread.join();
}
void
@@ -46,7 +49,7 @@ PreProcessor::event(Event* const ev)
{
// TODO: Probably possible to make this lock-free with CAS
ThreadManager::assert_not_thread(THREAD_IS_REAL_TIME);
- Glib::Mutex::Lock lock(_mutex);
+ std::lock_guard<std::mutex> lock(_mutex);
assert(!ev->is_prepared());
assert(!ev->next());
@@ -114,7 +117,7 @@ PreProcessor::process(ProcessContext& context, PostProcessor& dest, bool limit)
}
void
-PreProcessor::_run()
+PreProcessor::run()
{
ThreadManager::set_flag(THREAD_PRE_PROCESS);
while (_sem.wait() && !_exit_flag) {
diff --git a/src/server/PreProcessor.hpp b/src/server/PreProcessor.hpp
index 10563ee9..d8e71428 100644
--- a/src/server/PreProcessor.hpp
+++ b/src/server/PreProcessor.hpp
@@ -18,11 +18,10 @@
#define INGEN_ENGINE_PREPROCESSOR_HPP
#include <atomic>
-
-#include <glibmm/thread.h>
+#include <thread>
+#include <mutex>
#include "raul/Semaphore.hpp"
-#include "raul/Thread.hpp"
namespace Ingen {
namespace Server {
@@ -31,18 +30,13 @@ class Event;
class PostProcessor;
class ProcessContext;
-class PreProcessor : public Raul::Thread
+class PreProcessor
{
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.load(); }
@@ -59,14 +53,16 @@ public:
bool limit = true);
protected:
- virtual void _run();
+ void run();
private:
- Glib::Mutex _mutex;
+ std::mutex _mutex;
Raul::Semaphore _sem;
std::atomic<Event*> _head;
std::atomic<Event*> _prepared_back;
std::atomic<Event*> _tail;
+ bool _exit_flag;
+ std::thread _thread;
};
} // namespace Server
diff --git a/src/server/ThreadManager.hpp b/src/server/ThreadManager.hpp
index 445219ae..1fb1ca58 100644
--- a/src/server/ThreadManager.hpp
+++ b/src/server/ThreadManager.hpp
@@ -18,7 +18,7 @@
#define INGEN_ENGINE_THREADMANAGER_HPP
#include <cassert>
-#include "raul/Thread.hpp"
+
#include "raul/ThreadVar.hpp"
namespace Ingen {
diff --git a/src/server/Worker.cpp b/src/server/Worker.cpp
index 8afc8a20..ce7ba833 100644
--- a/src/server/Worker.cpp
+++ b/src/server/Worker.cpp
@@ -101,28 +101,26 @@ Worker::Schedule::feature(World* world, Node* n)
}
Worker::Worker(Log& log, uint32_t buffer_size)
- : Raul::Thread()
- , _schedule(new Schedule())
+ : _schedule(new Schedule())
, _log(log)
, _sem(0)
, _requests(buffer_size)
, _responses(buffer_size)
, _buffer((uint8_t*)malloc(buffer_size))
, _buffer_size(buffer_size)
-{
- start();
-}
+ , _thread(&Worker::run, this)
+{}
Worker::~Worker()
{
_exit_flag = true;
_sem.post();
- join();
+ _thread.join();
free(_buffer);
}
void
-Worker::_run()
+Worker::run()
{
while (_sem.wait() && !_exit_flag) {
MessageHeader msg;
diff --git a/src/server/Worker.hpp b/src/server/Worker.hpp
index b90e117e..d51c6559 100644
--- a/src/server/Worker.hpp
+++ b/src/server/Worker.hpp
@@ -17,11 +17,12 @@
#ifndef INGEN_ENGINE_WORKER_HPP
#define INGEN_ENGINE_WORKER_HPP
+#include <thread>
+
#include "ingen/LV2Features.hpp"
#include "lv2/lv2plug.in/ns/ext/worker/worker.h"
#include "raul/RingBuffer.hpp"
#include "raul/Semaphore.hpp"
-#include "raul/Thread.hpp"
namespace Ingen {
@@ -31,7 +32,7 @@ namespace Server {
class LV2Block;
-class Worker : public Raul::Thread
+class Worker
{
public:
Worker(Log& log, uint32_t buffer_size);
@@ -58,8 +59,10 @@ private:
Raul::RingBuffer _responses;
uint8_t* const _buffer;
const uint32_t _buffer_size;
+ bool _exit_flag;
+ std::thread _thread;
- virtual void _run();
+ void run();
};
} // namespace Server
diff --git a/src/server/ingen_lv2.cpp b/src/server/ingen_lv2.cpp
index e3bb240a..29d6d8c6 100644
--- a/src/server/ingen_lv2.cpp
+++ b/src/server/ingen_lv2.cpp
@@ -17,6 +17,7 @@
#include <stdlib.h>
#include <string>
+#include <thread>
#include <vector>
#include <glib.h>
@@ -44,7 +45,6 @@
#include "ingen/serialisation/Serialiser.hpp"
#include "ingen/types.hpp"
#include "raul/Semaphore.hpp"
-#include "raul/Thread.hpp"
#include "Buffer.hpp"
#include "Driver.hpp"
@@ -399,35 +399,22 @@ extern "C" {
using namespace Ingen;
using namespace Ingen::Server;
-class MainThread : public Raul::Thread
+static void
+ingen_lv2_main(SPtr<Engine> engine, LV2Driver* driver)
{
-public:
- explicit MainThread(SPtr<Engine> engine,
- LV2Driver* driver)
- : Raul::Thread()
- , _engine(engine)
- , _driver(driver)
- {}
+ while (true) {
+ // Wait until there is work to be done
+ driver->main_sem().wait();
-private:
- virtual void _run() {
- while (true) {
- // Wait until there is work to be done
- _driver->main_sem().wait();
+ // Convert pending messages to events and push to pre processor
+ driver->consume_from_ui();
- // Convert pending messages to events and push to pre processor
- _driver->consume_from_ui();
-
- // Run post processor and maid to finalise events from last time
- if (!_engine->main_iteration()) {
- return;
- }
+ // Run post processor and maid to finalise events from last time
+ if (!engine->main_iteration()) {
+ return;
}
}
-
- SPtr<Engine> _engine;
- LV2Driver* _driver;
-};
+}
struct IngenPlugin {
IngenPlugin()
@@ -439,7 +426,7 @@ struct IngenPlugin {
{}
Ingen::World* world;
- MainThread* main;
+ std::thread* main;
LV2_URID_Map* map;
int argc;
char** argv;
@@ -584,8 +571,6 @@ ingen_instantiate(const LV2_Descriptor* descriptor,
LV2Driver* driver = new LV2Driver(*engine.get(), block_length, rate);
engine->set_driver(SPtr<Ingen::Server::Driver>(driver));
- plugin->main = new MainThread(engine, driver);
-
engine->activate();
Server::ThreadManager::single_threaded = true;
@@ -632,10 +617,12 @@ ingen_connect_port(LV2_Handle instance, uint32_t port, void* data)
static void
ingen_activate(LV2_Handle instance)
{
- IngenPlugin* me = (IngenPlugin*)instance;
- me->world->engine()->activate();
- //((EventWriter*)me->world->engine().get())->start();
- me->main->start();
+ IngenPlugin* me = (IngenPlugin*)instance;
+ SPtr<Server::Engine> engine = dynamic_ptr_cast<Server::Engine>(
+ me->world->engine());
+ LV2Driver* driver = (LV2Driver*)engine->driver();
+ engine->activate();
+ me->main = new std::thread(ingen_lv2_main, engine, driver);
}
static void
@@ -656,6 +643,8 @@ ingen_deactivate(LV2_Handle instance)
{
IngenPlugin* me = (IngenPlugin*)instance;
me->world->engine()->deactivate();
+ delete me->main;
+ me->main = NULL;
}
static void
@@ -664,6 +653,7 @@ ingen_cleanup(LV2_Handle instance)
IngenPlugin* me = (IngenPlugin*)instance;
me->world->set_engine(SPtr<Ingen::Server::Engine>());
me->world->set_interface(SPtr<Ingen::Interface>());
+ delete me->main;
delete me->world;
delete me;
}