aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-09-29 12:01:58 +0200
committerDavid Robillard <d@drobilla.net>2018-11-10 11:45:15 +0100
commit10795f4e9262b7927ecdc845273888c37fbac685 (patch)
tree6d556946aa07fb7cce575caf01fd391297fc584d /src
parent67440e0cd7f68adc38c02a5ceaf54a180c74fa15 (diff)
downloadjalv-10795f4e9262b7927ecdc845273888c37fbac685.tar.gz
jalv-10795f4e9262b7927ecdc845273888c37fbac685.tar.bz2
jalv-10795f4e9262b7927ecdc845273888c37fbac685.zip
Move exit semaphore to Jalv struct
Diffstat (limited to 'src')
-rw-r--r--src/jack.c2
-rw-r--r--src/jalv.c22
-rw-r--r--src/jalv_console.c10
-rw-r--r--src/jalv_gtk.c2
-rw-r--r--src/jalv_gtkmm2.cpp2
-rw-r--r--src/jalv_internal.h2
-rw-r--r--src/jalv_qt.cpp2
7 files changed, 22 insertions, 20 deletions
diff --git a/src/jack.c b/src/jack.c
index f2ced50..28560d7 100644
--- a/src/jack.c
+++ b/src/jack.c
@@ -51,7 +51,7 @@ jack_shutdown_cb(void* data)
{
Jalv* const jalv = (Jalv*)data;
jalv_close_ui(jalv);
- zix_sem_post(jalv->done);
+ zix_sem_post(&jalv->done);
}
/** Jack process callback. */
diff --git a/src/jalv.c b/src/jalv.c
index 14a0988..b1cabfa 100644
--- a/src/jalv.c
+++ b/src/jalv.c
@@ -82,7 +82,7 @@
*/
#define N_BUFFER_CYCLES 16
-ZixSem exit_sem; /**< Exit semaphore */
+static ZixSem* exit_sem = NULL; /**< Exit semaphore used by signal handler*/
static LV2_URID
map_uri(LV2_URID_Map_Handle handle,
@@ -657,7 +657,7 @@ bool
jalv_update(Jalv* jalv)
{
/* Check quit flag and close if set. */
- if (zix_sem_try_wait(&exit_sem)) {
+ if (zix_sem_try_wait(&jalv->done)) {
jalv_close_ui(jalv);
return false;
}
@@ -725,12 +725,14 @@ jalv_apply_control_arg(Jalv* jalv, const char* s)
static void
signal_handler(ZIX_UNUSED int sig)
{
- zix_sem_post(&exit_sem);
+ zix_sem_post(exit_sem);
}
static void
-setup_signals(void)
+setup_signals(Jalv* const jalv)
{
+ exit_sem = &jalv->done;
+
#ifdef HAVE_SIGACTION
struct sigaction action;
sigemptyset(&action.sa_mask);
@@ -849,14 +851,11 @@ jalv_open(Jalv* const jalv, int argc, char** argv)
LV2_Log_Log llog = { jalv, jalv_printf, jalv_vprintf };
log_feature.data = &llog;
- zix_sem_init(&exit_sem, 0);
- jalv->done = &exit_sem;
+ zix_sem_init(&jalv->done, 0);
zix_sem_init(&jalv->paused, 0);
zix_sem_init(&jalv->worker.sem, 0);
- setup_signals();
-
/* Find all installed plugins */
LilvWorld* world = lilv_world_new();
lilv_world_load_all(world);
@@ -1193,7 +1192,7 @@ jalv_close(Jalv* const jalv)
lilv_uis_free(jalv->uis);
lilv_world_free(jalv->world);
- zix_sem_destroy(&exit_sem);
+ zix_sem_destroy(&jalv->done);
remove(jalv->temp_dir);
free(jalv->temp_dir);
@@ -1212,11 +1211,14 @@ main(int argc, char** argv)
return EXIT_FAILURE;
}
+ /* Set up signal handlers */
+ setup_signals(&jalv);
+
/* Run UI (or prompt at console) */
jalv_open_ui(&jalv);
/* Wait for finish signal from UI or signal handler */
- zix_sem_wait(jalv.done);
+ zix_sem_wait(&jalv.done);
return jalv_close(&jalv);
}
diff --git a/src/jalv_console.c b/src/jalv_console.c
index fb99a60..e12b050 100644
--- a/src/jalv_console.c
+++ b/src/jalv_console.c
@@ -245,7 +245,7 @@ jalv_run_custom_ui(Jalv* jalv)
show_iface->show(suil_instance_get_handle(jalv->ui_instance));
// Drive idle interface until interrupted
- while (!zix_sem_try_wait(jalv->done)) {
+ while (!zix_sem_try_wait(&jalv->done)) {
jalv_update(jalv);
if (idle_iface->idle(suil_instance_get_handle(jalv->ui_instance))) {
break;
@@ -266,7 +266,7 @@ jalv_open_ui(Jalv* jalv)
{
if (!jalv_run_custom_ui(jalv) && !jalv->opts.non_interactive) {
// Primitive command prompt for setting control values
- while (!zix_sem_try_wait(jalv->done)) {
+ while (!zix_sem_try_wait(&jalv->done)) {
char line[128];
printf("> ");
if (fgets(line, sizeof(line), stdin)) {
@@ -276,11 +276,11 @@ jalv_open_ui(Jalv* jalv)
}
}
} else {
- zix_sem_wait(jalv->done);
+ zix_sem_wait(&jalv->done);
}
// Caller waits on the done sem, so increment it again to exit
- zix_sem_post(jalv->done);
+ zix_sem_post(&jalv->done);
return 0;
}
@@ -288,6 +288,6 @@ jalv_open_ui(Jalv* jalv)
int
jalv_close_ui(Jalv* jalv)
{
- zix_sem_post(jalv->done);
+ zix_sem_post(&jalv->done);
return 0;
}
diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c
index f32c946..a27a8df 100644
--- a/src/jalv_gtk.c
+++ b/src/jalv_gtk.c
@@ -1227,7 +1227,7 @@ jalv_open_ui(Jalv* jalv)
gtk_main();
suil_instance_free(jalv->ui_instance);
jalv->ui_instance = NULL;
- zix_sem_post(jalv->done);
+ zix_sem_post(&jalv->done);
return 0;
}
diff --git a/src/jalv_gtkmm2.cpp b/src/jalv_gtkmm2.cpp
index 32a0264..ae0ac96 100644
--- a/src/jalv_gtkmm2.cpp
+++ b/src/jalv_gtkmm2.cpp
@@ -97,7 +97,7 @@ jalv_open_ui(Jalv* jalv)
delete window;
delete jalv_gtk_main;
- zix_sem_post(jalv->done);
+ zix_sem_post(&jalv->done);
return 0;
}
diff --git a/src/jalv_internal.h b/src/jalv_internal.h
index 6335f9e..a16868a 100644
--- a/src/jalv_internal.h
+++ b/src/jalv_internal.h
@@ -284,7 +284,7 @@ struct Jalv {
JalvWorker worker; ///< Worker thread implementation
JalvWorker state_worker; ///< Synchronous worker for state restore
ZixSem work_lock; ///< Lock for plugin work() method
- ZixSem* done; ///< Exit semaphore
+ ZixSem done; ///< Exit semaphore
ZixSem paused; ///< Paused signal from process thread
JalvPlayState play_state; ///< Current play state
char* temp_dir; ///< Temporary plugin state directory
diff --git a/src/jalv_qt.cpp b/src/jalv_qt.cpp
index ca19b92..aa6aea4 100644
--- a/src/jalv_qt.cpp
+++ b/src/jalv_qt.cpp
@@ -725,7 +725,7 @@ jalv_open_ui(Jalv* jalv)
timer->start(1000 / jalv->ui_update_hz);
int ret = app->exec();
- zix_sem_post(jalv->done);
+ zix_sem_post(&jalv->done);
return ret;
}