projects
/
ardour.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
NO-OP: whitespace
[ardour.git]
/
libs
/
ardour
/
worker.cc
diff --git
a/libs/ardour/worker.cc
b/libs/ardour/worker.cc
index 9d6dd09b55f64af6190f50e75f5a68a79e56a1a0..dd8f9e354f066dfa6a236897c7eeeb41e3590c61 100644
(file)
--- a/
libs/ardour/worker.cc
+++ b/
libs/ardour/worker.cc
@@
-1,5
+1,5
@@
/*
/*
- Copyright (C) 2012 Paul Davis
+ Copyright (C) 2012
-2016
Paul Davis
Author: David Robillard
This program is free software; you can redistribute it and/or modify
Author: David Robillard
This program is free software; you can redistribute it and/or modify
@@
-22,31
+22,48
@@
#include "ardour/worker.h"
#include "pbd/error.h"
#include "ardour/worker.h"
#include "pbd/error.h"
+#include "pbd/compose.h"
#include <glibmm/timer.h>
namespace ARDOUR {
#include <glibmm/timer.h>
namespace ARDOUR {
-Worker::Worker(Workee* workee, uint32_t ring_size)
+Worker::Worker(Workee* workee, uint32_t ring_size
, bool threaded
)
: _workee(workee)
: _workee(workee)
- , _requests(
new RingBuffer<uint8_t>(ring_size)
)
- , _responses(new RingBuffer<uint8_t>(ring_size))
+ , _requests(
threaded ? new PBD::RingBuffer<uint8_t>(ring_size) : NULL
)
+ , _responses(new
PBD::
RingBuffer<uint8_t>(ring_size))
, _response((uint8_t*)malloc(ring_size))
, _response((uint8_t*)malloc(ring_size))
- , _sem ("worker_semaphore", 0)
+ , _sem(string_compose ("worker_semaphore%1", this).c_str(), 0)
+ , _thread(NULL)
, _exit(false)
, _exit(false)
- , _thread (Glib::Threads::Thread::create(sigc::mem_fun(*this, &Worker::run)))
-{}
+ , _synchronous(!threaded)
+{
+ if (threaded) {
+ _thread = Glib::Threads::Thread::create(
+ sigc::mem_fun(*this, &Worker::run));
+ }
+}
Worker::~Worker()
{
_exit = true;
_sem.signal();
Worker::~Worker()
{
_exit = true;
_sem.signal();
- _thread->join();
+ if (_thread) {
+ _thread->join();
+ }
+ delete _responses;
+ delete _requests;
+ free (_response);
}
bool
Worker::schedule(uint32_t size, const void* data)
{
}
bool
Worker::schedule(uint32_t size, const void* data)
{
+ if (_synchronous || !_requests) {
+ _workee->work(*this, size, data);
+ emit_responses ();
+ return true;
+ }
if (_requests->write_space() < size + sizeof(size)) {
return false;
}
if (_requests->write_space() < size + sizeof(size)) {
return false;
}
@@
-76,11
+93,11
@@
Worker::respond(uint32_t size, const void* data)
}
bool
}
bool
-Worker::verify_message_completeness(RingBuffer<uint8_t>* rb)
+Worker::verify_message_completeness(
PBD::
RingBuffer<uint8_t>* rb)
{
uint32_t read_space = rb->read_space();
uint32_t size;
{
uint32_t read_space = rb->read_space();
uint32_t size;
- RingBuffer<uint8_t>::rw_vector vec;
+
PBD::
RingBuffer<uint8_t>::rw_vector vec;
rb->get_read_vector (&vec);
if (vec.len[0] + vec.len[1] < sizeof(size)) {
return false;
rb->get_read_vector (&vec);
if (vec.len[0] + vec.len[1] < sizeof(size)) {
return false;
@@
-124,7
+141,7
@@
Worker::run()
while (true) {
_sem.wait();
if (_exit) {
while (true) {
_sem.wait();
if (_exit) {
-
if (buf)
free(buf);
+ free(buf);
return;
}
return;
}
@@
-163,7
+180,7
@@
Worker::run()
continue; // TODO: This is probably fatal
}
continue; // TODO: This is probably fatal
}
- _workee->work(size, buf);
+ _workee->work(
*this,
size, buf);
}
}
}
}