summaryrefslogtreecommitdiffstats
path: root/src/normal.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2019-10-11 23:08:48 +0200
committerGravatar Nikias Bassen2019-10-11 23:10:07 +0200
commit767fcceaeb456f5e281a6bd1b3f51713e4989293 (patch)
treed9a01fbea3c1a85f41ca0f033037737739a14629 /src/normal.c
parent75a61508bd3c2013492744fb5aea755e19b01086 (diff)
downloadidevicerestore-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/normal.c')
-rw-r--r--src/normal.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/normal.c b/src/normal.c
index 89ec462..4104f33 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -33,6 +33,7 @@
#include "common.h"
#include "normal.h"
#include "recovery.h"
+#include "thread.h"
static int normal_idevice_new(struct idevicerestore_client_t* client, idevice_t* device)
{
@@ -237,19 +238,23 @@ int normal_enter_recovery(struct idevicerestore_client_t* client)
lockdown = NULL;
device = NULL;
+ mutex_lock(&client->device_event_mutex);
debug("DEBUG: Waiting for device to disconnect...\n");
- WAIT_FOR(client->mode != &idevicerestore_modes[MODE_NORMAL] || (client->flags & FLAG_QUIT), 60);
+ cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 60000);
if (client->mode == &idevicerestore_modes[MODE_NORMAL] || (client->flags & FLAG_QUIT)) {
+ mutex_unlock(&client->device_event_mutex);
error("ERROR: Failed to place device in recovery mode\n");
return -1;
}
debug("DEBUG: Waiting for device to connect in recovery mode...\n");
- WAIT_FOR(client->mode == &idevicerestore_modes[MODE_RECOVERY] || (client->flags & FLAG_QUIT), 60);
+ cond_wait_timeout(&client->device_event_cond, &client->device_event_mutex, 60000);
if (client->mode != &idevicerestore_modes[MODE_RECOVERY] || (client->flags & FLAG_QUIT)) {
+ mutex_unlock(&client->device_event_mutex);
error("ERROR: Failed to enter recovery mode\n");
return -1;
}
+ mutex_unlock(&client->device_event_mutex);
if (recovery_client_new(client) < 0) {
error("ERROR: Unable to enter recovery mode\n");