From: Mike Brady Date: Fri, 9 Mar 2018 16:26:09 +0000 (+0000) Subject: Add a prolog and epilog for safe reading of the metadata bundle X-Git-Tag: 3.2d29~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7fa1d3cbeeb702cf811a07c40a3b711fdb086395;p=thirdparty%2Fshairport-sync.git Add a prolog and epilog for safe reading of the metadata bundle --- diff --git a/metadata_hub.c b/metadata_hub.c index af335e52..a9ba715c 100644 --- a/metadata_hub.c +++ b/metadata_hub.c @@ -130,6 +130,18 @@ void metadata_hub_modify_epilog(int modified) { } } +void metadata_hub_read_prolog(void) { + // always run this before reading an entry or a sequence of entries in the metadata_hub + // debug(1, "locking metadata hub for reading"); + pthread_rwlock_rdlock(&metadata_hub_re_lock); +} + +void metadata_hub_read_epilog(void) { + // always run this after reading an entry or a sequence of entries in the metadata_hub + // debug(1, "unlocking metadata hub for reading"); + pthread_rwlock_unlock(&metadata_hub_re_lock); +} + char *metadata_write_image_file(const char *buf, int len) { // warning -- this removes all files from the directory apart from this one, if it exists diff --git a/metadata_hub.h b/metadata_hub.h index 25f16bc6..8c3606b9 100644 --- a/metadata_hub.h +++ b/metadata_hub.h @@ -87,7 +87,7 @@ typedef struct metadata_bundle { int speaker_volume; // this is the actual speaker volume, allowing for the main volume and the // speaker volume control - int previous_speaker_volume; // this is needed to prevent a loop + // int previous_speaker_volume; // this is needed to prevent a loop metadata_watcher watchers[number_of_watchers]; // functions to call if the metadata is changed. void *watchers_data[number_of_watchers]; // their individual data @@ -107,3 +107,7 @@ void metadata_hub_release_track_artwork(void); // afterwards void metadata_hub_modify_prolog(void); void metadata_hub_modify_epilog(int modified); // set to true if modifications occured, 0 otherwise + +// these are for safe reading +void metadata_hub_read_prolog(void); +void metadata_hub_read_epilog(void);