projects
/
ardour.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix crash when copy'ing latent plugins
[ardour.git]
/
libs
/
ardour
/
worker.cc
diff --git
a/libs/ardour/worker.cc
b/libs/ardour/worker.cc
index d5238adb60e49377e95810c5b3e1451b28e688a6..f8a5e44aee06294c0c354e5d85bf110715a05270 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
@@
-27,26
+27,38
@@
namespace ARDOUR {
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)
)
+ , _requests(
threaded ? new RingBuffer<uint8_t>(ring_size) : NULL
)
, _responses(new RingBuffer<uint8_t>(ring_size))
, _response((uint8_t*)malloc(ring_size))
, _responses(new RingBuffer<uint8_t>(ring_size))
, _response((uint8_t*)malloc(ring_size))
- , _sem(0)
+ , _sem("worker_semaphore", 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;
Worker::~Worker()
{
_exit = true;
- _sem.post();
- _thread->join();
+ _sem.signal();
+ if (_thread) {
+ _thread->join();
+ }
}
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);
+ return true;
+ }
if (_requests->write_space() < size + sizeof(size)) {
return false;
}
if (_requests->write_space() < size + sizeof(size)) {
return false;
}
@@
-56,14
+68,14
@@
Worker::schedule(uint32_t size, const void* data)
if (_requests->write((const uint8_t*)data, size) != size) {
return false;
}
if (_requests->write((const uint8_t*)data, size) != size) {
return false;
}
- _sem.
post
();
+ _sem.
signal
();
return true;
}
bool
Worker::respond(uint32_t size, const void* data)
{
return true;
}
bool
Worker::respond(uint32_t size, const void* data)
{
- if (_re
quest
s->write_space() < size + sizeof(size)) {
+ if (_re
sponse
s->write_space() < size + sizeof(size)) {
return false;
}
if (_responses->write((const uint8_t*)&size, sizeof(size)) != sizeof(size)) {
return false;
}
if (_responses->write((const uint8_t*)&size, sizeof(size)) != sizeof(size)) {
@@
-82,6
+94,9
@@
Worker::verify_message_completeness(RingBuffer<uint8_t>* rb)
uint32_t size;
RingBuffer<uint8_t>::rw_vector vec;
rb->get_read_vector (&vec);
uint32_t size;
RingBuffer<uint8_t>::rw_vector vec;
rb->get_read_vector (&vec);
+ if (vec.len[0] + vec.len[1] < sizeof(size)) {
+ return false;
+ }
if (vec.len[0] >= sizeof(size)) {
memcpy (&size, vec.buf[0], sizeof (size));
} else {
if (vec.len[0] >= sizeof(size)) {
memcpy (&size, vec.buf[0], sizeof (size));
} else {
@@
-121,6
+136,7
@@
Worker::run()
while (true) {
_sem.wait();
if (_exit) {
while (true) {
_sem.wait();
if (_exit) {
+ free(buf);
return;
}
return;
}
@@
-132,6
+148,7
@@
Worker::run()
while (!verify_message_completeness(_requests)) {
Glib::usleep(2000);
if (_exit) {
while (!verify_message_completeness(_requests)) {
Glib::usleep(2000);
if (_exit) {
+ if (buf) free(buf);
return;
}
}
return;
}
}
@@
-143,7
+160,13
@@
Worker::run()
if (size > buf_size) {
buf = realloc(buf, size);
if (size > buf_size) {
buf = realloc(buf, size);
- buf_size = size;
+ if (buf) {
+ buf_size = size;
+ } else {
+ PBD::error << "Worker: Error allocating memory"
+ << endmsg;
+ buf_size = 0; // TODO: This is probably fatal
+ }
}
if (_requests->read((uint8_t*)buf, size) < size) {
}
if (_requests->read((uint8_t*)buf, size) < size) {
@@
-152,7
+175,7
@@
Worker::run()
continue; // TODO: This is probably fatal
}
continue; // TODO: This is probably fatal
}
- _workee->work(size, buf);
+ _workee->work(
*this,
size, buf);
}
}
}
}