diff options
| author | 2011-09-10 19:08:39 +0200 | |
|---|---|---|
| committer | 2012-03-19 01:38:54 +0100 | |
| commit | 475c9679716eec92e3508063b7486e3508c4c974 (patch) | |
| tree | 5ab09c85387821e05b052cbb642b92ae102953ec /src/installation_proxy.c | |
| parent | 6f29ab73053327066409744d025dcbd03fd6b627 (diff) | |
| download | libimobiledevice-475c9679716eec92e3508063b7486e3508c4c974.tar.gz libimobiledevice-475c9679716eec92e3508063b7486e3508c4c974.tar.bz2 | |
WIN32: use windows threads and mutexes instead of pthread_*
Diffstat (limited to 'src/installation_proxy.c')
| -rw-r--r-- | src/installation_proxy.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/installation_proxy.c b/src/installation_proxy.c index e26a77d..a32fc50 100644 --- a/src/installation_proxy.c +++ b/src/installation_proxy.c | |||
| @@ -43,7 +43,11 @@ struct instproxy_status_data { | |||
| 43 | static void instproxy_lock(instproxy_client_t client) | 43 | static void instproxy_lock(instproxy_client_t client) |
| 44 | { | 44 | { |
| 45 | debug_info("InstallationProxy: Locked"); | 45 | debug_info("InstallationProxy: Locked"); |
| 46 | #ifdef WIN32 | ||
| 47 | EnterCriticalSection(&client->mutex); | ||
| 48 | #else | ||
| 46 | pthread_mutex_lock(&client->mutex); | 49 | pthread_mutex_lock(&client->mutex); |
| 50 | #endif | ||
| 47 | } | 51 | } |
| 48 | 52 | ||
| 49 | /** | 53 | /** |
| @@ -54,7 +58,11 @@ static void instproxy_lock(instproxy_client_t client) | |||
| 54 | static void instproxy_unlock(instproxy_client_t client) | 58 | static void instproxy_unlock(instproxy_client_t client) |
| 55 | { | 59 | { |
| 56 | debug_info("InstallationProxy: Unlocked"); | 60 | debug_info("InstallationProxy: Unlocked"); |
| 61 | #ifdef WIN32 | ||
| 62 | LeaveCriticalSection(&client->mutex); | ||
| 63 | #else | ||
| 57 | pthread_mutex_unlock(&client->mutex); | 64 | pthread_mutex_unlock(&client->mutex); |
| 65 | #endif | ||
| 58 | } | 66 | } |
| 59 | 67 | ||
| 60 | /** | 68 | /** |
| @@ -106,8 +114,13 @@ instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instprox | |||
| 106 | 114 | ||
| 107 | instproxy_client_t client_loc = (instproxy_client_t) malloc(sizeof(struct instproxy_client_private)); | 115 | instproxy_client_t client_loc = (instproxy_client_t) malloc(sizeof(struct instproxy_client_private)); |
| 108 | client_loc->parent = plistclient; | 116 | client_loc->parent = plistclient; |
| 117 | #ifdef WIN32 | ||
| 118 | InitializeCriticalSection(&client_loc->mutex); | ||
| 119 | client_loc->status_updater = NULL; | ||
| 120 | #else | ||
| 109 | pthread_mutex_init(&client_loc->mutex, NULL); | 121 | pthread_mutex_init(&client_loc->mutex, NULL); |
| 110 | client_loc->status_updater = (pthread_t)NULL; | 122 | client_loc->status_updater = (pthread_t)NULL; |
| 123 | #endif | ||
| 111 | 124 | ||
| 112 | *client = client_loc; | 125 | *client = client_loc; |
| 113 | return INSTPROXY_E_SUCCESS; | 126 | return INSTPROXY_E_SUCCESS; |
| @@ -131,9 +144,17 @@ instproxy_error_t instproxy_client_free(instproxy_client_t client) | |||
| 131 | client->parent = NULL; | 144 | client->parent = NULL; |
| 132 | if (client->status_updater) { | 145 | if (client->status_updater) { |
| 133 | debug_info("joining status_updater"); | 146 | debug_info("joining status_updater"); |
| 147 | #ifdef WIN32 | ||
| 148 | WaitForSingleObject(client->status_updater, INFINITE); | ||
| 149 | #else | ||
| 134 | pthread_join(client->status_updater, NULL); | 150 | pthread_join(client->status_updater, NULL); |
| 151 | #endif | ||
| 135 | } | 152 | } |
| 153 | #ifdef WIN32 | ||
| 154 | DeleteCriticalSection(&client->mutex); | ||
| 155 | #else | ||
| 136 | pthread_mutex_destroy(&client->mutex); | 156 | pthread_mutex_destroy(&client->mutex); |
| 157 | #endif | ||
| 137 | free(client); | 158 | free(client); |
| 138 | 159 | ||
| 139 | return INSTPROXY_E_SUCCESS; | 160 | return INSTPROXY_E_SUCCESS; |
| @@ -356,7 +377,11 @@ static void* instproxy_status_updater(void* arg) | |||
| 356 | if (data->operation) { | 377 | if (data->operation) { |
| 357 | free(data->operation); | 378 | free(data->operation); |
| 358 | } | 379 | } |
| 380 | #ifdef WIN32 | ||
| 381 | data->client->status_updater = NULL; | ||
| 382 | #else | ||
| 359 | data->client->status_updater = (pthread_t)NULL; | 383 | data->client->status_updater = (pthread_t)NULL; |
| 384 | #endif | ||
| 360 | instproxy_unlock(data->client); | 385 | instproxy_unlock(data->client); |
| 361 | free(data); | 386 | free(data); |
| 362 | 387 | ||
| @@ -391,9 +416,18 @@ static instproxy_error_t instproxy_create_status_updater(instproxy_client_t clie | |||
| 391 | data->operation = strdup(operation); | 416 | data->operation = strdup(operation); |
| 392 | data->user_data = user_data; | 417 | data->user_data = user_data; |
| 393 | 418 | ||
| 419 | #ifdef WIN32 | ||
| 420 | client->status_updater = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)instproxy_status_updater, data, 0, NULL); | ||
| 421 | if (client->status_updater != INVALID_HANDLE_VALUE) { | ||
| 422 | res = INSTPROXY_E_SUCCESS; | ||
| 423 | } else { | ||
| 424 | client->status_updater = NULL; | ||
| 425 | } | ||
| 426 | #else | ||
| 394 | if (pthread_create(&client->status_updater, NULL, instproxy_status_updater, data) == 0) { | 427 | if (pthread_create(&client->status_updater, NULL, instproxy_status_updater, data) == 0) { |
| 395 | res = INSTPROXY_E_SUCCESS; | 428 | res = INSTPROXY_E_SUCCESS; |
| 396 | } | 429 | } |
| 430 | #endif | ||
| 397 | } | 431 | } |
| 398 | } else { | 432 | } else { |
| 399 | /* sync mode */ | 433 | /* sync mode */ |
