diff options
| author | 2019-09-05 08:41:42 +0200 | |
|---|---|---|
| committer | 2019-09-05 08:41:42 +0200 | |
| commit | 43003cbc26315aaaee342158939c3b3504f367d0 (patch) | |
| tree | 49586b12981f955388cc7a765c557d687c5bfc9e /src/thread.h | |
| parent | 174123a943cd26a9c003745d0226eb5bfd1a5d6f (diff) | |
| download | libirecovery-43003cbc26315aaaee342158939c3b3504f367d0.tar.gz libirecovery-43003cbc26315aaaee342158939c3b3504f367d0.tar.bz2 | |
Add missing files for previous commit
I shouldn't do late night commits without checking that I added all files
Diffstat (limited to 'src/thread.h')
| -rw-r--r-- | src/thread.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/thread.h b/src/thread.h new file mode 100644 index 0000000..23e4510 --- /dev/null +++ b/src/thread.h | |||
| @@ -0,0 +1,76 @@ | |||
| 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 volatile struct { | ||
| 32 | LONG lock; | ||
| 33 | int state; | ||
| 34 | } thread_once_t; | ||
| 35 | #define THREAD_ONCE_INIT {0, 0} | ||
| 36 | #define THREAD_ID GetCurrentThreadId() | ||
| 37 | #define THREAD_T_NULL (THREAD_T)NULL | ||
| 38 | #else | ||
| 39 | #include <pthread.h> | ||
| 40 | #include <signal.h> | ||
| 41 | typedef pthread_t THREAD_T; | ||
| 42 | typedef pthread_mutex_t mutex_t; | ||
| 43 | typedef pthread_once_t thread_once_t; | ||
| 44 | #define THREAD_ONCE_INIT PTHREAD_ONCE_INIT | ||
| 45 | #define THREAD_ID pthread_self() | ||
| 46 | #define THREAD_T_NULL (THREAD_T)NULL | ||
| 47 | #endif | ||
| 48 | |||
| 49 | typedef void* (*thread_func_t)(void* data); | ||
| 50 | |||
| 51 | int thread_new(THREAD_T* thread, thread_func_t thread_func, void* data); | ||
| 52 | void thread_detach(THREAD_T thread); | ||
| 53 | void thread_free(THREAD_T thread); | ||
| 54 | int thread_join(THREAD_T thread); | ||
| 55 | int thread_alive(THREAD_T thread); | ||
| 56 | |||
| 57 | int thread_cancel(THREAD_T thread); | ||
| 58 | |||
| 59 | #ifdef WIN32 | ||
| 60 | #undef HAVE_THREAD_CLEANUP | ||
| 61 | #else | ||
| 62 | #ifdef HAVE_PTHREAD_CANCEL | ||
| 63 | #define HAVE_THREAD_CLEANUP 1 | ||
| 64 | #define thread_cleanup_push(routine, arg) pthread_cleanup_push(routine, arg) | ||
| 65 | #define thread_cleanup_pop(execute) pthread_cleanup_pop(execute) | ||
| 66 | #endif | ||
| 67 | #endif | ||
| 68 | |||
| 69 | void mutex_init(mutex_t* mutex); | ||
| 70 | void mutex_destroy(mutex_t* mutex); | ||
| 71 | void mutex_lock(mutex_t* mutex); | ||
| 72 | void mutex_unlock(mutex_t* mutex); | ||
| 73 | |||
| 74 | void thread_once(thread_once_t *once_control, void (*init_routine)(void)); | ||
| 75 | |||
| 76 | #endif | ||
