diff options
author | Nikias Bassen | 2019-10-11 23:08:48 +0200 |
---|---|---|
committer | Nikias Bassen | 2019-10-11 23:10:07 +0200 |
commit | 767fcceaeb456f5e281a6bd1b3f51713e4989293 (patch) | |
tree | d9a01fbea3c1a85f41ca0f033037737739a14629 /src/thread.h | |
parent | 75a61508bd3c2013492744fb5aea755e19b01086 (diff) | |
download | idevicerestore-767fcceaeb456f5e281a6bd1b3f51713e4989293.tar.gz idevicerestore-767fcceaeb456f5e281a6bd1b3f51713e4989293.tar.bz2 |
Use condition variable instead of active waiting for device event handling
With some devices and USB hardware the reconnect of a device might actually
be faster than the check interval of the active waiting loop. With mutexes
and a condition variable we will not miss the moment of reconnect anymore,
even if it is really quick (like 7ms, right DanyL?)
Diffstat (limited to 'src/thread.h')
-rw-r--r-- | src/thread.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/thread.h b/src/thread.h index feccc94..69c6632 100644 --- a/src/thread.h +++ b/src/thread.h @@ -26,6 +26,9 @@ #include <windows.h> typedef HANDLE thread_t; typedef CRITICAL_SECTION mutex_t; +typedef struct { + HANDLE sem; +} cond_t; typedef volatile struct { LONG lock; int state; @@ -35,8 +38,10 @@ typedef volatile struct { #else #include <pthread.h> #include <signal.h> +#include <sys/time.h> typedef pthread_t thread_t; typedef pthread_mutex_t mutex_t; +typedef pthread_cond_t cond_t; typedef pthread_once_t thread_once_t; #define THREAD_ONCE_INIT PTHREAD_ONCE_INIT #define THREAD_ID pthread_self() @@ -56,4 +61,10 @@ void mutex_unlock(mutex_t* mutex); void thread_once(thread_once_t *once_control, void (*init_routine)(void)); +void cond_init(cond_t* cond); +void cond_destroy(cond_t* cond); +int cond_signal(cond_t* cond); +int cond_wait(cond_t* cond, mutex_t* mutex); +int cond_wait_timeout(cond_t* cond, mutex_t* mutex, unsigned int timeout_ms); + #endif |