diff options
Diffstat (limited to 'src')
-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 |
11 files changed, 38 insertions, 201 deletions
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 AM_LDFLAGS = $(libgnutls_LIBS) $(libtasn1_LIBS) $(libplist_LIBS) $(libusbmuxd_LIBS) $(libgcrypt_LIBS) ${libpthread_LIBS} $(openssl_LIBS) lib_LTLIBRARIES = libimobiledevice.la -libimobiledevice_la_LIBADD = +libimobiledevice_la_LIBADD = $(top_srcdir)/common/libinternalcommon.la libimobiledevice_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBIMOBILEDEVICE_SO_VERSION) -no-undefined libimobiledevice_la_SOURCES = idevice.c idevice.h \ debug.c debug.h\ @@ -43,11 +43,7 @@ static const int MAXIMUM_PACKET_SIZE = (2 << 15); static void afc_lock(afc_client_t client) { debug_info("Locked"); -#ifdef WIN32 - EnterCriticalSection(&client->mutex); -#else - pthread_mutex_lock(&client->mutex); -#endif + mutex_lock(&client->mutex); } /** @@ -58,11 +54,7 @@ static void afc_lock(afc_client_t client) static void afc_unlock(afc_client_t client) { debug_info("Unlocked"); -#ifdef WIN32 - LeaveCriticalSection(&client->mutex); -#else - pthread_mutex_unlock(&client->mutex); -#endif + mutex_unlock(&client->mutex); } /** @@ -99,11 +91,7 @@ afc_error_t afc_client_new_with_service_client(service_client_t service_client, memcpy(client_loc->afc_packet->magic, AFC_MAGIC, AFC_MAGIC_LEN); client_loc->file_handle = 0; client_loc->lock = 0; -#ifdef WIN32 - InitializeCriticalSection(&client_loc->mutex); -#else - pthread_mutex_init(&client_loc->mutex, NULL); -#endif + mutex_init(&client_loc->mutex); *client = client_loc; return AFC_E_SUCCESS; @@ -156,11 +144,7 @@ afc_error_t afc_client_free(afc_client_t client) client->parent = NULL; } free(client->afc_packet); -#ifdef WIN32 - DeleteCriticalSection(&client->mutex); -#else - pthread_mutex_destroy(&client->mutex); -#endif + mutex_destroy(&client->mutex); free(client); return AFC_E_SUCCESS; } @@ -23,15 +23,11 @@ #define __AFC_H #include <stdint.h> -#ifdef WIN32 -#include <windows.h> -#else -#include <pthread.h> -#endif #include "libimobiledevice/afc.h" #include "service.h" #include "endianness.h" +#include "common/thread.h" #define AFC_MAGIC "CFA6LPAA" #define AFC_MAGIC_LEN (8) @@ -62,11 +58,7 @@ struct afc_client_private { AFCPacket *afc_packet; int file_handle; int lock; -#ifdef WIN32 - CRITICAL_SECTION mutex; -#else - pthread_mutex_t mutex; -#endif + mutex_t mutex; int free_parent; }; 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 { static void instproxy_lock(instproxy_client_t client) { debug_info("InstallationProxy: Locked"); -#ifdef WIN32 - EnterCriticalSection(&client->mutex); -#else - pthread_mutex_lock(&client->mutex); -#endif + mutex_lock(&client->mutex); } /** @@ -58,11 +54,7 @@ static void instproxy_lock(instproxy_client_t client) static void instproxy_unlock(instproxy_client_t client) { debug_info("InstallationProxy: Unlocked"); -#ifdef WIN32 - LeaveCriticalSection(&client->mutex); -#else - pthread_mutex_unlock(&client->mutex); -#endif + mutex_unlock(&client->mutex); } /** @@ -112,13 +104,8 @@ instproxy_error_t instproxy_client_new(idevice_t device, lockdownd_service_descr instproxy_client_t client_loc = (instproxy_client_t) malloc(sizeof(struct instproxy_client_private)); client_loc->parent = plistclient; -#ifdef WIN32 - InitializeCriticalSection(&client_loc->mutex); + mutex_init(&client_loc->mutex); client_loc->status_updater = NULL; -#else - pthread_mutex_init(&client_loc->mutex, NULL); - client_loc->status_updater = (pthread_t)NULL; -#endif *client = client_loc; return INSTPROXY_E_SUCCESS; @@ -142,17 +129,9 @@ instproxy_error_t instproxy_client_free(instproxy_client_t client) client->parent = NULL; if (client->status_updater) { debug_info("joining status_updater"); -#ifdef WIN32 - WaitForSingleObject(client->status_updater, INFINITE); -#else - pthread_join(client->status_updater, NULL); -#endif + thread_join(client->status_updater); } -#ifdef WIN32 - DeleteCriticalSection(&client->mutex); -#else - pthread_mutex_destroy(&client->mutex); -#endif + mutex_destroy(&client->mutex); free(client); return INSTPROXY_E_SUCCESS; @@ -375,11 +354,7 @@ static void* instproxy_status_updater(void* arg) if (data->operation) { free(data->operation); } -#ifdef WIN32 data->client->status_updater = NULL; -#else - data->client->status_updater = (pthread_t)NULL; -#endif instproxy_unlock(data->client); free(data); @@ -414,18 +389,9 @@ static instproxy_error_t instproxy_create_status_updater(instproxy_client_t clie data->operation = strdup(operation); data->user_data = user_data; -#ifdef WIN32 - client->status_updater = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)instproxy_status_updater, data, 0, NULL); - if (client->status_updater != INVALID_HANDLE_VALUE) { - res = INSTPROXY_E_SUCCESS; - } else { - client->status_updater = NULL; - } -#else - if (pthread_create(&client->status_updater, NULL, instproxy_status_updater, data) == 0) { + if (thread_create(&client->status_updater, instproxy_status_updater, data) == 0) { res = INSTPROXY_E_SUCCESS; } -#endif } } else { /* 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 @@ #ifndef __INSTALLATION_PROXY_H #define __INSTALLATION_PROXY_H -#ifdef WIN32 -#include <windows.h> -#else -#include <pthread.h> -#endif - #include "libimobiledevice/installation_proxy.h" #include "property_list_service.h" +#include "common/thread.h" struct instproxy_client_private { property_list_service_client_t parent; -#ifdef WIN32 - CRITICAL_SECTION mutex; - HANDLE status_updater; -#else - pthread_mutex_t mutex; - pthread_t status_updater; -#endif + mutex_t mutex; + thread_t status_updater; }; #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 @@ */ static void mobile_image_mounter_lock(mobile_image_mounter_client_t client) { -#ifdef WIN32 - EnterCriticalSection(&client->mutex); -#else - pthread_mutex_lock(&client->mutex); -#endif + mutex_lock(&client->mutex); } /** @@ -49,11 +45,7 @@ static void mobile_image_mounter_lock(mobile_image_mounter_client_t client) */ static void mobile_image_mounter_unlock(mobile_image_mounter_client_t client) { -#ifdef WIN32 - LeaveCriticalSection(&client->mutex); -#else - pthread_mutex_unlock(&client->mutex); -#endif + mutex_unlock(&client->mutex); } /** @@ -107,11 +99,7 @@ mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, lockdown mobile_image_mounter_client_t client_loc = (mobile_image_mounter_client_t) malloc(sizeof(struct mobile_image_mounter_client_private)); client_loc->parent = plistclient; -#ifdef WIN32 - InitializeCriticalSection(&client_loc->mutex); -#else - pthread_mutex_init(&client_loc->mutex, NULL); -#endif + mutex_init(&client_loc->mutex); *client = client_loc; return MOBILE_IMAGE_MOUNTER_E_SUCCESS; @@ -133,11 +121,7 @@ mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_clie property_list_service_client_free(client->parent); client->parent = NULL; -#ifdef WIN32 - DeleteCriticalSection(&client->mutex); -#else - pthread_mutex_destroy(&client->mutex); -#endif + mutex_destroy(&client->mutex); free(client); 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 @@ #ifndef __MOBILE_IMAGE_MOUNTER_H #define __MOBILE_IMAGE_MOUNTER_H -#ifdef WIN32 -#include <windows.h> -#else -#include <pthread.h> -#endif - #include "libimobiledevice/mobile_image_mounter.h" #include "property_list_service.h" +#include "common/thread.h" struct mobile_image_mounter_client_private { property_list_service_client_t parent; -#ifdef WIN32 - CRITICAL_SECTION mutex; -#else - pthread_mutex_t mutex; -#endif + mutex_t mutex; }; #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 { static void np_lock(np_client_t client) { debug_info("NP: Locked"); -#ifdef WIN32 - EnterCriticalSection(&client->mutex); -#else - pthread_mutex_lock(&client->mutex); -#endif + mutex_lock(&client->mutex); } /** @@ -61,11 +57,7 @@ static void np_lock(np_client_t client) static void np_unlock(np_client_t client) { debug_info("NP: Unlocked"); -#ifdef WIN32 - LeaveCriticalSection(&client->mutex); -#else - pthread_mutex_unlock(&client->mutex); -#endif + mutex_unlock(&client->mutex); } /** @@ -117,13 +109,8 @@ np_error_t np_client_new(idevice_t device, lockdownd_service_descriptor_t servic np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_private)); client_loc->parent = plistclient; -#ifdef WIN32 - InitializeCriticalSection(&client_loc->mutex); + mutex_init(&client_loc->mutex); client_loc->notifier = NULL; -#else - pthread_mutex_init(&client_loc->mutex, NULL); - client_loc->notifier = (pthread_t)NULL; -#endif *client = client_loc; return NP_E_SUCCESS; @@ -146,17 +133,9 @@ np_error_t np_client_free(np_client_t client) client->parent = NULL; if (client->notifier) { debug_info("joining np callback"); -#ifdef WIN32 - WaitForSingleObject(client->notifier, INFINITE); -#else - pthread_join(client->notifier, NULL); -#endif + thread_join(client->notifier); } -#ifdef WIN32 - DeleteCriticalSection(&client->mutex); -#else - pthread_mutex_destroy(&client->mutex); -#endif + mutex_destroy(&client->mutex); free(client); 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, debug_info("callback already set, removing\n"); property_list_service_client_t parent = client->parent; client->parent = NULL; -#ifdef WIN32 - WaitForSingleObject(client->notifier, INFINITE); + thread_join(client->notifier); client->notifier = NULL; -#else - pthread_join(client->notifier, NULL); - client->notifier = (pthread_t)NULL; -#endif client->parent = parent; } @@ -432,18 +406,9 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb, npt->cbfunc = notify_cb; npt->user_data = user_data; -#ifdef WIN32 - client->notifier = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)np_notifier, npt, 0, NULL); - if (client->notifier != INVALID_HANDLE_VALUE) { - res = NP_E_SUCCESS; - } else { - client->notifier = NULL; - } -#else - if (pthread_create(&client->notifier, NULL, np_notifier, npt) == 0) { + if (thread_create(&client->notifier, np_notifier, npt) == 0) { res = NP_E_SUCCESS; } -#endif } } else { 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 @@ #ifndef __NOTIFICATION_PROXY_H #define __NOTIFICATION_PROXY_H -#ifdef WIN32 -#include <windows.h> -#else -#include <pthread.h> -#endif - #include "libimobiledevice/notification_proxy.h" #include "property_list_service.h" +#include "common/thread.h" struct np_client_private { property_list_service_client_t parent; -#ifdef WIN32 - CRITICAL_SECTION mutex; - HANDLE notifier; -#else - pthread_mutex_t mutex; - pthread_t notifier; -#endif + mutex_t mutex; + thread_t notifier; }; 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 @@ static void sbs_lock(sbservices_client_t client) { debug_info("SBServices: Locked"); -#ifdef WIN32 - EnterCriticalSection(&client->mutex); -#else - pthread_mutex_lock(&client->mutex); -#endif + mutex_lock(&client->mutex); } /** @@ -51,11 +47,7 @@ static void sbs_lock(sbservices_client_t client) static void sbs_unlock(sbservices_client_t client) { debug_info("SBServices: Unlocked"); -#ifdef WIN32 - LeaveCriticalSection(&client->mutex); -#else - pthread_mutex_unlock(&client->mutex); -#endif + mutex_unlock(&client->mutex); } /** @@ -105,11 +97,7 @@ sbservices_error_t sbservices_client_new(idevice_t device, lockdownd_service_des sbservices_client_t client_loc = (sbservices_client_t) malloc(sizeof(struct sbservices_client_private)); client_loc->parent = plistclient; -#ifdef WIN32 - InitializeCriticalSection(&client_loc->mutex); -#else - pthread_mutex_init(&client_loc->mutex, NULL); -#endif + mutex_init(&client_loc->mutex); *client = client_loc; return SBSERVICES_E_SUCCESS; @@ -131,11 +119,7 @@ sbservices_error_t sbservices_client_free(sbservices_client_t client) sbservices_error_t err = sbservices_error(property_list_service_client_free(client->parent)); client->parent = NULL; -#ifdef WIN32 - DeleteCriticalSection(&client->mutex); -#else - pthread_mutex_destroy(&client->mutex); -#endif + mutex_destroy(&client->mutex); free(client); 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 @@ #ifndef __SBSERVICES_H #define __SBSERVICES_H -#ifdef WIN32 -#include <windows.h> -#else -#include <pthread.h> -#endif - #include "libimobiledevice/sbservices.h" #include "property_list_service.h" +#include "common/thread.h" struct sbservices_client_private { property_list_service_client_t parent; -#ifdef WIN32 - CRITICAL_SECTION mutex; -#else - pthread_mutex_t mutex; -#endif + mutex_t mutex; }; #endif |