summaryrefslogtreecommitdiff
path: root/src/thread
diff options
context:
space:
mode:
authorTazyFoundSoup <gardendistrict0x0@outlook.com>2026-06-11 19:07:15 +1000
committerTazyFoundSoup <gardendistrict0x0@outlook.com>2026-06-11 19:07:15 +1000
commitb1e964269f4afc8f714687049b268a8901786e84 (patch)
tree8b8306afea9b5cf5759c4543fd85cfa7cf7be27a /src/thread
parent039452e45658a1160cebe8937133d3fe7f9265b4 (diff)
feat(thread): Add ff_thread_submit helper
Diffstat (limited to 'src/thread')
-rw-r--r--src/thread/thread_submit.c27
1 files changed, 27 insertions, 0 deletions
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 <tinyff/thread/thread.h>
+#include <bridges/pthread/thread_bridge.h>
+#include <tinyff/result.h>
+
+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