diff options
| author | TazyFoundSoup <gardendistrict0x0@outlook.com> | 2026-06-11 19:07:19 +1000 |
|---|---|---|
| committer | TazyFoundSoup <gardendistrict0x0@outlook.com> | 2026-06-11 19:07:19 +1000 |
| commit | ee5421470a92d66ff79098f68e2ceb99c4cbfd3c (patch) | |
| tree | d4224df4c1fd2eaf189adf00cdd3270a353e8551 /src/common.c | |
| parent | b1e964269f4afc8f714687049b268a8901786e84 (diff) | |
fix(thread): Add mutex to ff_ctx and make ff_dprintf thread-safe
Diffstat (limited to 'src/common.c')
| -rw-r--r-- | src/common.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common.c b/src/common.c index bde1bac..f9e46d5 100644 --- a/src/common.c +++ b/src/common.c @@ -6,6 +6,9 @@ #include <stdlib.h> #endif +#ifdef USE_THREAD +#include <pthread.h> +#endif // Initializes a new tinyff context. ff_ctx* ff_init(ff_allocator* allocator) @@ -27,12 +30,25 @@ ff_ctx* ff_init(ff_allocator* allocator) ctx->allocator = *allocator; +#ifdef USE_THREAD + /* initialize mutex used to protect ctx state */ + if (pthread_mutex_init(&ctx->ff_lock, NULL) != 0) { + ctx->allocator.ff_free(ctx); + return NULL; + } +#endif + return ctx; } void ff_cleanup(ff_ctx *ctx) { if (!ctx) return; ff_dprintf(ctx, "goodbye from tinyff ;]\n"); + +#ifdef USE_THREAD + pthread_mutex_destroy(&ctx->ff_lock); +#endif + ctx->allocator.ff_free(ctx); } |
