From 218589a6dad6decf6f5998068ff723b69854db0a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 30 May 2022 19:41:47 -0400 Subject: Remove Jalv back pointer from Worker --- src/jalv.c | 15 +++++++++++---- src/jalv_internal.h | 4 +++- src/worker.c | 21 ++++++++------------- src/worker.h | 3 +-- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/jalv.c b/src/jalv.c index ac4f9a9..dd9e66b 100644 --- a/src/jalv.c +++ b/src/jalv.c @@ -852,8 +852,10 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) jalv->map.map = map_uri; init_feature(&jalv->features.map_feature, LV2_URID__map, &jalv->map); - jalv->worker.jalv = jalv; - jalv->state_worker.jalv = jalv; + jalv->worker.lock = &jalv->work_lock; + jalv->worker.exit = &jalv->exit; + jalv->state_worker.lock = &jalv->work_lock; + jalv->state_worker.exit = &jalv->exit; jalv->unmap.handle = jalv; jalv->unmap.unmap = unmap_uri; @@ -1243,9 +1245,14 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) return -9; } + // Point things to the instance that require it + jalv->features.ext_data.data_access = lilv_instance_get_descriptor(jalv->instance)->extension_data; + jalv->worker.handle = jalv->instance->lv2_handle; + jalv->state_worker.handle = jalv->instance->lv2_handle; + fprintf(stderr, "\n"); if (!jalv->buf_size_set) { jalv_allocate_port_buffers(jalv); @@ -1258,9 +1265,9 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) (const LV2_Worker_Interface*)lilv_instance_get_extension_data( jalv->instance, LV2_WORKER__interface); - jalv_worker_init(jalv, &jalv->worker, iface, true); + jalv_worker_init(&jalv->worker, iface, true); if (jalv->safe_restore) { - jalv_worker_init(jalv, &jalv->state_worker, iface, false); + jalv_worker_init(&jalv->state_worker, iface, false); } } diff --git a/src/jalv_internal.h b/src/jalv_internal.h index 0224651..11bf05e 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -55,12 +55,14 @@ typedef struct Jalv Jalv; typedef enum { JALV_RUNNING, JALV_PAUSE_REQUESTED, JALV_PAUSED } JalvPlayState; typedef struct { - Jalv* jalv; ///< Pointer back to Jalv ZixRing* requests; ///< Requests to the worker ZixRing* responses; ///< Responses from the worker void* response; ///< Worker response buffer + ZixSem* lock; ///< Lock for plugin work() method + bool* exit; ///< Pointer to exit flag ZixSem sem; ///< Worker semaphore ZixThread thread; ///< Worker thread + LV2_Handle handle; ///< Plugin handle const LV2_Worker_Interface* iface; ///< Plugin worker interface bool threaded; ///< Run work in another thread } JalvWorker; diff --git a/src/worker.c b/src/worker.c index 0242ed4..e7dfa87 100644 --- a/src/worker.c +++ b/src/worker.c @@ -4,7 +4,6 @@ #include "worker.h" #include "lv2/worker/worker.h" -#include "zix/common.h" #include "zix/ring.h" #include "zix/sem.h" #include "zix/thread.h" @@ -27,11 +26,10 @@ static void* worker_func(void* data) { JalvWorker* worker = (JalvWorker*)data; - Jalv* jalv = worker->jalv; void* buf = NULL; while (true) { zix_sem_wait(&worker->sem); - if (jalv->exit) { + if (*worker->exit) { break; } @@ -46,10 +44,9 @@ worker_func(void* data) zix_ring_read(worker->requests, (char*)buf, size); - zix_sem_wait(&jalv->work_lock); - worker->iface->work( - jalv->instance->lv2_handle, jalv_worker_respond, worker, size, buf); - zix_sem_post(&jalv->work_lock); + zix_sem_wait(worker->lock); + worker->iface->work(worker->handle, jalv_worker_respond, worker, size, buf); + zix_sem_post(worker->lock); } free(buf); @@ -57,8 +54,7 @@ worker_func(void* data) } void -jalv_worker_init(Jalv* ZIX_UNUSED(jalv), - JalvWorker* worker, +jalv_worker_init(JalvWorker* worker, const LV2_Worker_Interface* iface, bool threaded) { @@ -101,7 +97,6 @@ jalv_worker_schedule(LV2_Worker_Schedule_Handle handle, const void* data) { JalvWorker* worker = (JalvWorker*)handle; - Jalv* jalv = worker->jalv; if (!size) { return LV2_WORKER_ERR_UNKNOWN; @@ -114,10 +109,10 @@ jalv_worker_schedule(LV2_Worker_Schedule_Handle handle, zix_sem_post(&worker->sem); } else { // Execute work immediately in this thread - zix_sem_wait(&jalv->work_lock); + zix_sem_wait(worker->lock); worker->iface->work( - jalv->instance->lv2_handle, jalv_worker_respond, worker, size, data); - zix_sem_post(&jalv->work_lock); + worker->handle, jalv_worker_respond, worker, size, data); + zix_sem_post(worker->lock); } return LV2_WORKER_SUCCESS; diff --git a/src/worker.h b/src/worker.h index 28a40eb..e3adeec 100644 --- a/src/worker.h +++ b/src/worker.h @@ -10,8 +10,7 @@ #include void -jalv_worker_init(Jalv* jalv, - JalvWorker* worker, +jalv_worker_init(JalvWorker* worker, const LV2_Worker_Interface* iface, bool threaded); -- cgit v1.2.1