diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-11-23 22:33:43 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-11-23 22:33:43 +0100 |
| commit | b1e857cf1471d1871a9396696b22fa531da98249 (patch) | |
| tree | 3923008a8653057698cb339faf6dcfa92e18364b /project-base/src/thread.h | |
| parent | 106bb7fcadf637cec883648916cc8d19529d6199 (diff) | |
add projbase to repo
Diffstat (limited to 'project-base/src/thread.h')
| -rw-r--r-- | project-base/src/thread.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/project-base/src/thread.h b/project-base/src/thread.h new file mode 100644 index 0000000..01e8614 --- /dev/null +++ b/project-base/src/thread.h @@ -0,0 +1,68 @@ +/* +* 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); +void thread_exit(); + +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 |
