diff options
| author | 2013-03-20 05:38:06 +0100 | |
|---|---|---|
| committer | 2013-03-20 05:38:06 +0100 | |
| commit | b2924a1549d874fb86deaad5fd2438e567c65bf4 (patch) | |
| tree | ead89f885a0492cdfc228a1c25326912e7d9b973 | |
| parent | efca491e4c19868a68a099638552f9ba431dca4b (diff) | |
| download | libimobiledevice-b2924a1549d874fb86deaad5fd2438e567c65bf4.tar.gz libimobiledevice-b2924a1549d874fb86deaad5fd2438e567c65bf4.tar.bz2 | |
use new internal common code for thread, mutex, and socket operations
| -rw-r--r-- | dev/afccheck.c | 10 | ||||
| -rw-r--r-- | src/Makefile.am | 2 | ||||
| -rw-r--r-- | src/afc.c | 24 | ||||
| -rw-r--r-- | src/afc.h | 12 | ||||
| -rw-r--r-- | src/installation_proxy.c | 46 | ||||
| -rw-r--r-- | src/installation_proxy.h | 16 | ||||
| -rw-r--r-- | src/mobile_image_mounter.c | 24 | ||||
| -rw-r--r-- | src/mobile_image_mounter.h | 13 | ||||
| -rw-r--r-- | src/notification_proxy.c | 49 | ||||
| -rw-r--r-- | src/notification_proxy.h | 16 | ||||
| -rw-r--r-- | src/sbservices.c | 24 | ||||
| -rw-r--r-- | src/sbservices.h | 13 | ||||
| -rw-r--r-- | tools/Makefile.am | 2 | ||||
| -rw-r--r-- | tools/idevicesyslog.c | 29 |
14 files changed, 50 insertions, 230 deletions
diff --git a/dev/afccheck.c b/dev/afccheck.c index 665aa47..3eb53c8 100644 --- a/dev/afccheck.c +++ b/dev/afccheck.c | |||
| @@ -22,11 +22,11 @@ | |||
| 22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
| 23 | #include <stdio.h> | 23 | #include <stdio.h> |
| 24 | #include <string.h> | 24 | #include <string.h> |
| 25 | #include <pthread.h> | ||
| 26 | 25 | ||
| 27 | #include <libimobiledevice/libimobiledevice.h> | 26 | #include <libimobiledevice/libimobiledevice.h> |
| 28 | #include <libimobiledevice/lockdown.h> | 27 | #include <libimobiledevice/lockdown.h> |
| 29 | #include <libimobiledevice/afc.h> | 28 | #include <libimobiledevice/afc.h> |
| 29 | #include "common/thread.h" | ||
| 30 | 30 | ||
| 31 | #define BUFFER_SIZE 20000 | 31 | #define BUFFER_SIZE 20000 |
| 32 | #define NB_THREADS 10 | 32 | #define NB_THREADS 10 |
| @@ -85,7 +85,7 @@ static void* check_afc(void *data) | |||
| 85 | 85 | ||
| 86 | //cleanup | 86 | //cleanup |
| 87 | afc_remove_path(((param *) data)->afc, path); | 87 | afc_remove_path(((param *) data)->afc, path); |
| 88 | pthread_exit(0); | 88 | return NULL; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | int main(int argc, char *argv[]) | 91 | int main(int argc, char *argv[]) |
| @@ -125,18 +125,18 @@ int main(int argc, char *argv[]) | |||
| 125 | service = NULL; | 125 | service = NULL; |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | pthread_t threads[NB_THREADS]; | 128 | thread_t threads[NB_THREADS]; |
| 129 | param data[NB_THREADS]; | 129 | param data[NB_THREADS]; |
| 130 | 130 | ||
| 131 | int i = 0; | 131 | int i = 0; |
| 132 | for (i = 0; i < NB_THREADS; i++) { | 132 | for (i = 0; i < NB_THREADS; i++) { |
| 133 | data[i].afc = afc; | 133 | data[i].afc = afc; |
| 134 | data[i].id = i + 1; | 134 | data[i].id = i + 1; |
| 135 | pthread_create(&threads[i], NULL, check_afc, data + i); | 135 | thread_create(&threads[i], check_afc, data + i); |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | for (i = 0; i < NB_THREADS; i++) { | 138 | for (i = 0; i < NB_THREADS; i++) { |
| 139 | pthread_join(threads[i], NULL); | 139 | thread_join(threads[i]); |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | lockdownd_client_free(client); | 142 | lockdownd_client_free(client); |
diff --git a/src/Makefile.am b/src/Makefile.am index 574075e..66be29f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am | |||
| @@ -4,7 +4,7 @@ AM_CFLAGS = $(GLOBAL_CFLAGS) $(libusbmuxd_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1 | |||
| 4 | AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(libplist_LIBS) $(libusbmuxd_LIBS) $(libgcrypt_LIBS) ${libpthread_LIBS} $(openssl_LIBS) | 4 | AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(libplist_LIBS) $(libusbmuxd_LIBS) $(libgcrypt_LIBS) ${libpthread_LIBS} $(openssl_LIBS) |
| 5 | 5 | ||
| 6 | lib_LTLIBRARIES = libimobiledevice.la | 6 | lib_LTLIBRARIES = libimobiledevice.la |
| 7 | libimobiledevice_la_LIBADD = | 7 | libimobiledevice_la_LIBADD = $(top_srcdir)/common/libinternalcommon.la |
| 8 | libimobiledevice_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBIMOBILEDEVICE_SO_VERSION) -no-undefined | 8 | libimobiledevice_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBIMOBILEDEVICE_SO_VERSION) -no-undefined |
| 9 | libimobiledevice_la_SOURCES = idevice.c idevice.h \ | 9 | libimobiledevice_la_SOURCES = idevice.c idevice.h \ |
| 10 | debug.c debug.h\ | 10 | debug.c debug.h\ |
| @@ -43,11 +43,7 @@ static const int MAXIMUM_PACKET_SIZE = (2 << 15); | |||
| 43 | static void afc_lock(afc_client_t client) | 43 | static void afc_lock(afc_client_t client) |
| 44 | { | 44 | { |
| 45 | debug_info("Locked"); | 45 | debug_info("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 afc_lock(afc_client_t client) | |||
| 58 | static void afc_unlock(afc_client_t client) | 54 | static void afc_unlock(afc_client_t client) |
| 59 | { | 55 | { |
| 60 | debug_info("Unlocked"); | 56 | debug_info("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 | /** |
| @@ -99,11 +91,7 @@ afc_error_t afc_client_new_with_service_client(service_client_t service_client, | |||
| 99 | memcpy(client_loc->afc_packet->magic, AFC_MAGIC, AFC_MAGIC_LEN); | 91 | memcpy(client_loc->afc_packet->magic, AFC_MAGIC, AFC_MAGIC_LEN); |
| 100 | client_loc->file_handle = 0; | 92 | client_loc->file_handle = 0; |
| 101 | client_loc->lock = 0; | 93 | client_loc->lock = 0; |
| 102 | #ifdef WIN32 | 94 | mutex_init(&client_loc->mutex); |
| 103 | InitializeCriticalSection(&client_loc->mutex); | ||
| 104 | #else | ||
| 105 | pthread_mutex_init(&client_loc->mutex, NULL); | ||
| 106 | #endif | ||
| 107 | 95 | ||
| 108 | *client = client_loc; | 96 | *client = client_loc; |
| 109 | return AFC_E_SUCCESS; | 97 | return AFC_E_SUCCESS; |
| @@ -156,11 +144,7 @@ afc_error_t afc_client_free(afc_client_t client) | |||
| 156 | client->parent = NULL; | 144 | client->parent = NULL; |
| 157 | } | 145 | } |
| 158 | free(client->afc_packet); | 146 | free(client->afc_packet); |
| 159 | #ifdef WIN32 | 147 | mutex_destroy(&client->mutex); |
| 160 | DeleteCriticalSection(&client->mutex); | ||
| 161 | #else | ||
| 162 | pthread_mutex_destroy(&client->mutex); | ||
| 163 | #endif | ||
| 164 | free(client); | 148 | free(client); |
| 165 | return AFC_E_SUCCESS; | 149 | return AFC_E_SUCCESS; |
| 166 | } | 150 | } |
| @@ -23,15 +23,11 @@ | |||
| 23 | #define __AFC_H | 23 | #define __AFC_H |
| 24 | 24 | ||
| 25 | #include <stdint.h> | 25 | #include <stdint.h> |
| 26 | #ifdef WIN32 | ||
| 27 | #include <windows.h> | ||
| 28 | #else | ||
| 29 | #include <pthread.h> | ||
| 30 | #endif | ||
| 31 | 26 | ||
| 32 | #include "libimobiledevice/afc.h" | 27 | #include "libimobiledevice/afc.h" |
| 33 | #include "service.h" | 28 | #include "service.h" |
| 34 | #include "endianness.h" | 29 | #include "endianness.h" |
| 30 | #include "common/thread.h" | ||
| 35 | 31 | ||
| 36 | #define AFC_MAGIC "CFA6LPAA" | 32 | #define AFC_MAGIC "CFA6LPAA" |
| 37 | #define AFC_MAGIC_LEN (8) | 33 | #define AFC_MAGIC_LEN (8) |
| @@ -62,11 +58,7 @@ struct afc_client_private { | |||
| 62 | AFCPacket *afc_packet; | 58 | AFCPacket *afc_packet; |
| 63 | int file_handle; | 59 | int file_handle; |
| 64 | int lock; | 60 | int lock; |
| 65 | #ifdef WIN32 | 61 | mutex_t mutex; |
| 66 | CRITICAL_SECTION mutex; | ||
| 67 | #else | ||
| 68 | pthread_mutex_t mutex; | ||
| 69 | #endif | ||
| 70 | int free_parent; | 62 | int free_parent; |
| 71 | }; | 63 | }; |
| 72 | 64 | ||
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 { | |||
| 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 | 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) | |||
| 58 | static void instproxy_unlock(instproxy_client_t client) | 54 | static 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 */ |
diff --git a/src/installation_proxy.h b/src/installation_proxy.h index 40175a0..4f79c12 100644 --- a/src/installation_proxy.h +++ b/src/installation_proxy.h | |||
| @@ -22,24 +22,14 @@ | |||
| 22 | #ifndef __INSTALLATION_PROXY_H | 22 | #ifndef __INSTALLATION_PROXY_H |
| 23 | #define __INSTALLATION_PROXY_H | 23 | #define __INSTALLATION_PROXY_H |
| 24 | 24 | ||
| 25 | #ifdef WIN32 | ||
| 26 | #include <windows.h> | ||
| 27 | #else | ||
| 28 | #include <pthread.h> | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #include "libimobiledevice/installation_proxy.h" | 25 | #include "libimobiledevice/installation_proxy.h" |
| 32 | #include "property_list_service.h" | 26 | #include "property_list_service.h" |
| 27 | #include "common/thread.h" | ||
| 33 | 28 | ||
| 34 | struct instproxy_client_private { | 29 | struct instproxy_client_private { |
| 35 | property_list_service_client_t parent; | 30 | property_list_service_client_t parent; |
| 36 | #ifdef WIN32 | 31 | mutex_t mutex; |
| 37 | CRITICAL_SECTION mutex; | 32 | thread_t status_updater; |
| 38 | HANDLE status_updater; | ||
| 39 | #else | ||
| 40 | pthread_mutex_t mutex; | ||
| 41 | pthread_t status_updater; | ||
| 42 | #endif | ||
| 43 | }; | 33 | }; |
| 44 | 34 | ||
| 45 | #endif | 35 | #endif |
diff --git a/src/mobile_image_mounter.c b/src/mobile_image_mounter.c index 1d608db..209e367 100644 --- a/src/mobile_image_mounter.c +++ b/src/mobile_image_mounter.c | |||
| @@ -35,11 +35,7 @@ | |||
| 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 | 38 | mutex_lock(&client->mutex); |
| 39 | EnterCriticalSection(&client->mutex); | ||
| 40 | #else | ||
| 41 | pthread_mutex_lock(&client->mutex); | ||
| 42 | #endif | ||
| 43 | } | 39 | } |
| 44 | 40 | ||
| 45 | /** | 41 | /** |
| @@ -49,11 +45,7 @@ static void mobile_image_mounter_lock(mobile_image_mounter_client_t client) | |||
| 49 | */ | 45 | */ |
| 50 | static void mobile_image_mounter_unlock(mobile_image_mounter_client_t client) | 46 | static void mobile_image_mounter_unlock(mobile_image_mounter_client_t client) |
| 51 | { | 47 | { |
| 52 | #ifdef WIN32 | 48 | mutex_unlock(&client->mutex); |
| 53 | LeaveCriticalSection(&client->mutex); | ||
| 54 | #else | ||
| 55 | pthread_mutex_unlock(&client->mutex); | ||
| 56 | #endif | ||
| 57 | } | 49 | } |
| 58 | 50 | ||
| 59 | /** | 51 | /** |
| @@ -107,11 +99,7 @@ mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, lockdown | |||
| 107 | mobile_image_mounter_client_t client_loc = (mobile_image_mounter_client_t) malloc(sizeof(struct mobile_image_mounter_client_private)); | 99 | mobile_image_mounter_client_t client_loc = (mobile_image_mounter_client_t) malloc(sizeof(struct mobile_image_mounter_client_private)); |
| 108 | client_loc->parent = plistclient; | 100 | client_loc->parent = plistclient; |
| 109 | 101 | ||
| 110 | #ifdef WIN32 | 102 | mutex_init(&client_loc->mutex); |
| 111 | InitializeCriticalSection(&client_loc->mutex); | ||
| 112 | #else | ||
| 113 | pthread_mutex_init(&client_loc->mutex, NULL); | ||
| 114 | #endif | ||
| 115 | 103 | ||
| 116 | *client = client_loc; | 104 | *client = client_loc; |
| 117 | return MOBILE_IMAGE_MOUNTER_E_SUCCESS; | 105 | return MOBILE_IMAGE_MOUNTER_E_SUCCESS; |
| @@ -133,11 +121,7 @@ mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_clie | |||
| 133 | 121 | ||
| 134 | property_list_service_client_free(client->parent); | 122 | property_list_service_client_free(client->parent); |
| 135 | client->parent = NULL; | 123 | client->parent = NULL; |
| 136 | #ifdef WIN32 | 124 | mutex_destroy(&client->mutex); |
| 137 | DeleteCriticalSection(&client->mutex); | ||
| 138 | #else | ||
| 139 | pthread_mutex_destroy(&client->mutex); | ||
| 140 | #endif | ||
| 141 | free(client); | 125 | free(client); |
| 142 | 126 | ||
| 143 | return MOBILE_IMAGE_MOUNTER_E_SUCCESS; | 127 | return MOBILE_IMAGE_MOUNTER_E_SUCCESS; |
diff --git a/src/mobile_image_mounter.h b/src/mobile_image_mounter.h index 4056dc8..67cb589 100644 --- a/src/mobile_image_mounter.h +++ b/src/mobile_image_mounter.h | |||
| @@ -22,22 +22,13 @@ | |||
| 22 | #ifndef __MOBILE_IMAGE_MOUNTER_H | 22 | #ifndef __MOBILE_IMAGE_MOUNTER_H |
| 23 | #define __MOBILE_IMAGE_MOUNTER_H | 23 | #define __MOBILE_IMAGE_MOUNTER_H |
| 24 | 24 | ||
| 25 | #ifdef WIN32 | ||
| 26 | #include <windows.h> | ||
| 27 | #else | ||
| 28 | #include <pthread.h> | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #include "libimobiledevice/mobile_image_mounter.h" | 25 | #include "libimobiledevice/mobile_image_mounter.h" |
| 32 | #include "property_list_service.h" | 26 | #include "property_list_service.h" |
| 27 | #include "common/thread.h" | ||
| 33 | 28 | ||
| 34 | struct mobile_image_mounter_client_private { | 29 | struct mobile_image_mounter_client_private { |
| 35 | property_list_service_client_t parent; | 30 | property_list_service_client_t parent; |
| 36 | #ifdef WIN32 | 31 | mutex_t mutex; |
| 37 | CRITICAL_SECTION mutex; | ||
| 38 | #else | ||
| 39 | pthread_mutex_t mutex; | ||
| 40 | #endif | ||
| 41 | }; | 32 | }; |
| 42 | 33 | ||
| 43 | #endif | 34 | #endif |
diff --git a/src/notification_proxy.c b/src/notification_proxy.c index 5b293f8..952e5f2 100644 --- a/src/notification_proxy.c +++ b/src/notification_proxy.c | |||
| @@ -46,11 +46,7 @@ struct np_thread { | |||
| 46 | static void np_lock(np_client_t client) | 46 | static void np_lock(np_client_t client) |
| 47 | { | 47 | { |
| 48 | debug_info("NP: Locked"); | 48 | debug_info("NP: Locked"); |
| 49 | #ifdef WIN32 | 49 | mutex_lock(&client->mutex); |
| 50 | EnterCriticalSection(&client->mutex); | ||
| 51 | #else | ||
| 52 | pthread_mutex_lock(&client->mutex); | ||
| 53 | #endif | ||
| 54 | } | 50 | } |
| 55 | 51 | ||
| 56 | /** | 52 | /** |
| @@ -61,11 +57,7 @@ static void np_lock(np_client_t client) | |||
| 61 | static void np_unlock(np_client_t client) | 57 | static void np_unlock(np_client_t client) |
| 62 | { | 58 | { |
| 63 | debug_info("NP: Unlocked"); | 59 | debug_info("NP: Unlocked"); |
| 64 | #ifdef WIN32 | 60 | mutex_unlock(&client->mutex); |
| 65 | LeaveCriticalSection(&client->mutex); | ||
| 66 | #else | ||
| 67 | pthread_mutex_unlock(&client->mutex); | ||
| 68 | #endif | ||
| 69 | } | 61 | } |
| 70 | 62 | ||
| 71 | /** | 63 | /** |
| @@ -117,13 +109,8 @@ np_error_t np_client_new(idevice_t device, lockdownd_service_descriptor_t servic | |||
| 117 | np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_private)); | 109 | np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_private)); |
| 118 | client_loc->parent = plistclient; | 110 | client_loc->parent = plistclient; |
| 119 | 111 | ||
| 120 | #ifdef WIN32 | 112 | mutex_init(&client_loc->mutex); |
| 121 | InitializeCriticalSection(&client_loc->mutex); | ||
| 122 | client_loc->notifier = NULL; | 113 | client_loc->notifier = NULL; |
| 123 | #else | ||
| 124 | pthread_mutex_init(&client_loc->mutex, NULL); | ||
| 125 | client_loc->notifier = (pthread_t)NULL; | ||
| 126 | #endif | ||
| 127 | 114 | ||
| 128 | *client = client_loc; | 115 | *client = client_loc; |
| 129 | return NP_E_SUCCESS; | 116 | return NP_E_SUCCESS; |
| @@ -146,17 +133,9 @@ np_error_t np_client_free(np_client_t client) | |||
| 146 | client->parent = NULL; | 133 | client->parent = NULL; |
| 147 | if (client->notifier) { | 134 | if (client->notifier) { |
| 148 | debug_info("joining np callback"); | 135 | debug_info("joining np callback"); |
| 149 | #ifdef WIN32 | 136 | thread_join(client->notifier); |
| 150 | WaitForSingleObject(client->notifier, INFINITE); | ||
| 151 | #else | ||
| 152 | pthread_join(client->notifier, NULL); | ||
| 153 | #endif | ||
| 154 | } | 137 | } |
| 155 | #ifdef WIN32 | 138 | mutex_destroy(&client->mutex); |
| 156 | DeleteCriticalSection(&client->mutex); | ||
| 157 | #else | ||
| 158 | pthread_mutex_destroy(&client->mutex); | ||
| 159 | #endif | ||
| 160 | free(client); | 139 | free(client); |
| 161 | 140 | ||
| 162 | return NP_E_SUCCESS; | 141 | return NP_E_SUCCESS; |
| @@ -415,13 +394,8 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb, | |||
| 415 | debug_info("callback already set, removing\n"); | 394 | debug_info("callback already set, removing\n"); |
| 416 | property_list_service_client_t parent = client->parent; | 395 | property_list_service_client_t parent = client->parent; |
| 417 | client->parent = NULL; | 396 | client->parent = NULL; |
| 418 | #ifdef WIN32 | 397 | thread_join(client->notifier); |
| 419 | WaitForSingleObject(client->notifier, INFINITE); | ||
| 420 | client->notifier = NULL; | 398 | client->notifier = NULL; |
| 421 | #else | ||
| 422 | pthread_join(client->notifier, NULL); | ||
| 423 | client->notifier = (pthread_t)NULL; | ||
| 424 | #endif | ||
| 425 | client->parent = parent; | 399 | client->parent = parent; |
| 426 | } | 400 | } |
| 427 | 401 | ||
| @@ -432,18 +406,9 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb, | |||
| 432 | npt->cbfunc = notify_cb; | 406 | npt->cbfunc = notify_cb; |
| 433 | npt->user_data = user_data; | 407 | npt->user_data = user_data; |
| 434 | 408 | ||
| 435 | #ifdef WIN32 | 409 | if (thread_create(&client->notifier, np_notifier, npt) == 0) { |
| 436 | client->notifier = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)np_notifier, npt, 0, NULL); | ||
| 437 | if (client->notifier != INVALID_HANDLE_VALUE) { | ||
| 438 | res = NP_E_SUCCESS; | ||
| 439 | } else { | ||
| 440 | client->notifier = NULL; | ||
| 441 | } | ||
| 442 | #else | ||
| 443 | if (pthread_create(&client->notifier, NULL, np_notifier, npt) == 0) { | ||
| 444 | res = NP_E_SUCCESS; | 410 | res = NP_E_SUCCESS; |
| 445 | } | 411 | } |
| 446 | #endif | ||
| 447 | } | 412 | } |
| 448 | } else { | 413 | } else { |
| 449 | debug_info("no callback set"); | 414 | debug_info("no callback set"); |
diff --git a/src/notification_proxy.h b/src/notification_proxy.h index d8e9915..c2ded6a 100644 --- a/src/notification_proxy.h +++ b/src/notification_proxy.h | |||
| @@ -22,24 +22,14 @@ | |||
| 22 | #ifndef __NOTIFICATION_PROXY_H | 22 | #ifndef __NOTIFICATION_PROXY_H |
| 23 | #define __NOTIFICATION_PROXY_H | 23 | #define __NOTIFICATION_PROXY_H |
| 24 | 24 | ||
| 25 | #ifdef WIN32 | ||
| 26 | #include <windows.h> | ||
| 27 | #else | ||
| 28 | #include <pthread.h> | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #include "libimobiledevice/notification_proxy.h" | 25 | #include "libimobiledevice/notification_proxy.h" |
| 32 | #include "property_list_service.h" | 26 | #include "property_list_service.h" |
| 27 | #include "common/thread.h" | ||
| 33 | 28 | ||
| 34 | struct np_client_private { | 29 | struct np_client_private { |
| 35 | property_list_service_client_t parent; | 30 | property_list_service_client_t parent; |
| 36 | #ifdef WIN32 | 31 | mutex_t mutex; |
| 37 | CRITICAL_SECTION mutex; | 32 | thread_t notifier; |
| 38 | HANDLE notifier; | ||
| 39 | #else | ||
| 40 | pthread_mutex_t mutex; | ||
| 41 | pthread_t notifier; | ||
| 42 | #endif | ||
| 43 | }; | 33 | }; |
| 44 | 34 | ||
| 45 | void* np_notifier(void* arg); | 35 | void* np_notifier(void* arg); |
diff --git a/src/sbservices.c b/src/sbservices.c index 00f2862..1cd17db 100644 --- a/src/sbservices.c +++ b/src/sbservices.c | |||
| @@ -36,11 +36,7 @@ | |||
| 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 | 39 | mutex_lock(&client->mutex); |
| 40 | EnterCriticalSection(&client->mutex); | ||
| 41 | #else | ||
| 42 | pthread_mutex_lock(&client->mutex); | ||
| 43 | #endif | ||
| 44 | } | 40 | } |
| 45 | 41 | ||
| 46 | /** | 42 | /** |
| @@ -51,11 +47,7 @@ static void sbs_lock(sbservices_client_t client) | |||
| 51 | static void sbs_unlock(sbservices_client_t client) | 47 | static void sbs_unlock(sbservices_client_t client) |
| 52 | { | 48 | { |
| 53 | debug_info("SBServices: Unlocked"); | 49 | debug_info("SBServices: Unlocked"); |
| 54 | #ifdef WIN32 | 50 | mutex_unlock(&client->mutex); |
| 55 | LeaveCriticalSection(&client->mutex); | ||
| 56 | #else | ||
| 57 | pthread_mutex_unlock(&client->mutex); | ||
| 58 | #endif | ||
| 59 | } | 51 | } |
| 60 | 52 | ||
| 61 | /** | 53 | /** |
| @@ -105,11 +97,7 @@ sbservices_error_t sbservices_client_new(idevice_t device, lockdownd_service_des | |||
| 105 | 97 | ||
| 106 | sbservices_client_t client_loc = (sbservices_client_t) malloc(sizeof(struct sbservices_client_private)); | 98 | sbservices_client_t client_loc = (sbservices_client_t) malloc(sizeof(struct sbservices_client_private)); |
| 107 | client_loc->parent = plistclient; | 99 | client_loc->parent = plistclient; |
| 108 | #ifdef WIN32 | 100 | mutex_init(&client_loc->mutex); |
| 109 | InitializeCriticalSection(&client_loc->mutex); | ||
| 110 | #else | ||
| 111 | pthread_mutex_init(&client_loc->mutex, NULL); | ||
| 112 | #endif | ||
| 113 | 101 | ||
| 114 | *client = client_loc; | 102 | *client = client_loc; |
| 115 | return SBSERVICES_E_SUCCESS; | 103 | return SBSERVICES_E_SUCCESS; |
| @@ -131,11 +119,7 @@ sbservices_error_t sbservices_client_free(sbservices_client_t client) | |||
| 131 | 119 | ||
| 132 | sbservices_error_t err = sbservices_error(property_list_service_client_free(client->parent)); | 120 | sbservices_error_t err = sbservices_error(property_list_service_client_free(client->parent)); |
| 133 | client->parent = NULL; | 121 | client->parent = NULL; |
| 134 | #ifdef WIN32 | 122 | mutex_destroy(&client->mutex); |
| 135 | DeleteCriticalSection(&client->mutex); | ||
| 136 | #else | ||
| 137 | pthread_mutex_destroy(&client->mutex); | ||
| 138 | #endif | ||
| 139 | free(client); | 123 | free(client); |
| 140 | 124 | ||
| 141 | return err; | 125 | return err; |
diff --git a/src/sbservices.h b/src/sbservices.h index 598b794..ba64d67 100644 --- a/src/sbservices.h +++ b/src/sbservices.h | |||
| @@ -22,22 +22,13 @@ | |||
| 22 | #ifndef __SBSERVICES_H | 22 | #ifndef __SBSERVICES_H |
| 23 | #define __SBSERVICES_H | 23 | #define __SBSERVICES_H |
| 24 | 24 | ||
| 25 | #ifdef WIN32 | ||
| 26 | #include <windows.h> | ||
| 27 | #else | ||
| 28 | #include <pthread.h> | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #include "libimobiledevice/sbservices.h" | 25 | #include "libimobiledevice/sbservices.h" |
| 32 | #include "property_list_service.h" | 26 | #include "property_list_service.h" |
| 27 | #include "common/thread.h" | ||
| 33 | 28 | ||
| 34 | struct sbservices_client_private { | 29 | struct sbservices_client_private { |
| 35 | property_list_service_client_t parent; | 30 | property_list_service_client_t parent; |
| 36 | #ifdef WIN32 | 31 | mutex_t mutex; |
| 37 | CRITICAL_SECTION mutex; | ||
| 38 | #else | ||
| 39 | pthread_mutex_t mutex; | ||
| 40 | #endif | ||
| 41 | }; | 32 | }; |
| 42 | 33 | ||
| 43 | #endif | 34 | #endif |
diff --git a/tools/Makefile.am b/tools/Makefile.am index 57445d8..e668592 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am | |||
| @@ -18,7 +18,7 @@ idevicepair_LDADD = ../src/libimobiledevice.la | |||
| 18 | idevicesyslog_SOURCES = idevicesyslog.c | 18 | idevicesyslog_SOURCES = idevicesyslog.c |
| 19 | idevicesyslog_CFLAGS = $(AM_CFLAGS) | 19 | idevicesyslog_CFLAGS = $(AM_CFLAGS) |
| 20 | idevicesyslog_LDFLAGS = $(AM_LDFLAGS) | 20 | idevicesyslog_LDFLAGS = $(AM_LDFLAGS) |
| 21 | idevicesyslog_LDADD = ../src/libimobiledevice.la | 21 | idevicesyslog_LDADD = $(top_srcdir)/common/libinternalcommon.la ../src/libimobiledevice.la |
| 22 | 22 | ||
| 23 | idevice_id_SOURCES = idevice_id.c | 23 | idevice_id_SOURCES = idevice_id.c |
| 24 | idevice_id_CFLAGS = $(AM_CFLAGS) | 24 | idevice_id_CFLAGS = $(AM_CFLAGS) |
diff --git a/tools/idevicesyslog.c b/tools/idevicesyslog.c index 32163e6..3dd2257 100644 --- a/tools/idevicesyslog.c +++ b/tools/idevicesyslog.c | |||
| @@ -29,13 +29,13 @@ | |||
| 29 | #ifdef WIN32 | 29 | #ifdef WIN32 |
| 30 | #include <windows.h> | 30 | #include <windows.h> |
| 31 | #define sleep(x) Sleep(x*1000) | 31 | #define sleep(x) Sleep(x*1000) |
| 32 | #else | ||
| 33 | #include <pthread.h> | ||
| 34 | #endif | 32 | #endif |
| 35 | 33 | ||
| 36 | #include <libimobiledevice/libimobiledevice.h> | 34 | #include <libimobiledevice/libimobiledevice.h> |
| 37 | #include <libimobiledevice/lockdown.h> | 35 | #include <libimobiledevice/lockdown.h> |
| 38 | #include "../src/service.h" | 36 | |
| 37 | #include "src/service.h" | ||
| 38 | #include "common/thread.h" | ||
| 39 | 39 | ||
| 40 | static int quit_flag = 0; | 40 | static int quit_flag = 0; |
| 41 | 41 | ||
| @@ -46,11 +46,7 @@ static char* udid = NULL; | |||
| 46 | static idevice_t device = NULL; | 46 | static idevice_t device = NULL; |
| 47 | static service_client_t syslog = NULL; | 47 | static service_client_t syslog = NULL; |
| 48 | 48 | ||
| 49 | #ifdef WIN32 | 49 | thread_t worker = NULL; |
| 50 | HANDLE worker = NULL; | ||
| 51 | #else | ||
| 52 | pthread_t worker; | ||
| 53 | #endif | ||
| 54 | 50 | ||
| 55 | static int logging = 0; | 51 | static int logging = 0; |
| 56 | 52 | ||
| @@ -100,19 +96,10 @@ static int start_logging() | |||
| 100 | 96 | ||
| 101 | /* start worker thread */ | 97 | /* start worker thread */ |
| 102 | logging = 1; | 98 | logging = 1; |
| 103 | #ifdef WIN32 | 99 | if (thread_create(&worker, syslog_worker, NULL) != 0) { |
| 104 | worker = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)syslog_worker, NULL, 0, NULL); | ||
| 105 | if (worker == INVALID_HANDLE_VALUE) { | ||
| 106 | logging = 0; | 100 | logging = 0; |
| 107 | return -1; | 101 | return -1; |
| 108 | } | 102 | } |
| 109 | #else | ||
| 110 | if (pthread_create(&worker, NULL, syslog_worker, NULL) != 0) { | ||
| 111 | logging = 0; | ||
| 112 | return -1; | ||
| 113 | } | ||
| 114 | #endif | ||
| 115 | |||
| 116 | return 0; | 103 | return 0; |
| 117 | } | 104 | } |
| 118 | 105 | ||
| @@ -127,11 +114,7 @@ static void stop_logging() | |||
| 127 | } | 114 | } |
| 128 | 115 | ||
| 129 | /* wait for thread to complete */ | 116 | /* wait for thread to complete */ |
| 130 | #ifdef WIN32 | 117 | thread_join(worker); |
| 131 | WaitForSingleObject(worker, INFINITE); | ||
| 132 | #else | ||
| 133 | pthread_join(worker, NULL); | ||
| 134 | #endif | ||
| 135 | } | 118 | } |
| 136 | 119 | ||
| 137 | if (device) { | 120 | if (device) { |
