diff options
author | David Robillard <d@drobilla.net> | 2022-08-10 14:26:04 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-08-17 13:51:04 -0400 |
commit | cdfc39737361d4514fc7dfeb355d0eb011ade1bd (patch) | |
tree | 5d1c945347b97398c99ae8132fac1b888400bf04 /src | |
parent | 06b49a3419f35ee8c802f1f15b52cc45b546efb3 (diff) | |
download | jalv-cdfc39737361d4514fc7dfeb355d0eb011ade1bd.tar.gz jalv-cdfc39737361d4514fc7dfeb355d0eb011ade1bd.tar.bz2 jalv-cdfc39737361d4514fc7dfeb355d0eb011ade1bd.zip |
Factor out the concept of writing a "packet" in the worker
Diffstat (limited to 'src')
-rw-r--r-- | src/worker.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/worker.c b/src/worker.c index e0eb021..7f502e1 100644 --- a/src/worker.c +++ b/src/worker.c @@ -13,14 +13,19 @@ #include <stdlib.h> 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); |