diff options
| author | 2011-09-10 19:08:39 +0200 | |
|---|---|---|
| committer | 2012-03-19 01:38:54 +0100 | |
| commit | 475c9679716eec92e3508063b7486e3508c4c974 (patch) | |
| tree | 5ab09c85387821e05b052cbb642b92ae102953ec | |
| parent | 6f29ab73053327066409744d025dcbd03fd6b627 (diff) | |
| download | libimobiledevice-475c9679716eec92e3508063b7486e3508c4c974.tar.gz libimobiledevice-475c9679716eec92e3508063b7486e3508c4c974.tar.bz2 | |
WIN32: use windows threads and mutexes instead of pthread_*
| -rw-r--r-- | src/afc.c | 18 | ||||
| -rw-r--r-- | src/afc.h | 8 | ||||
| -rw-r--r-- | src/installation_proxy.c | 34 | ||||
| -rw-r--r-- | src/installation_proxy.h | 9 | ||||
| -rw-r--r-- | src/mobile_image_mounter.c | 16 | ||||
| -rw-r--r-- | src/mobile_image_mounter.h | 8 | ||||
| -rw-r--r-- | src/notification_proxy.c | 36 | ||||
| -rw-r--r-- | src/notification_proxy.h | 9 | ||||
| -rw-r--r-- | src/sbservices.c | 16 | ||||
| -rw-r--r-- | src/sbservices.h | 8 |
10 files changed, 161 insertions, 1 deletions
| @@ -42,7 +42,11 @@ static const int MAXIMUM_PACKET_SIZE = (2 << 15); | |||
| 42 | static void afc_lock(afc_client_t client) | 42 | static void afc_lock(afc_client_t client) |
| 43 | { | 43 | { |
| 44 | debug_info("Locked"); | 44 | debug_info("Locked"); |
| 45 | #ifdef WIN32 | ||
| 46 | EnterCriticalSection(&client->mutex); | ||
| 47 | #else | ||
| 45 | pthread_mutex_lock(&client->mutex); | 48 | pthread_mutex_lock(&client->mutex); |
| 49 | #endif | ||
| 46 | } | 50 | } |
| 47 | 51 | ||
| 48 | /** | 52 | /** |
| @@ -53,7 +57,11 @@ static void afc_lock(afc_client_t client) | |||
| 53 | static void afc_unlock(afc_client_t client) | 57 | static void afc_unlock(afc_client_t client) |
| 54 | { | 58 | { |
| 55 | debug_info("Unlocked"); | 59 | debug_info("Unlocked"); |
| 60 | #ifdef WIN32 | ||
| 61 | LeaveCriticalSection(&client->mutex); | ||
| 62 | #else | ||
| 56 | pthread_mutex_unlock(&client->mutex); | 63 | pthread_mutex_unlock(&client->mutex); |
| 64 | #endif | ||
| 57 | } | 65 | } |
| 58 | 66 | ||
| 59 | /** | 67 | /** |
| @@ -92,7 +100,11 @@ afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_ | |||
| 92 | memcpy(client_loc->afc_packet->magic, AFC_MAGIC, AFC_MAGIC_LEN); | 100 | memcpy(client_loc->afc_packet->magic, AFC_MAGIC, AFC_MAGIC_LEN); |
| 93 | client_loc->file_handle = 0; | 101 | client_loc->file_handle = 0; |
| 94 | client_loc->lock = 0; | 102 | client_loc->lock = 0; |
| 103 | #ifdef WIN32 | ||
| 104 | InitializeCriticalSection(&client_loc->mutex); | ||
| 105 | #else | ||
| 95 | pthread_mutex_init(&client_loc->mutex, NULL); | 106 | pthread_mutex_init(&client_loc->mutex, NULL); |
| 107 | #endif | ||
| 96 | 108 | ||
| 97 | *client = client_loc; | 109 | *client = client_loc; |
| 98 | return AFC_E_SUCCESS; | 110 | return AFC_E_SUCCESS; |
| @@ -150,7 +162,11 @@ afc_error_t afc_client_free(afc_client_t client) | |||
| 150 | client->connection = NULL; | 162 | client->connection = NULL; |
| 151 | } | 163 | } |
| 152 | free(client->afc_packet); | 164 | free(client->afc_packet); |
| 165 | #ifdef WIN32 | ||
| 166 | DeleteCriticalSection(&client->mutex); | ||
| 167 | #else | ||
| 153 | pthread_mutex_destroy(&client->mutex); | 168 | pthread_mutex_destroy(&client->mutex); |
| 169 | #endif | ||
| 154 | free(client); | 170 | free(client); |
| 155 | return AFC_E_SUCCESS; | 171 | return AFC_E_SUCCESS; |
| 156 | } | 172 | } |
| @@ -402,7 +418,9 @@ static afc_error_t afc_receive_data(afc_client_t client, char **dump_here, uint3 | |||
| 402 | *bytes_recv = 0; | 418 | *bytes_recv = 0; |
| 403 | 419 | ||
| 404 | debug_info("WARNING: Unknown operation code received 0x%llx param1=%lld", header.operation, param1); | 420 | debug_info("WARNING: Unknown operation code received 0x%llx param1=%lld", header.operation, param1); |
| 421 | #ifndef WIN32 | ||
| 405 | fprintf(stderr, "%s: WARNING: Unknown operation code received 0x%llx param1=%lld", __func__, (long long)header.operation, (long long)param1); | 422 | fprintf(stderr, "%s: WARNING: Unknown operation code received 0x%llx param1=%lld", __func__, (long long)header.operation, (long long)param1); |
| 423 | #endif | ||
| 406 | 424 | ||
| 407 | return AFC_E_OP_NOT_SUPPORTED; | 425 | return AFC_E_OP_NOT_SUPPORTED; |
| 408 | } | 426 | } |
| @@ -20,7 +20,11 @@ | |||
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #include <stdint.h> | 22 | #include <stdint.h> |
| 23 | #ifdef WIN32 | ||
| 24 | #include <windows.h> | ||
| 25 | #else | ||
| 23 | #include <pthread.h> | 26 | #include <pthread.h> |
| 27 | #endif | ||
| 24 | 28 | ||
| 25 | #include "libimobiledevice/afc.h" | 29 | #include "libimobiledevice/afc.h" |
| 26 | 30 | ||
| @@ -53,7 +57,11 @@ struct afc_client_private { | |||
| 53 | AFCPacket *afc_packet; | 57 | AFCPacket *afc_packet; |
| 54 | int file_handle; | 58 | int file_handle; |
| 55 | int lock; | 59 | int lock; |
| 60 | #ifdef WIN32 | ||
| 61 | CRITICAL_SECTION mutex; | ||
| 62 | #else | ||
| 56 | pthread_mutex_t mutex; | 63 | pthread_mutex_t mutex; |
| 64 | #endif | ||
| 57 | int own_connection; | 65 | int own_connection; |
| 58 | }; | 66 | }; |
| 59 | 67 | ||
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 */ |
diff --git a/src/installation_proxy.h b/src/installation_proxy.h index 811ead6..642968d 100644 --- a/src/installation_proxy.h +++ b/src/installation_proxy.h | |||
| @@ -21,15 +21,24 @@ | |||
| 21 | #ifndef IINSTALLATION_PROXY_H | 21 | #ifndef IINSTALLATION_PROXY_H |
| 22 | #define IINSTALLATION_PROXY_H | 22 | #define IINSTALLATION_PROXY_H |
| 23 | 23 | ||
| 24 | #ifdef WIN32 | ||
| 25 | #include <windows.h> | ||
| 26 | #else | ||
| 24 | #include <pthread.h> | 27 | #include <pthread.h> |
| 28 | #endif | ||
| 25 | 29 | ||
| 26 | #include "libimobiledevice/installation_proxy.h" | 30 | #include "libimobiledevice/installation_proxy.h" |
| 27 | #include "property_list_service.h" | 31 | #include "property_list_service.h" |
| 28 | 32 | ||
| 29 | struct instproxy_client_private { | 33 | struct instproxy_client_private { |
| 30 | property_list_service_client_t parent; | 34 | property_list_service_client_t parent; |
| 35 | #ifdef WIN32 | ||
| 36 | CRITICAL_SECTION mutex; | ||
| 37 | HANDLE status_updater; | ||
| 38 | #else | ||
| 31 | pthread_mutex_t mutex; | 39 | pthread_mutex_t mutex; |
| 32 | pthread_t status_updater; | 40 | pthread_t status_updater; |
| 41 | #endif | ||
| 33 | }; | 42 | }; |
| 34 | 43 | ||
| 35 | #endif | 44 | #endif |
diff --git a/src/mobile_image_mounter.c b/src/mobile_image_mounter.c index 18caf73..557fbda 100644 --- a/src/mobile_image_mounter.c +++ b/src/mobile_image_mounter.c | |||
| @@ -35,7 +35,11 @@ | |||
| 35 | */ | 35 | */ |
| 36 | static void mobile_image_mounter_lock(mobile_image_mounter_client_t client) | 36 | static void mobile_image_mounter_lock(mobile_image_mounter_client_t client) |
| 37 | { | 37 | { |
| 38 | #ifdef WIN32 | ||
| 39 | EnterCriticalSection(&client->mutex); | ||
| 40 | #else | ||
| 38 | pthread_mutex_lock(&client->mutex); | 41 | pthread_mutex_lock(&client->mutex); |
| 42 | #endif | ||
| 39 | } | 43 | } |
| 40 | 44 | ||
| 41 | /** | 45 | /** |
| @@ -45,7 +49,11 @@ static void mobile_image_mounter_lock(mobile_image_mounter_client_t client) | |||
| 45 | */ | 49 | */ |
| 46 | static void mobile_image_mounter_unlock(mobile_image_mounter_client_t client) | 50 | static void mobile_image_mounter_unlock(mobile_image_mounter_client_t client) |
| 47 | { | 51 | { |
| 52 | #ifdef WIN32 | ||
| 53 | LeaveCriticalSection(&client->mutex); | ||
| 54 | #else | ||
| 48 | pthread_mutex_unlock(&client->mutex); | 55 | pthread_mutex_unlock(&client->mutex); |
| 56 | #endif | ||
| 49 | } | 57 | } |
| 50 | 58 | ||
| 51 | /** | 59 | /** |
| @@ -101,7 +109,11 @@ mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, uint16_t | |||
| 101 | mobile_image_mounter_client_t client_loc = (mobile_image_mounter_client_t) malloc(sizeof(struct mobile_image_mounter_client_private)); | 109 | mobile_image_mounter_client_t client_loc = (mobile_image_mounter_client_t) malloc(sizeof(struct mobile_image_mounter_client_private)); |
| 102 | client_loc->parent = plistclient; | 110 | client_loc->parent = plistclient; |
| 103 | 111 | ||
| 112 | #ifdef WIN32 | ||
| 113 | InitializeCriticalSection(&client_loc->mutex); | ||
| 114 | #else | ||
| 104 | pthread_mutex_init(&client_loc->mutex, NULL); | 115 | pthread_mutex_init(&client_loc->mutex, NULL); |
| 116 | #endif | ||
| 105 | 117 | ||
| 106 | *client = client_loc; | 118 | *client = client_loc; |
| 107 | return MOBILE_IMAGE_MOUNTER_E_SUCCESS; | 119 | return MOBILE_IMAGE_MOUNTER_E_SUCCESS; |
| @@ -123,7 +135,11 @@ mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_clie | |||
| 123 | 135 | ||
| 124 | property_list_service_client_free(client->parent); | 136 | property_list_service_client_free(client->parent); |
| 125 | client->parent = NULL; | 137 | client->parent = NULL; |
| 138 | #ifdef WIN32 | ||
| 139 | DeleteCriticalSection(&client->mutex); | ||
| 140 | #else | ||
| 126 | pthread_mutex_destroy(&client->mutex); | 141 | pthread_mutex_destroy(&client->mutex); |
| 142 | #endif | ||
| 127 | free(client); | 143 | free(client); |
| 128 | 144 | ||
| 129 | return MOBILE_IMAGE_MOUNTER_E_SUCCESS; | 145 | return MOBILE_IMAGE_MOUNTER_E_SUCCESS; |
diff --git a/src/mobile_image_mounter.h b/src/mobile_image_mounter.h index e0828f9..ff0690d 100644 --- a/src/mobile_image_mounter.h +++ b/src/mobile_image_mounter.h | |||
| @@ -21,14 +21,22 @@ | |||
| 21 | #ifndef IMOBILE_IMAGE_MOUNTER_H | 21 | #ifndef IMOBILE_IMAGE_MOUNTER_H |
| 22 | #define IMOBILE_IMAGE_MOUNTER_H | 22 | #define IMOBILE_IMAGE_MOUNTER_H |
| 23 | 23 | ||
| 24 | #ifdef WIN32 | ||
| 25 | #include <windows.h> | ||
| 26 | #else | ||
| 24 | #include <pthread.h> | 27 | #include <pthread.h> |
| 28 | #endif | ||
| 25 | 29 | ||
| 26 | #include "libimobiledevice/mobile_image_mounter.h" | 30 | #include "libimobiledevice/mobile_image_mounter.h" |
| 27 | #include "property_list_service.h" | 31 | #include "property_list_service.h" |
| 28 | 32 | ||
| 29 | struct mobile_image_mounter_client_private { | 33 | struct mobile_image_mounter_client_private { |
| 30 | property_list_service_client_t parent; | 34 | property_list_service_client_t parent; |
| 35 | #ifdef WIN32 | ||
| 36 | CRITICAL_SECTION mutex; | ||
| 37 | #else | ||
| 31 | pthread_mutex_t mutex; | 38 | pthread_mutex_t mutex; |
| 39 | #endif | ||
| 32 | }; | 40 | }; |
| 33 | 41 | ||
| 34 | #endif | 42 | #endif |
diff --git a/src/notification_proxy.c b/src/notification_proxy.c index 792a165..086dec4 100644 --- a/src/notification_proxy.c +++ b/src/notification_proxy.c | |||
| @@ -42,7 +42,11 @@ struct np_thread { | |||
| 42 | static void np_lock(np_client_t client) | 42 | static void np_lock(np_client_t client) |
| 43 | { | 43 | { |
| 44 | debug_info("NP: Locked"); | 44 | debug_info("NP: Locked"); |
| 45 | #ifdef WIN32 | ||
| 46 | EnterCriticalSection(&client->mutex); | ||
| 47 | #else | ||
| 45 | pthread_mutex_lock(&client->mutex); | 48 | pthread_mutex_lock(&client->mutex); |
| 49 | #endif | ||
| 46 | } | 50 | } |
| 47 | 51 | ||
| 48 | /** | 52 | /** |
| @@ -53,7 +57,11 @@ static void np_lock(np_client_t client) | |||
| 53 | static void np_unlock(np_client_t client) | 57 | static void np_unlock(np_client_t client) |
| 54 | { | 58 | { |
| 55 | debug_info("NP: Unlocked"); | 59 | debug_info("NP: Unlocked"); |
| 60 | #ifdef WIN32 | ||
| 61 | LeaveCriticalSection(&client->mutex); | ||
| 62 | #else | ||
| 56 | pthread_mutex_unlock(&client->mutex); | 63 | pthread_mutex_unlock(&client->mutex); |
| 64 | #endif | ||
| 57 | } | 65 | } |
| 58 | 66 | ||
| 59 | /** | 67 | /** |
| @@ -107,9 +115,13 @@ np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client) | |||
| 107 | np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_private)); | 115 | np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_private)); |
| 108 | client_loc->parent = plistclient; | 116 | client_loc->parent = plistclient; |
| 109 | 117 | ||
| 118 | #ifdef WIN32 | ||
| 119 | InitializeCriticalSection(&client_loc->mutex); | ||
| 120 | client_loc->notifier = NULL; | ||
| 121 | #else | ||
| 110 | pthread_mutex_init(&client_loc->mutex, NULL); | 122 | pthread_mutex_init(&client_loc->mutex, NULL); |
| 111 | |||
| 112 | client_loc->notifier = (pthread_t)NULL; | 123 | client_loc->notifier = (pthread_t)NULL; |
| 124 | #endif | ||
| 113 | 125 | ||
| 114 | *client = client_loc; | 126 | *client = client_loc; |
| 115 | return NP_E_SUCCESS; | 127 | return NP_E_SUCCESS; |
| @@ -132,9 +144,17 @@ np_error_t np_client_free(np_client_t client) | |||
| 132 | client->parent = NULL; | 144 | client->parent = NULL; |
| 133 | if (client->notifier) { | 145 | if (client->notifier) { |
| 134 | debug_info("joining np callback"); | 146 | debug_info("joining np callback"); |
| 147 | #ifdef WIN32 | ||
| 148 | WaitForSingleObject(client->notifier, INFINITE); | ||
| 149 | #else | ||
| 135 | pthread_join(client->notifier, NULL); | 150 | pthread_join(client->notifier, NULL); |
| 151 | #endif | ||
| 136 | } | 152 | } |
| 153 | #ifdef WIN32 | ||
| 154 | DeleteCriticalSection(&client->mutex); | ||
| 155 | #else | ||
| 137 | pthread_mutex_destroy(&client->mutex); | 156 | pthread_mutex_destroy(&client->mutex); |
| 157 | #endif | ||
| 138 | free(client); | 158 | free(client); |
| 139 | 159 | ||
| 140 | return NP_E_SUCCESS; | 160 | return NP_E_SUCCESS; |
| @@ -393,8 +413,13 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb, | |||
| 393 | debug_info("callback already set, removing\n"); | 413 | debug_info("callback already set, removing\n"); |
| 394 | property_list_service_client_t parent = client->parent; | 414 | property_list_service_client_t parent = client->parent; |
| 395 | client->parent = NULL; | 415 | client->parent = NULL; |
| 416 | #ifdef WIN32 | ||
| 417 | WaitForSingleObject(client->notifier, INFINITE); | ||
| 418 | client->notifier = NULL; | ||
| 419 | #else | ||
| 396 | pthread_join(client->notifier, NULL); | 420 | pthread_join(client->notifier, NULL); |
| 397 | client->notifier = (pthread_t)NULL; | 421 | client->notifier = (pthread_t)NULL; |
| 422 | #endif | ||
| 398 | client->parent = parent; | 423 | client->parent = parent; |
| 399 | } | 424 | } |
| 400 | 425 | ||
| @@ -405,9 +430,18 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb, | |||
| 405 | npt->cbfunc = notify_cb; | 430 | npt->cbfunc = notify_cb; |
| 406 | npt->user_data = user_data; | 431 | npt->user_data = user_data; |
| 407 | 432 | ||
| 433 | #ifdef WIN32 | ||
| 434 | client->notifier = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)np_notifier, npt, 0, NULL); | ||
| 435 | if (client->notifier != INVALID_HANDLE_VALUE) { | ||
| 436 | res = NP_E_SUCCESS; | ||
| 437 | } else { | ||
| 438 | client->notifier = NULL; | ||
| 439 | } | ||
| 440 | #else | ||
| 408 | if (pthread_create(&client->notifier, NULL, np_notifier, npt) == 0) { | 441 | if (pthread_create(&client->notifier, NULL, np_notifier, npt) == 0) { |
| 409 | res = NP_E_SUCCESS; | 442 | res = NP_E_SUCCESS; |
| 410 | } | 443 | } |
| 444 | #endif | ||
| 411 | } | 445 | } |
| 412 | } else { | 446 | } else { |
| 413 | debug_info("no callback set"); | 447 | debug_info("no callback set"); |
diff --git a/src/notification_proxy.h b/src/notification_proxy.h index 4a9cdad..0f92cdf 100644 --- a/src/notification_proxy.h +++ b/src/notification_proxy.h | |||
| @@ -21,15 +21,24 @@ | |||
| 21 | #ifndef INOTIFICATION_PROXY_H | 21 | #ifndef INOTIFICATION_PROXY_H |
| 22 | #define INOTIFICATION_PROXY_H | 22 | #define INOTIFICATION_PROXY_H |
| 23 | 23 | ||
| 24 | #ifdef WIN32 | ||
| 25 | #include <windows.h> | ||
| 26 | #else | ||
| 24 | #include <pthread.h> | 27 | #include <pthread.h> |
| 28 | #endif | ||
| 25 | 29 | ||
| 26 | #include "libimobiledevice/notification_proxy.h" | 30 | #include "libimobiledevice/notification_proxy.h" |
| 27 | #include "property_list_service.h" | 31 | #include "property_list_service.h" |
| 28 | 32 | ||
| 29 | struct np_client_private { | 33 | struct np_client_private { |
| 30 | property_list_service_client_t parent; | 34 | property_list_service_client_t parent; |
| 35 | #ifdef WIN32 | ||
| 36 | CRITICAL_SECTION mutex; | ||
| 37 | HANDLE notifier; | ||
| 38 | #else | ||
| 31 | pthread_mutex_t mutex; | 39 | pthread_mutex_t mutex; |
| 32 | pthread_t notifier; | 40 | pthread_t notifier; |
| 41 | #endif | ||
| 33 | }; | 42 | }; |
| 34 | 43 | ||
| 35 | void* np_notifier(void* arg); | 44 | void* np_notifier(void* arg); |
diff --git a/src/sbservices.c b/src/sbservices.c index dd5f571..7f050bf 100644 --- a/src/sbservices.c +++ b/src/sbservices.c | |||
| @@ -36,7 +36,11 @@ | |||
| 36 | static void sbs_lock(sbservices_client_t client) | 36 | static void sbs_lock(sbservices_client_t client) |
| 37 | { | 37 | { |
| 38 | debug_info("SBServices: Locked"); | 38 | debug_info("SBServices: Locked"); |
| 39 | #ifdef WIN32 | ||
| 40 | EnterCriticalSection(&client->mutex); | ||
| 41 | #else | ||
| 39 | pthread_mutex_lock(&client->mutex); | 42 | pthread_mutex_lock(&client->mutex); |
| 43 | #endif | ||
| 40 | } | 44 | } |
| 41 | 45 | ||
| 42 | /** | 46 | /** |
| @@ -47,7 +51,11 @@ static void sbs_lock(sbservices_client_t client) | |||
| 47 | static void sbs_unlock(sbservices_client_t client) | 51 | static void sbs_unlock(sbservices_client_t client) |
| 48 | { | 52 | { |
| 49 | debug_info("SBServices: Unlocked"); | 53 | debug_info("SBServices: Unlocked"); |
| 54 | #ifdef WIN32 | ||
| 55 | LeaveCriticalSection(&client->mutex); | ||
| 56 | #else | ||
| 50 | pthread_mutex_unlock(&client->mutex); | 57 | pthread_mutex_unlock(&client->mutex); |
| 58 | #endif | ||
| 51 | } | 59 | } |
| 52 | 60 | ||
| 53 | /** | 61 | /** |
| @@ -100,7 +108,11 @@ sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbserv | |||
| 100 | 108 | ||
| 101 | sbservices_client_t client_loc = (sbservices_client_t) malloc(sizeof(struct sbservices_client_private)); | 109 | sbservices_client_t client_loc = (sbservices_client_t) malloc(sizeof(struct sbservices_client_private)); |
| 102 | client_loc->parent = plistclient; | 110 | client_loc->parent = plistclient; |
| 111 | #ifdef WIN32 | ||
| 112 | InitializeCriticalSection(&client_loc->mutex); | ||
| 113 | #else | ||
| 103 | pthread_mutex_init(&client_loc->mutex, NULL); | 114 | pthread_mutex_init(&client_loc->mutex, NULL); |
| 115 | #endif | ||
| 104 | 116 | ||
| 105 | *client = client_loc; | 117 | *client = client_loc; |
| 106 | return SBSERVICES_E_SUCCESS; | 118 | return SBSERVICES_E_SUCCESS; |
| @@ -122,7 +134,11 @@ sbservices_error_t sbservices_client_free(sbservices_client_t client) | |||
| 122 | 134 | ||
| 123 | sbservices_error_t err = sbservices_error(property_list_service_client_free(client->parent)); | 135 | sbservices_error_t err = sbservices_error(property_list_service_client_free(client->parent)); |
| 124 | client->parent = NULL; | 136 | client->parent = NULL; |
| 137 | #ifdef WIN32 | ||
| 138 | DeleteCriticalSection(&client->mutex); | ||
| 139 | #else | ||
| 125 | pthread_mutex_destroy(&client->mutex); | 140 | pthread_mutex_destroy(&client->mutex); |
| 141 | #endif | ||
| 126 | free(client); | 142 | free(client); |
| 127 | 143 | ||
| 128 | return err; | 144 | return err; |
diff --git a/src/sbservices.h b/src/sbservices.h index 1c85fe8..2b600ad 100644 --- a/src/sbservices.h +++ b/src/sbservices.h | |||
| @@ -21,14 +21,22 @@ | |||
| 21 | #ifndef ISBSERVICES_H | 21 | #ifndef ISBSERVICES_H |
| 22 | #define ISBSERVICES_H | 22 | #define ISBSERVICES_H |
| 23 | 23 | ||
| 24 | #ifdef WIN32 | ||
| 25 | #include <windows.h> | ||
| 26 | #else | ||
| 24 | #include <pthread.h> | 27 | #include <pthread.h> |
| 28 | #endif | ||
| 25 | 29 | ||
| 26 | #include "libimobiledevice/sbservices.h" | 30 | #include "libimobiledevice/sbservices.h" |
| 27 | #include "property_list_service.h" | 31 | #include "property_list_service.h" |
| 28 | 32 | ||
| 29 | struct sbservices_client_private { | 33 | struct sbservices_client_private { |
| 30 | property_list_service_client_t parent; | 34 | property_list_service_client_t parent; |
| 35 | #ifdef WIN32 | ||
| 36 | CRITICAL_SECTION mutex; | ||
| 37 | #else | ||
| 31 | pthread_mutex_t mutex; | 38 | pthread_mutex_t mutex; |
| 39 | #endif | ||
| 32 | }; | 40 | }; |
| 33 | 41 | ||
| 34 | #endif | 42 | #endif |
