From cdfc39737361d4514fc7dfeb355d0eb011ade1bd Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 10 Aug 2022 14:26:04 -0400 Subject: Factor out the concept of writing a "packet" in the worker --- src/worker.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/worker.c b/src/worker.c index e0eb021..7f502e1 100644 --- a/src/worker.c +++ b/src/worker.c @@ -12,15 +12,20 @@ #include #include +static LV2_Worker_Status +jalv_worker_write_packet(ZixRing* const target, uint32_t size, const void* data) +{ + zix_ring_write(target, (const char*)&size, sizeof(size)); + zix_ring_write(target, (const char*)data, size); + return LV2_WORKER_SUCCESS; +} + static LV2_Worker_Status jalv_worker_respond(LV2_Worker_Respond_Handle handle, uint32_t size, const void* data) { - JalvWorker* worker = (JalvWorker*)handle; - zix_ring_write(worker->responses, (const char*)&size, sizeof(size)); - zix_ring_write(worker->responses, (const char*)data, size); - return LV2_WORKER_SUCCESS; + return jalv_worker_write_packet(((JalvWorker*)handle)->responses, size, data); } static void* @@ -102,9 +107,10 @@ jalv_worker_schedule(LV2_Worker_Schedule_Handle handle, if (worker->threaded) { // Schedule a request to be executed by the worker thread - zix_ring_write(worker->requests, (const char*)&size, sizeof(size)); - zix_ring_write(worker->requests, (const char*)data, size); - zix_sem_post(&worker->sem); + if (!(st = jalv_worker_write_packet(worker->requests, size, data))) { + zix_sem_post(&worker->sem); + } + } else { // Execute work immediately in this thread zix_sem_wait(worker->lock); -- cgit v1.2.1