aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-11-17 23:11:42 +0000
committerDavid Robillard <d@drobilla.net>2012-11-17 23:11:42 +0000
commite5941f303a13dd1ec5659ad447d99fa522589cb8 (patch)
tree3a1aca905388f6051c9cc60db6927bb9ae137620 /src
parent797a9a172729e43c467ea6b2c84eb9d39035170e (diff)
downloadjalv-e5941f303a13dd1ec5659ad447d99fa522589cb8.tar.gz
jalv-e5941f303a13dd1ec5659ad447d99fa522589cb8.tar.bz2
jalv-e5941f303a13dd1ec5659ad447d99fa522589cb8.zip
Make URI map thread-safe, fixing occasional crashes for plugins with UIs.
git-svn-id: http://svn.drobilla.net/lad/trunk/jalv@4828 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/jalv.c22
-rw-r--r--src/jalv_internal.h3
2 files changed, 20 insertions, 5 deletions
diff --git a/src/jalv.c b/src/jalv.c
index 70e9028..d3d8c75 100644
--- a/src/jalv.c
+++ b/src/jalv.c
@@ -88,14 +88,22 @@ static LV2_URID
map_uri(LV2_URID_Map_Handle handle,
const char* uri)
{
- return symap_map(((Jalv*)handle)->symap, uri);
+ Jalv* jalv = (Jalv*)handle;
+ zix_sem_wait(&jalv->symap_lock);
+ const LV2_URID id = symap_map(jalv->symap, uri);
+ zix_sem_post(&jalv->symap_lock);
+ return id;
}
static const char*
unmap_uri(LV2_URID_Unmap_Handle handle,
LV2_URID urid)
{
- return symap_unmap(((Jalv*)handle)->symap, urid);
+ Jalv* jalv = (Jalv*)handle;
+ zix_sem_wait(&jalv->symap_lock);
+ const char* uri = symap_unmap(jalv->symap, urid);
+ zix_sem_post(&jalv->symap_lock);
+ return uri;
}
/**
@@ -106,7 +114,11 @@ uri_to_id(LV2_URI_Map_Callback_Data callback_data,
const char* map,
const char* uri)
{
- return symap_map(((Jalv*)callback_data)->symap, uri);
+ Jalv* jalv = (Jalv*)callback_data;
+ zix_sem_wait(&jalv->symap_lock);
+ const LV2_URID id = symap_map(jalv->symap, uri);
+ zix_sem_post(&jalv->symap_lock);
+ return id;
}
#define NS_EXT "http://lv2plug.in/ns/ext/"
@@ -677,7 +689,7 @@ jalv_ui_write(SuilController controller,
if (protocol != 0 && protocol != jalv->urids.atom_eventTransfer) {
fprintf(stderr, "UI write with unsupported protocol %d (%s)\n",
- protocol, symap_unmap(jalv->symap, protocol));
+ protocol, unmap_uri(jalv, protocol));
return;
}
@@ -766,6 +778,7 @@ main(int argc, char** argv)
}
jalv.symap = symap_new();
+ zix_sem_init(&jalv.symap_lock, 1);
uri_map.callback_data = &jalv;
jalv.map.handle = &jalv;
@@ -1096,6 +1109,7 @@ main(int argc, char** argv)
lilv_node_free(*n);
}
symap_free(jalv.symap);
+ zix_sem_destroy(&jalv.symap_lock);
suil_host_free(jalv.ui_host);
sratom_free(jalv.sratom);
lilv_uis_free(jalv.uis);
diff --git a/src/jalv_internal.h b/src/jalv_internal.h
index 3c66f68..76de642 100644
--- a/src/jalv_internal.h
+++ b/src/jalv_internal.h
@@ -153,7 +153,8 @@ typedef struct {
LV2_URID_Map map; ///< URI => Int map
LV2_URID_Unmap unmap; ///< Int => URI map
Sratom* sratom; ///< Atom serialiser
- Symap* symap; ///< Symbol (URI) map
+ Symap* symap; ///< URI map
+ ZixSem symap_lock; ///< Lock for URI map
jack_client_t* jack_client; ///< Jack client
jack_ringbuffer_t* ui_events; ///< Port events from UI
jack_ringbuffer_t* plugin_events; ///< Port events from plugin