diff options
author | David Robillard <d@drobilla.net> | 2007-07-25 05:01:28 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-07-25 05:01:28 +0000 |
commit | 9f43f23510ba2acd8e03f2822d87c74a8774b9d6 (patch) | |
tree | fc29ca27803d92e78f3cfdf9838896351c21c052 /src/world.c | |
parent | 092c9d03af043af4bad2d2402ee9c75d68dca67a (diff) | |
download | lilv-9f43f23510ba2acd8e03f2822d87c74a8774b9d6.tar.gz lilv-9f43f23510ba2acd8e03f2822d87c74a8774b9d6.tar.bz2 lilv-9f43f23510ba2acd8e03f2822d87c74a8774b9d6.zip |
Start work on lock stuff, for threadsafe SLV2 and using SLV2 with apps that use Redland themselves.
git-svn-id: http://svn.drobilla.net/lad/slv2@621 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/world.c')
-rw-r--r-- | src/world.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/src/world.c b/src/world.c index 898ab5a..d3776e5 100644 --- a/src/world.c +++ b/src/world.c @@ -67,6 +67,11 @@ slv2_world_new() world->rdf_a_node = librdf_new_node_from_uri_string(world->world, (unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); + + world->rdf_lock = NULL; + world->rdf_unlock = NULL; + world->rdf_lock_data = NULL; + world->rdf_lock_count = 0; return world; @@ -110,6 +115,11 @@ slv2_world_new_using_rdf_world(librdf_world* rdf_world) world->rdf_a_node = librdf_new_node_from_uri_string(rdf_world, (unsigned char*)"http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); + + world->rdf_lock = NULL; + world->rdf_unlock = NULL; + world->rdf_lock_data = NULL; + world->rdf_lock_count = 0; return world; @@ -122,6 +132,9 @@ fail: void slv2_world_free(SLV2World world) { + if (world->rdf_lock) + world->rdf_lock(world->rdf_lock_data); + librdf_free_node(world->lv2_plugin_node); librdf_free_node(world->rdf_a_node); @@ -144,14 +157,62 @@ slv2_world_free(SLV2World world) librdf_free_world(world->world); world->world = NULL; + + if (world->rdf_unlock) + world->rdf_unlock(world->rdf_lock_data); free(world); } void +slv2_world_set_rdf_lock_function(SLV2World world, void (*lock)(void*), void* data) +{ + world->rdf_lock = lock; + world->rdf_lock_data = data; +} + + +void +slv2_world_set_rdf_unlock_function(SLV2World world, void (*unlock)(void*)) +{ + world->rdf_unlock = unlock; +} + + +void +slv2_world_lock_if_necessary(SLV2World world) +{ + if (world->rdf_lock) { + + if (world->rdf_lock_count == 0) + world->rdf_lock(world->rdf_lock_data); + + ++world->rdf_lock_count; + + } +} + + +void +slv2_world_unlock_if_necessary(SLV2World world) +{ + if (world->rdf_lock && world->rdf_lock_count > 0) { + + if (world->rdf_lock_count == 1 && world->rdf_unlock) + world->rdf_unlock(world->rdf_lock_data); + + world->rdf_lock_count = 0; + + } +} + + +void slv2_world_load_bundle(SLV2World world, const char* bundle_uri_str) { + slv2_world_lock_if_necessary(world); + librdf_uri* bundle_uri = librdf_new_uri(world->world, (const unsigned char*)bundle_uri_str); @@ -209,6 +270,8 @@ slv2_world_load_bundle(SLV2World world, const char* bundle_uri_str) librdf_free_storage(manifest_storage); librdf_free_uri(manifest_uri); librdf_free_uri(bundle_uri); + + slv2_world_unlock_if_necessary(world); } |