From 76d85a10f6cda93eba29dad5372e8160af7289c8 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 27 Feb 2019 22:26:35 +0100 Subject: Use multiple threads to parse --- include/std/thread.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 include/std/thread.h (limited to 'include/std/thread.h') 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 + +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 -- cgit v1.2.3