aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2019-08-01 11:08:44 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2019-08-01 11:08:44 +0200
commit550c91803e18de6ba8ce3c48b5ce67d33d6f4d15 (patch)
tree787b6d64a442dd125b6ab03c141e881650cd8fa7
parent1fb6c85cdcd3fdd35198f85218a479bbe508c650 (diff)
downloadsynthpod-550c91803e18de6ba8ce3c48b5ce67d33d6f4d15.tar.xz
sbox: wait for slave init before sending events.
-rw-r--r--sandbox_ui.lv2/sandbox_io.h21
-rw-r--r--sandbox_ui.lv2/sandbox_slave.c4
2 files changed, 25 insertions, 0 deletions
diff --git a/sandbox_ui.lv2/sandbox_io.h b/sandbox_ui.lv2/sandbox_io.h
index ebd8bb8b..e9b5e574 100644
--- a/sandbox_ui.lv2/sandbox_io.h
+++ b/sandbox_ui.lv2/sandbox_io.h
@@ -65,6 +65,7 @@ struct _sandbox_io_shm_body_t {
struct _sandbox_io_shm_t {
atomic_size_t minimum;
+ atomic_bool connected;
};
struct _sandbox_io_t {
@@ -243,6 +244,18 @@ _sandbox_io_recv(sandbox_io_t *io, _sandbox_io_recv_cb_t recv_cb,
return 0;
}
+static inline void
+_sandbox_io_connected_set(sandbox_io_t *io, bool connected)
+{
+ atomic_store_explicit(&io->shm->connected, connected, memory_order_release);
+}
+
+static inline bool
+_sandbox_io_connected_get(sandbox_io_t *io)
+{
+ return atomic_load_explicit(&io->shm->connected, memory_order_acquire);
+}
+
static inline int
_sandbox_io_send(sandbox_io_t *io, uint32_t index,
uint32_t size, uint32_t protocol, const void *buf)
@@ -251,6 +264,12 @@ _sandbox_io_send(sandbox_io_t *io, uint32_t index,
? io->from_master
: io->to_master;
+ // check connection status to slave
+ if(io->is_master && !_sandbox_io_connected_get(io))
+ {
+ return 0; // success
+ }
+
// reserve additional bytes for the parent atom and dictionary
const size_t add_sz = sizeof(LV2_Atom_Object) + 3*(sizeof(LV2_Atom_Property) + sizeof(LV2_Atom_Int));
const size_t dict_sz = 1024; //FIXME how big ?
@@ -484,6 +503,8 @@ _sandbox_io_init(sandbox_io_t *io, LV2_URID_Map *map, LV2_URID_Unmap *unmap,
varchunk_init(&io->from_master->varchunk, minimum, true);
varchunk_init(&io->to_master->varchunk, minimum, true);
+
+ atomic_init(&io->shm->connected, false);
}
lv2_atom_forge_init(&io->forge, map);
diff --git a/sandbox_ui.lv2/sandbox_slave.c b/sandbox_ui.lv2/sandbox_slave.c
index 90b72c9f..4b0e601f 100644
--- a/sandbox_ui.lv2/sandbox_slave.c
+++ b/sandbox_ui.lv2/sandbox_slave.c
@@ -603,6 +603,8 @@ sandbox_slave_new(int argc, char **argv, const sandbox_slave_driver_t *driver,
goto fail;
}
+ _sandbox_io_connected_set(&sb->io, true);
+
sb->initialized = true;
*res = EXIT_SUCCESS;
return sb; // success
@@ -619,6 +621,8 @@ sandbox_slave_free(sandbox_slave_t *sb)
if(!sb)
return;
+ _sandbox_io_connected_set(&sb->io, false);
+
xpress_deinit(&sb->xpress);
if(sb->desc && sb->desc->cleanup && sb->handle)