diff options
| author | 2011-09-10 19:08:39 +0200 | |
|---|---|---|
| committer | 2012-03-19 01:38:54 +0100 | |
| commit | 475c9679716eec92e3508063b7486e3508c4c974 (patch) | |
| tree | 5ab09c85387821e05b052cbb642b92ae102953ec /src/notification_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/notification_proxy.c')
| -rw-r--r-- | src/notification_proxy.c | 36 |
1 files changed, 35 insertions, 1 deletions
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"); |
