aboutsummaryrefslogtreecommitdiff
path: root/include/std/thread.h
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-02-27 22:26:35 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit76d85a10f6cda93eba29dad5372e8160af7289c8 (patch)
treecfec3043ec45a5e83494ec109e87c239dad6cc47 /include/std/thread.h
parent8201cd9f40897cf6b8e6973b28a8661108702ab1 (diff)
Use multiple threads to parse
Diffstat (limited to 'include/std/thread.h')
-rw-r--r--include/std/thread.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/include/std/thread.h b/include/std/thread.h
new file mode 100644
index 0000000..dd09039
--- /dev/null
+++ b/include/std/thread.h
@@ -0,0 +1,50 @@
+#ifndef AMALGAM_THREAD_H
+#define AMALGAM_THREAD_H
+
+#include "misc.h"
+#include "types.h"
+#include "defs.h"
+#include <pthread.h>
+
+typedef void* (AmalThreadCallbackFunc)(void *userdata);
+
+#define AMAL_THREAD_OK 0
+/* General error */
+#define AMAL_THREAD_ERR -1
+#define AMAL_THREAD_NOT_JOINABLE -23
+
+struct amal_thread {
+ pthread_t thread_id;
+ pthread_attr_t thread_attr;
+ const char *name;
+ bool cancellable;
+ bool destroyable;
+};
+
+typedef enum {
+ AMAL_THREAD_JOINABLE,
+ AMAL_THREAD_DETACHED
+} amal_thread_type;
+
+struct amal_mutex {
+ pthread_mutex_t mutex;
+ const char *lock_identifier;
+};
+
+CHECK_RESULT int amal_thread_create(amal_thread *self, amal_thread_type thread_type, const char *name, AmalThreadCallbackFunc callback_func, void *userdata);
+/* Safe to call multiple times */
+CHECK_RESULT int amal_thread_deinit(amal_thread *self);
+CHECK_RESULT int amal_thread_detach(amal_thread *self);
+CHECK_RESULT int amal_thread_join(amal_thread *self, void **result);
+
+void amal_mutex_init(amal_mutex *self);
+CHECK_RESULT int amal_mutex_lock(amal_mutex *self, const char *lock_identifier);
+CHECK_RESULT int amal_mutex_unlock(amal_mutex *self);
+void amal_mutex_tryunlock(amal_mutex *self);
+
+bool amal_thread_is_main();
+
+/* Returns 0 if the number of usable threads is unknown */
+int amal_get_usable_thread_count();
+
+#endif \ No newline at end of file