aboutsummaryrefslogtreecommitdiff
path: root/src/imv.c
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2019-02-04 03:53:36 +0000
committerHarry Jeffery <harry@exec64.co.uk>2019-02-04 03:53:36 +0000
commitf57d0adaec789dbbfcca6b8bf4ddf51ac76ec9b3 (patch)
tree524117874d53f116d699ed9c75fd41ec68b7df23 /src/imv.c
parent05db4c452cbf6d314be60b86524629ef22798adf (diff)
downloadimv-f57d0adaec789dbbfcca6b8bf4ddf51ac76ec9b3.tar.gz
Run sources in background threads
Diffstat (limited to 'src/imv.c')
-rw-r--r--src/imv.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/imv.c b/src/imv.c
index eaed73f..60954fe 100644
--- a/src/imv.c
+++ b/src/imv.c
@@ -225,6 +225,38 @@ static bool add_bind(struct imv *imv, const char *keys, const char *commands)
return success;
}
+static int async_free_source_thread(void *raw)
+{
+ struct imv_source *src = raw;
+ src->free(src);
+ return 0;
+}
+
+static void async_free_source(struct imv_source *src)
+{
+ SDL_Thread *thread = SDL_CreateThread(async_free_source_thread,
+ "async_free_source", src);
+ SDL_DetachThread(thread);
+}
+
+static void async_load_first_frame(struct imv_source *src)
+{
+ typedef int (*thread_func)(void*);
+ SDL_Thread *thread = SDL_CreateThread((thread_func)src->load_first_frame,
+ "async_load_first_frame",
+ src);
+ SDL_DetachThread(thread);
+}
+
+static void async_load_next_frame(struct imv_source *src)
+{
+ typedef int (*thread_func)(void*);
+ SDL_Thread *thread = SDL_CreateThread((thread_func)src->load_next_frame,
+ "async_load_next_frame",
+ src);
+ SDL_DetachThread(thread);
+}
+
static void source_callback(struct imv_source_message *msg)
{
struct imv *imv = msg->user_data;
@@ -748,12 +780,12 @@ int imv_run(struct imv *imv)
if (result == BACKEND_SUCCESS) {
if (imv->source) {
- imv->source->free(imv->source);
+ async_free_source(imv->source);
}
imv->source = new_source;
imv->source->callback = &source_callback;
imv->source->user_data = imv;
- imv->source->load_first_frame(imv->source);
+ async_load_first_frame(imv->source);
imv->loading = true;
imv_viewport_set_playing(imv->view, true);
@@ -800,7 +832,7 @@ int imv_run(struct imv *imv)
/* Trigger loading of a new frame, now this one's being displayed */
if (imv->source && imv->source->load_next_frame) {
- imv->source->load_next_frame(imv->source);
+ async_load_next_frame(imv->source);
}
}
@@ -934,7 +966,7 @@ static void handle_new_image(struct imv *imv, struct imv_bitmap *bitmap, int fra
/* If this is an animated image, we should kick off loading the next frame */
if (imv->source && imv->source->load_next_frame && frametime) {
- imv->source->load_next_frame(imv->source);
+ async_load_next_frame(imv->source);
}
}
@@ -1455,7 +1487,7 @@ void command_next_frame(struct list *args, const char *argstr, void *data)
(void)argstr;
struct imv *imv = data;
if (imv->source && imv->source->load_next_frame) {
- imv->source->load_next_frame(imv->source);
+ async_load_next_frame(imv->source);
imv->next_frame_due = 1; /* Earliest possible non-zero timestamp */
}
}