diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-03-08 20:48:05 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-03-08 20:48:05 +0100 |
| commit | 0b429e06b8c4b66a9f7fe89b5504315ab4f69616 (patch) | |
| tree | d5cf9d15d8790559f0c4b006ede0ca1314639077 /src/mutex.h | |
| parent | def620a66bc5b0dc1107102f2c234888dc9bd830 (diff) | |
linux building
Diffstat (limited to 'src/mutex.h')
| -rw-r--r-- | src/mutex.h | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/mutex.h b/src/mutex.h index a745947..8499bcc 100644 --- a/src/mutex.h +++ b/src/mutex.h @@ -1,7 +1,7 @@ #ifndef INCLUDE_MUTEX #define INCLUDE_MUTEX -#ifdef _WIN32 +#if defined(_WIN32) #include <windows.h> #include <process.h> /* _beginthread, _endthread */ #include <stddef.h> @@ -19,11 +19,28 @@ typedef struct t_ts_thread HANDLE thread; int valid; } ts_thread; + +#elif defined(__linux__) +#include <pthread.h> +#include <unistd.h> +#include <sys/types.h> +#include <sys/syscall.h> + +typedef struct t_ts_thread +{ + pthread_t thread; + bool valid; +} ts_thread; + +typedef struct t_ts_mutex +{ + pthread_mutex_t mutex; +} ts_mutex; #endif ts_thread ts_thread_start(void *(*start_routine) (void *), void *arg); void ts_thread_join(ts_thread *ts_thread); -int ts_thread_tryjoin(ts_thread *ts_thread); +bool ts_thread_tryjoin(ts_thread *ts_thread); void ts_thread_detach(ts_thread *ts_thread); void ts_thread_stop(ts_thread *ts_thread); int ts_thread_get_id(); @@ -33,7 +50,7 @@ void ts_thread_exit(); ts_mutex ts_mutex_create_recursive(); ts_mutex ts_mutex_create(); void ts_mutex_lock(ts_mutex *ts_mutex); -int ts_mutex_trylock(ts_mutex *ts_mutex); +bool ts_mutex_trylock(ts_mutex *ts_mutex); void ts_mutex_unlock(ts_mutex *ts_mutex); void ts_mutex_destroy(ts_mutex *ts_mutex); |
