summaryrefslogtreecommitdiff
path: root/src/thread.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/thread.h')
-rw-r--r--src/thread.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/thread.h b/src/thread.h
new file mode 100644
index 0000000..b019fdb
--- /dev/null
+++ b/src/thread.h
@@ -0,0 +1,67 @@
+/*
+* BSD 2-Clause “Simplified” License
+* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com
+* All rights reserved.
+*/
+
+#ifndef INCLUDE_THREAD
+#define INCLUDE_THREAD
+
+#ifdef OS_LINUX
+#include <pthread.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/syscall.h>
+
+struct t_thread
+{
+ pthread_t thread;
+ bool valid;
+};
+
+struct t_mutex
+{
+ pthread_mutex_t mutex;
+};
+#endif
+
+#ifdef OS_WIN
+#include <windows.h>
+#include <process.h> /* _beginthread, _endthread */
+#include <stddef.h>
+#include <stdlib.h>
+#include <conio.h>
+
+struct t_thread
+{
+ HANDLE thread;
+ bool valid;
+};
+
+struct t_mutex
+{
+ HANDLE mutex;
+};
+#endif
+
+typedef struct t_thread thread;
+typedef struct t_mutex mutex;
+
+thread thread_start(void *(*start_routine) (void *), void *arg);
+void thread_join(thread *thread);
+bool thread_tryjoin(thread *thread);
+void thread_detach(thread *thread);
+void thread_stop(thread *thread);
+u32 thread_get_id();
+void thread_sleep(u64 microseconds);
+
+mutex mutex_create_recursive();
+mutex mutex_create();
+
+void mutex_lock(mutex *mutex);
+bool mutex_trylock(mutex *mutex);
+void mutex_unlock(mutex *mutex);
+
+void mutex_destroy(mutex *mutex);
+
+#endif \ No newline at end of file