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/dbg.c | |
| parent | b1e964269f4afc8f714687049b268a8901786e84 (diff) | |
fix(thread): Add mutex to ff_ctx and make ff_dprintf thread-safe
Diffstat (limited to 'src/dbg.c')
| -rw-r--r-- | src/dbg.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -3,6 +3,10 @@ #include <stdarg.h> #include <stdint.h> +#ifdef USE_THREAD +#include <pthread.h> +#endif + static size_t ff_internal_itoa(int value, char* buf) { char temp[12]; @@ -52,6 +56,9 @@ static inline void ff_debug_flush(ff_ctx* ctx, char* buffer, size_t* idx) { if (*idx == 0) return; +#ifdef USE_THREAD + pthread_mutex_lock(&ctx->ff_lock); +#endif ctx->ff_debug_stream.write( buffer, *idx, @@ -59,6 +66,9 @@ static inline void ff_debug_flush(ff_ctx* ctx, char* buffer, size_t* idx) ); *idx = 0; +#ifdef USE_THREAD + pthread_mutex_unlock(&ctx->ff_lock); +#endif } ff_result ff_dprintf(ff_ctx* ctx, const char *format, ...) @@ -74,6 +84,10 @@ ff_result ff_dprintf(ff_ctx* ctx, const char *format, ...) size_t buf_idx = 0; const char* p = format; +#ifdef USE_THREAD + pthread_mutex_lock(&ctx->ff_lock); +#endif + while (*p) { if (buf_idx >= sizeof(buffer) - 64) { @@ -152,6 +166,10 @@ ff_result ff_dprintf(ff_ctx* ctx, const char *format, ...) ff_debug_flush(ctx, buffer, &buf_idx); +#ifdef USE_THREAD + pthread_mutex_unlock(&ctx->ff_lock); +#endif + va_end(args); return FF_RESULT_OK; }
\ No newline at end of file |
