aboutsummaryrefslogtreecommitdiff
path: root/src/backend_librsvg.c
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2019-02-04 02:34:46 +0000
committerHarry Jeffery <harry@exec64.co.uk>2019-02-04 03:48:03 +0000
commit05db4c452cbf6d314be60b86524629ef22798adf (patch)
treeaf4830b00a8ccfd70a9d5563ef0534924da080ca /src/backend_librsvg.c
parent09928120e31edbfa63791f0c2f5e14374ae518de (diff)
downloadimv-05db4c452cbf6d314be60b86524629ef22798adf.tar.gz
Make sources thread-safe
Diffstat (limited to 'src/backend_librsvg.c')
-rw-r--r--src/backend_librsvg.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/backend_librsvg.c b/src/backend_librsvg.c
index 083fb9c..c9a91ff 100644
--- a/src/backend_librsvg.c
+++ b/src/backend_librsvg.c
@@ -21,6 +21,7 @@ struct private {
static void source_free(struct imv_source *src)
{
+ pthread_mutex_lock(&src->busy);
free(src->name);
src->name = NULL;
@@ -28,6 +29,8 @@ static void source_free(struct imv_source *src)
free(private);
src->private = NULL;
+ pthread_mutex_unlock(&src->busy);
+ pthread_mutex_destroy(&src->busy);
free(src);
}
@@ -57,6 +60,7 @@ static void report_error(struct imv_source *src)
msg.bitmap = NULL;
msg.error = "Internal error";
+ pthread_mutex_unlock(&src->busy);
src->callback(&msg);
}
@@ -76,11 +80,17 @@ static void send_bitmap(struct imv_source *src, GdkPixbuf *bitmap)
msg.frametime = 0;
msg.error = NULL;
+ pthread_mutex_unlock(&src->busy);
src->callback(&msg);
}
-static void load_image(struct imv_source *src)
+static int load_image(struct imv_source *src)
{
+ /* Don't run if this source is already active */
+ if (pthread_mutex_trylock(&src->busy)) {
+ return -1;
+ }
+
RsvgHandle *handle = NULL;
GError *error = NULL;
@@ -95,7 +105,7 @@ static void load_image(struct imv_source *src)
if (!handle) {
report_error(src);
- return;
+ return -1;
}
RsvgDimensionData dim;
@@ -107,11 +117,12 @@ static void load_image(struct imv_source *src)
if (!buf) {
rsvg_handle_close(handle, &error);
report_error(src);
- return;
+ return -1;
}
rsvg_handle_close(handle, &error);
send_bitmap(src, buf);
+ return 0;
}
static enum backend_result open_path(const char *path, struct imv_source **src)
@@ -141,6 +152,7 @@ static enum backend_result open_path(const char *path, struct imv_source **src)
source->height = 1024;
source->num_frames = 1;
source->next_frame = 1;
+ pthread_mutex_init(&source->busy, NULL);
source->load_first_frame = &load_image;
source->load_next_frame = NULL;
source->free = &source_free;
@@ -173,6 +185,7 @@ static enum backend_result open_memory(void *data, size_t len, struct imv_source
source->height = 1024;
source->num_frames = 1;
source->next_frame = 1;
+ pthread_mutex_init(&source->busy, NULL);
source->load_first_frame = &load_image;
source->load_next_frame = NULL;
source->free = &source_free;