diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2019-02-04 02:34:46 +0000 |
---|---|---|
committer | Harry Jeffery <harry@exec64.co.uk> | 2019-02-04 03:48:03 +0000 |
commit | 05db4c452cbf6d314be60b86524629ef22798adf (patch) | |
tree | af4830b00a8ccfd70a9d5563ef0534924da080ca /src/source.h | |
parent | 09928120e31edbfa63791f0c2f5e14374ae518de (diff) | |
download | imv-05db4c452cbf6d314be60b86524629ef22798adf.tar.gz |
Make sources thread-safe
Diffstat (limited to 'src/source.h')
-rw-r--r-- | src/source.h | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/source.h b/src/source.h index 74501ed..4f1a0dd 100644 --- a/src/source.h +++ b/src/source.h @@ -1,6 +1,7 @@ #ifndef IMV_SOURCE_H #define IMV_SOURCE_H +#include <pthread.h> #include <stdbool.h> #include "bitmap.h" @@ -36,11 +37,18 @@ struct imv_source { /* Next frame to be loaded, 0-indexed */ int next_frame; - /* Trigger loading of the first frame. */ - void (*load_first_frame)(struct imv_source *src); + /* Attempted to be locked by load_first_frame or load_next_frame. + * If the mutex can't be locked, the call is aborted. + * Used to prevent the source from having multiple worker threads at once. + * Released by the source before calling the message callback with a result. + */ + pthread_mutex_t busy; + + /* Trigger loading of the first frame. Returns 0 on success. */ + int (*load_first_frame)(struct imv_source *src); - /* Trigger loading of next frame. */ - void (*load_next_frame)(struct imv_source *src); + /* Trigger loading of next frame. Returns 0 on success. */ + int (*load_next_frame)(struct imv_source *src); /* Safely free contents of this source. After this returns * it is safe to dealocate/overwrite the imv_source instance. |