From b2924a1549d874fb86deaad5fd2438e567c65bf4 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Wed, 20 Mar 2013 05:38:06 +0100 Subject: use new internal common code for thread, mutex, and socket operations --- src/installation_proxy.c | 46 ++++++---------------------------------------- 1 file changed, 6 insertions(+), 40 deletions(-) (limited to 'src/installation_proxy.c') 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 */ -- cgit v1.1-32-gdbae