summaryrefslogtreecommitdiffstats
path: root/src/server/Worker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Worker.cpp')
-rw-r--r--src/server/Worker.cpp39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/server/Worker.cpp b/src/server/Worker.cpp
index 68926278..cf252d37 100644
--- a/src/server/Worker.cpp
+++ b/src/server/Worker.cpp
@@ -21,18 +21,26 @@
#include "LV2Block.hpp"
#include "ingen/Log.hpp"
+#include "ingen/Node.hpp"
+#include "lv2/core/lv2.h"
#include "lv2/worker/worker.h"
+#include "raul/RingBuffer.hpp"
+#include "raul/Semaphore.hpp"
#include <cstdlib>
+#include <memory>
namespace ingen {
+
+class World;
+
namespace server {
/// A message in the Worker::_requests ring
struct MessageHeader {
- LV2Block* block; ///< Node this message is from
+ LV2Block* block; ///< Node this message is from
uint32_t size; ///< Size of following data
- // `size' bytes of data follow here
+ // `size' bytes of data follow here
};
static LV2_Worker_Status
@@ -40,8 +48,8 @@ schedule(LV2_Worker_Schedule_Handle handle,
uint32_t size,
const void* data)
{
- auto* block = (LV2Block*)handle;
- Engine& engine = block->parent_graph()->engine();
+ auto* block = static_cast<LV2Block*>(handle);
+ const Engine& engine = block->parent_graph()->engine();
return engine.worker()->request(block, size, data);
}
@@ -51,8 +59,8 @@ schedule_sync(LV2_Worker_Schedule_Handle handle,
uint32_t size,
const void* data)
{
- auto* block = (LV2Block*)handle;
- Engine& engine = block->parent_graph()->engine();
+ auto* block = static_cast<LV2Block*>(handle);
+ const Engine& engine = block->parent_graph()->engine();
return engine.sync_worker()->request(block, size, data);
}
@@ -66,7 +74,7 @@ Worker::request(LV2Block* block,
return block->work(size, data);
}
- Engine& engine = block->parent_graph()->engine();
+ const Engine& engine = block->parent_graph()->engine();
if (_requests.write_space() < sizeof(MessageHeader) + size) {
engine.log().error("Work request ring overflow\n");
return LV2_WORKER_ERR_NO_SPACE;
@@ -87,39 +95,38 @@ Worker::request(LV2Block* block,
return LV2_WORKER_SUCCESS;
}
-SPtr<LV2_Feature>
+std::shared_ptr<LV2_Feature>
Worker::Schedule::feature(World&, Node* n)
{
auto* block = dynamic_cast<LV2Block*>(n);
if (!block) {
- return SPtr<LV2_Feature>();
+ return nullptr;
}
- auto* data = (LV2_Worker_Schedule*)malloc(sizeof(LV2_Worker_Schedule));
+ auto* data = static_cast<LV2_Worker_Schedule*>(malloc(sizeof(LV2_Worker_Schedule)));
+
data->handle = block;
data->schedule_work = synchronous ? schedule_sync : schedule;
- auto* f = (LV2_Feature*)malloc(sizeof(LV2_Feature));
+ auto* f = static_cast<LV2_Feature*>(malloc(sizeof(LV2_Feature)));
f->URI = LV2_WORKER__schedule;
f->data = data;
- return SPtr<LV2_Feature>(f, &free_feature);
+ return {f, &free_feature};
}
Worker::Worker(Log& log, uint32_t buffer_size, bool synchronous)
: _schedule(new Schedule(synchronous))
, _log(log)
- , _sem(0)
, _requests(buffer_size)
, _responses(buffer_size)
- , _buffer((uint8_t*)malloc(buffer_size))
+ , _buffer(static_cast<uint8_t*>(malloc(buffer_size)))
, _buffer_size(buffer_size)
, _thread(nullptr)
- , _exit_flag(false)
, _synchronous(synchronous)
{
if (!synchronous) {
- _thread = make_unique<std::thread>(&Worker::run, this);
+ _thread = std::make_unique<std::thread>(&Worker::run, this);
}
}