diff options
Diffstat (limited to 'src/thread.h')
| -rw-r--r-- | src/thread.h | 87 |
1 files changed, 0 insertions, 87 deletions
diff --git a/src/thread.h b/src/thread.h deleted file mode 100644 index 2aadc6e..0000000 --- a/src/thread.h +++ /dev/null | |||
| @@ -1,87 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * thread.h | ||
| 3 | * | ||
| 4 | * Copyright (c) 2012-2019 Nikias Bassen, All Rights Reserved. | ||
| 5 | * Copyright (c) 2012 Martin Szulecki, All Rights Reserved. | ||
| 6 | * | ||
| 7 | * This library is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * This library is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with this library; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #ifndef __THREAD_H | ||
| 23 | #define __THREAD_H | ||
| 24 | |||
| 25 | #include <stddef.h> | ||
| 26 | |||
| 27 | #ifdef WIN32 | ||
| 28 | #include <windows.h> | ||
| 29 | typedef HANDLE THREAD_T; | ||
| 30 | typedef CRITICAL_SECTION mutex_t; | ||
| 31 | typedef struct { | ||
| 32 | HANDLE sem; | ||
| 33 | } cond_t; | ||
| 34 | typedef volatile struct { | ||
| 35 | LONG lock; | ||
| 36 | int state; | ||
| 37 | } thread_once_t; | ||
| 38 | #define THREAD_ONCE_INIT {0, 0} | ||
| 39 | #define THREAD_ID GetCurrentThreadId() | ||
| 40 | #define THREAD_T_NULL (THREAD_T)NULL | ||
| 41 | #else | ||
| 42 | #include <pthread.h> | ||
| 43 | #include <signal.h> | ||
| 44 | #include <sys/time.h> | ||
| 45 | typedef pthread_t THREAD_T; | ||
| 46 | typedef pthread_mutex_t mutex_t; | ||
| 47 | typedef pthread_cond_t cond_t; | ||
| 48 | typedef pthread_once_t thread_once_t; | ||
| 49 | #define THREAD_ONCE_INIT PTHREAD_ONCE_INIT | ||
| 50 | #define THREAD_ID pthread_self() | ||
| 51 | #define THREAD_T_NULL (THREAD_T)NULL | ||
| 52 | #endif | ||
| 53 | |||
| 54 | typedef void* (*thread_func_t)(void* data); | ||
| 55 | |||
| 56 | int thread_new(THREAD_T* thread, thread_func_t thread_func, void* data); | ||
| 57 | void thread_detach(THREAD_T thread); | ||
| 58 | void thread_free(THREAD_T thread); | ||
| 59 | int thread_join(THREAD_T thread); | ||
| 60 | int thread_alive(THREAD_T thread); | ||
| 61 | |||
| 62 | int thread_cancel(THREAD_T thread); | ||
| 63 | |||
| 64 | #ifdef WIN32 | ||
| 65 | #undef HAVE_THREAD_CLEANUP | ||
| 66 | #else | ||
| 67 | #ifdef HAVE_PTHREAD_CANCEL | ||
| 68 | #define HAVE_THREAD_CLEANUP 1 | ||
| 69 | #define thread_cleanup_push(routine, arg) pthread_cleanup_push(routine, arg) | ||
| 70 | #define thread_cleanup_pop(execute) pthread_cleanup_pop(execute) | ||
| 71 | #endif | ||
| 72 | #endif | ||
| 73 | |||
| 74 | void mutex_init(mutex_t* mutex); | ||
| 75 | void mutex_destroy(mutex_t* mutex); | ||
| 76 | void mutex_lock(mutex_t* mutex); | ||
| 77 | void mutex_unlock(mutex_t* mutex); | ||
| 78 | |||
| 79 | void thread_once(thread_once_t *once_control, void (*init_routine)(void)); | ||
| 80 | |||
| 81 | void cond_init(cond_t* cond); | ||
| 82 | void cond_destroy(cond_t* cond); | ||
| 83 | int cond_signal(cond_t* cond); | ||
| 84 | int cond_wait(cond_t* cond, mutex_t* mutex); | ||
| 85 | int cond_wait_timeout(cond_t* cond, mutex_t* mutex, unsigned int timeout_ms); | ||
| 86 | |||
| 87 | #endif | ||
