From b1e857cf1471d1871a9396696b22fa531da98249 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 23 Nov 2024 22:33:43 +0100 Subject: add projbase to repo --- project-base/src/thread.h | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 project-base/src/thread.h (limited to 'project-base/src/thread.h') 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 +#include +#include +#include + +struct t_thread +{ + pthread_t thread; + bool valid; +}; + +struct t_mutex +{ + pthread_mutex_t mutex; +}; +#endif + +#ifdef OS_WIN +#include +#include /* _beginthread, _endthread */ +#include +#include +#include + +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 -- cgit v1.2.3-70-g09d2