From 767fcceaeb456f5e281a6bd1b3f51713e4989293 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Fri, 11 Oct 2019 23:08:48 +0200 Subject: 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?) --- src/common.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/common.h') diff --git a/src/common.h b/src/common.h index 41a7bc6..87ceaaf 100644 --- a/src/common.h +++ b/src/common.h @@ -38,6 +38,7 @@ extern "C" { #include #include "idevicerestore.h" +#include "thread.h" #define MODE_UNKNOWN -1 #define MODE_WTF 0 @@ -106,6 +107,8 @@ struct idevicerestore_client_t { void* progress_cb_data; irecv_device_event_context_t irecv_e_ctx; void* idevice_e_ctx; + mutex_t device_event_mutex; + cond_t device_event_cond; }; extern struct idevicerestore_mode_t idevicerestore_modes[]; @@ -155,10 +158,6 @@ char* realpath(const char *filename, char *resolved_name); void get_user_input(char *buf, int maxlen, int secure); -#define WAIT_INTERVAL 200000 -#define WAIT_MAX(x) (x * (1000000 / WAIT_INTERVAL)) -#define WAIT_FOR(cond, timeout) { int __repeat = WAIT_MAX(timeout); while (!(cond) && __repeat-- > 0) { __usleep(WAIT_INTERVAL); } } - uint8_t _plist_dict_get_bool(plist_t dict, const char *key); uint64_t _plist_dict_get_uint(plist_t dict, const char *key); -- cgit v1.1-32-gdbae