From b1e964269f4afc8f714687049b268a8901786e84 Mon Sep 17 00:00:00 2001 From: TazyFoundSoup Date: Thu, 11 Jun 2026 19:07:15 +1000 Subject: feat(thread): Add ff_thread_submit helper --- src/thread/thread_submit.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/thread/thread_submit.c (limited to 'src/thread') diff --git a/src/thread/thread_submit.c b/src/thread/thread_submit.c new file mode 100644 index 0000000..fd332b6 --- /dev/null +++ b/src/thread/thread_submit.c @@ -0,0 +1,27 @@ +#ifdef USE_THREAD + +#include +#include +#include + +ff_result ff_thread_submit(ff_ctx *ctx, ff_job_cb callback, void *arg) { + if (!ctx || !callback) return FF_RESULT_ERROR_NULL_PTR; + + ff_thread_job *job = ctx->allocator.ff_alloc(sizeof(ff_thread_job)); + if (!job) return FF_RESULT_ERROR_MEMORY_ALLOCATION; + + job->callback = callback; + job->arg = arg; + job->ctx = ctx; + + pthread_t t = run_job_in_thread(job); + if ((pthread_t)0 == t) { + // failed to create thread + ctx->allocator.ff_free(job); + return FF_RESULT_WARN_NO_IMPL; // thread creation failed + } + + return FF_RESULT_OK; +} + +#endif \ No newline at end of file -- cgit v1.2.3