summaryrefslogtreecommitdiff
path: root/lib/mlibc/options/ansi/include/threads.h
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-03-07 17:28:00 -0500
committerIan Moffett <ian@osmora.org>2024-03-07 17:28:32 -0500
commitbd5969fc876a10b18613302db7087ef3c40f18e1 (patch)
tree7c2b8619afe902abf99570df2873fbdf40a4d1a1 /lib/mlibc/options/ansi/include/threads.h
parenta95b38b1b92b172e6cc4e8e56a88a30cc65907b0 (diff)
lib: Add mlibc
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'lib/mlibc/options/ansi/include/threads.h')
-rw-r--r--lib/mlibc/options/ansi/include/threads.h61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/mlibc/options/ansi/include/threads.h b/lib/mlibc/options/ansi/include/threads.h
new file mode 100644
index 0000000..f96abcd
--- /dev/null
+++ b/lib/mlibc/options/ansi/include/threads.h
@@ -0,0 +1,61 @@
+#ifndef _THREADS_H
+#define _THREADS_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <bits/threads.h>
+
+enum {
+ mtx_plain,
+ mtx_recursive,
+ mtx_timed,
+};
+
+enum {
+ thrd_success,
+ thrd_timedout,
+ thrd_busy,
+ thrd_error,
+ thrd_nomem,
+};
+
+typedef struct __mlibc_thread_data *thrd_t;
+typedef struct __mlibc_mutex mtx_t;
+typedef struct __mlibc_cond cnd_t;
+#ifndef __cplusplus
+#define thread_local _Thread_local
+#endif
+
+typedef int (*thrd_start_t)(void*);
+
+#ifndef __MLIBC_ABI_ONLY
+
+int thrd_create(thrd_t *thr, thrd_start_t func, void *arg);
+int thrd_equal(thrd_t lhs, thrd_t rhs);
+thrd_t thrd_current(void);
+int thrd_sleep(const struct timespec *duration, struct timespec *remaining);
+void thrd_yield(void);
+int thrd_detach(thrd_t thr);
+int thrd_join(thrd_t thr, int *res);
+__attribute__((__noreturn__)) void thrd_exit(int res);
+
+int mtx_init(mtx_t *mtx, int type);
+void mtx_destroy(mtx_t *mtx);
+int mtx_lock(mtx_t *mtx);
+int mtx_unlock(mtx_t *mtx);
+
+int cnd_init(cnd_t *cond);
+void cnd_destroy(cnd_t *cond);
+int cnd_broadcast(cnd_t *cond);
+int cnd_wait(cnd_t *cond, mtx_t *mtx);
+
+#endif /* !__MLIBC_ABI_ONLY */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _THREADS_H */
+