summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTazyFoundSoup <gardendistrict0x0@outlook.com>2026-06-08 10:35:16 +1000
committerTazyFoundSoup <gardendistrict0x0@outlook.com>2026-06-08 10:35:16 +1000
commitedc34e77d5f19aa2a697f16d9e2d24677dafb506 (patch)
tree2949e8b6cacf7f1d7232dfa6077de0b1c12d9326
parentc9f5da1d19e6ace5d6a7c650fe996f359e11d1a5 (diff)
feat(thread): Implement pthread bridge and fix allocator usage in wrapperfeat/multi-threading
-rw-r--r--Makefile4
-rw-r--r--include/bridges/pthread/thread_bridge.h13
-rw-r--r--include/tinyff/thread/thread.h6
-rw-r--r--src/bridges/pthread/thread_bridge.c11
-rw-r--r--src/thread/thread.c10
5 files changed, 39 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 72bcb00..9801d29 100644
--- a/Makefile
+++ b/Makefile
@@ -24,6 +24,10 @@ ifeq ($(USE_BENCH),1)
ALL_CFLAGS += -DUSE_BENCH
endif
+ifeq ($(USE_THREAD),1)
+ALL_CFLAGS += -DUSE_THREAD
+endif
+
OBJ = $(patsubst %.c,$(OUTDIR)/%.o,$(SRC))
all: release
diff --git a/include/bridges/pthread/thread_bridge.h b/include/bridges/pthread/thread_bridge.h
new file mode 100644
index 0000000..dc7b75b
--- /dev/null
+++ b/include/bridges/pthread/thread_bridge.h
@@ -0,0 +1,13 @@
+#ifdef USE_THREAD
+
+#ifndef BRIDGES_PTHREAD_THREAD_BRIDGE_H
+#define BRIDGES_PTHREAD_THREAD_BRIDGE_H
+
+#include <pthread.h>
+#include <tinyff/thread/thread.h>
+
+pthread_t run_job_in_thread(ff_thread_job *job);
+
+#endif
+
+#endif \ No newline at end of file
diff --git a/include/tinyff/thread/thread.h b/include/tinyff/thread/thread.h
index 40c09a0..1d0a644 100644
--- a/include/tinyff/thread/thread.h
+++ b/include/tinyff/thread/thread.h
@@ -3,15 +3,17 @@
#ifndef TINYFF_THREAD_H
#define TINYFF_THREAD_H
+#include <tinyff/common.h>
+
typedef void (*ff_job_cb)(void *arg);
typedef struct {
ff_job_cb callback;
void *arg;
+ ff_ctx *ctx;
} ff_thread_job;
void *ff_thread_wrapper(void *ptr);
-// Each platform must have their own bridge for running a thread job
-// Like pthreads for POSIX systems
#endif
+#endif \ No newline at end of file
diff --git a/src/bridges/pthread/thread_bridge.c b/src/bridges/pthread/thread_bridge.c
new file mode 100644
index 0000000..e014a3a
--- /dev/null
+++ b/src/bridges/pthread/thread_bridge.c
@@ -0,0 +1,11 @@
+#ifdef USE_THREAD
+
+#include <bridges/pthread/thread_bridge.h>
+
+pthread_t run_job_in_thread(ff_thread_job *job) {
+ pthread_t thread;
+ pthread_create(&thread, NULL, ff_thread_wrapper, job);
+ return thread;
+}
+
+#endif \ No newline at end of file
diff --git a/src/thread/thread.c b/src/thread/thread.c
index 524c64a..d8ba05b 100644
--- a/src/thread/thread.c
+++ b/src/thread/thread.c
@@ -1,12 +1,16 @@
+#ifdef USE_THREAD
+
#include <tinyff/thread/thread.h>
-void *thread_wrapper(void *ptr) {
+void *ff_thread_wrapper(void *ptr) {
ff_thread_job *job = (ff_thread_job *)ptr;
-
+
if (job->callback) {
job->callback(job->arg);
}
- free(job);
+ job->ctx->allocator.ff_free(job);
return NULL;
}
+
+#endif \ No newline at end of file