summaryrefslogtreecommitdiffstats
path: root/src/installation_proxy.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2013-03-20 05:38:06 +0100
committerGravatar Nikias Bassen2013-03-20 05:38:06 +0100
commitb2924a1549d874fb86deaad5fd2438e567c65bf4 (patch)
treeead89f885a0492cdfc228a1c25326912e7d9b973 /src/installation_proxy.c
parentefca491e4c19868a68a099638552f9ba431dca4b (diff)
downloadlibimobiledevice-b2924a1549d874fb86deaad5fd2438e567c65bf4.tar.gz
libimobiledevice-b2924a1549d874fb86deaad5fd2438e567c65bf4.tar.bz2
use new internal common code for thread, mutex, and socket operations
Diffstat (limited to 'src/installation_proxy.c')
-rw-r--r--src/installation_proxy.c46
1 files changed, 6 insertions, 40 deletions
diff --git a/src/installation_proxy.c b/src/installation_proxy.c
index f8da91c..c49014d 100644
--- a/src/installation_proxy.c
+++ b/src/installation_proxy.c
@@ -43,11 +43,7 @@ struct instproxy_status_data {
43static void instproxy_lock(instproxy_client_t client) 43static void instproxy_lock(instproxy_client_t client)
44{ 44{
45 debug_info("InstallationProxy: Locked"); 45 debug_info("InstallationProxy: Locked");
46#ifdef WIN32 46 mutex_lock(&client->mutex);
47 EnterCriticalSection(&client->mutex);
48#else
49 pthread_mutex_lock(&client->mutex);
50#endif
51} 47}
52 48
53/** 49/**
@@ -58,11 +54,7 @@ static void instproxy_lock(instproxy_client_t client)
58static void instproxy_unlock(instproxy_client_t client) 54static void instproxy_unlock(instproxy_client_t client)
59{ 55{
60 debug_info("InstallationProxy: Unlocked"); 56 debug_info("InstallationProxy: Unlocked");
61#ifdef WIN32 57 mutex_unlock(&client->mutex);
62 LeaveCriticalSection(&client->mutex);
63#else
64 pthread_mutex_unlock(&client->mutex);
65#endif
66} 58}
67 59
68/** 60/**
@@ -112,13 +104,8 @@ instproxy_error_t instproxy_client_new(idevice_t device, lockdownd_service_descr
112 104
113 instproxy_client_t client_loc = (instproxy_client_t) malloc(sizeof(struct instproxy_client_private)); 105 instproxy_client_t client_loc = (instproxy_client_t) malloc(sizeof(struct instproxy_client_private));
114 client_loc->parent = plistclient; 106 client_loc->parent = plistclient;
115#ifdef WIN32 107 mutex_init(&client_loc->mutex);
116 InitializeCriticalSection(&client_loc->mutex);
117 client_loc->status_updater = NULL; 108 client_loc->status_updater = NULL;
118#else
119 pthread_mutex_init(&client_loc->mutex, NULL);
120 client_loc->status_updater = (pthread_t)NULL;
121#endif
122 109
123 *client = client_loc; 110 *client = client_loc;
124 return INSTPROXY_E_SUCCESS; 111 return INSTPROXY_E_SUCCESS;
@@ -142,17 +129,9 @@ instproxy_error_t instproxy_client_free(instproxy_client_t client)
142 client->parent = NULL; 129 client->parent = NULL;
143 if (client->status_updater) { 130 if (client->status_updater) {
144 debug_info("joining status_updater"); 131 debug_info("joining status_updater");
145#ifdef WIN32 132 thread_join(client->status_updater);
146 WaitForSingleObject(client->status_updater, INFINITE);
147#else
148 pthread_join(client->status_updater, NULL);
149#endif
150 } 133 }
151#ifdef WIN32 134 mutex_destroy(&client->mutex);
152 DeleteCriticalSection(&client->mutex);
153#else
154 pthread_mutex_destroy(&client->mutex);
155#endif
156 free(client); 135 free(client);
157 136
158 return INSTPROXY_E_SUCCESS; 137 return INSTPROXY_E_SUCCESS;
@@ -375,11 +354,7 @@ static void* instproxy_status_updater(void* arg)
375 if (data->operation) { 354 if (data->operation) {
376 free(data->operation); 355 free(data->operation);
377 } 356 }
378#ifdef WIN32
379 data->client->status_updater = NULL; 357 data->client->status_updater = NULL;
380#else
381 data->client->status_updater = (pthread_t)NULL;
382#endif
383 instproxy_unlock(data->client); 358 instproxy_unlock(data->client);
384 free(data); 359 free(data);
385 360
@@ -414,18 +389,9 @@ static instproxy_error_t instproxy_create_status_updater(instproxy_client_t clie
414 data->operation = strdup(operation); 389 data->operation = strdup(operation);
415 data->user_data = user_data; 390 data->user_data = user_data;
416 391
417#ifdef WIN32 392 if (thread_create(&client->status_updater, instproxy_status_updater, data) == 0) {
418 client->status_updater = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)instproxy_status_updater, data, 0, NULL);
419 if (client->status_updater != INVALID_HANDLE_VALUE) {
420 res = INSTPROXY_E_SUCCESS;
421 } else {
422 client->status_updater = NULL;
423 }
424#else
425 if (pthread_create(&client->status_updater, NULL, instproxy_status_updater, data) == 0) {
426 res = INSTPROXY_E_SUCCESS; 393 res = INSTPROXY_E_SUCCESS;
427 } 394 }
428#endif
429 } 395 }
430 } else { 396 } else {
431 /* sync mode */ 397 /* sync mode */