summaryrefslogtreecommitdiffstats
path: root/src/installation_proxy.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2011-09-10 19:08:39 +0200
committerGravatar Martin Szulecki2012-03-19 01:38:54 +0100
commit475c9679716eec92e3508063b7486e3508c4c974 (patch)
tree5ab09c85387821e05b052cbb642b92ae102953ec /src/installation_proxy.c
parent6f29ab73053327066409744d025dcbd03fd6b627 (diff)
downloadlibimobiledevice-475c9679716eec92e3508063b7486e3508c4c974.tar.gz
libimobiledevice-475c9679716eec92e3508063b7486e3508c4c974.tar.bz2
WIN32: use windows threads and mutexes instead of pthread_*
Diffstat (limited to 'src/installation_proxy.c')
-rw-r--r--src/installation_proxy.c34
1 files changed, 34 insertions, 0 deletions
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 {
static void instproxy_lock(instproxy_client_t client)
{
debug_info("InstallationProxy: Locked");
+#ifdef WIN32
+ EnterCriticalSection(&client->mutex);
+#else
pthread_mutex_lock(&client->mutex);
+#endif
}
/**
@@ -54,7 +58,11 @@ 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
}
/**
@@ -106,8 +114,13 @@ instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instprox
instproxy_client_t client_loc = (instproxy_client_t) malloc(sizeof(struct instproxy_client_private));
client_loc->parent = plistclient;
+#ifdef WIN32
+ InitializeCriticalSection(&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;
@@ -131,9 +144,17 @@ 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
}
+#ifdef WIN32
+ DeleteCriticalSection(&client->mutex);
+#else
pthread_mutex_destroy(&client->mutex);
+#endif
free(client);
return INSTPROXY_E_SUCCESS;
@@ -356,7 +377,11 @@ 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);
@@ -391,9 +416,18 @@ 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) {
res = INSTPROXY_E_SUCCESS;
}
+#endif
}
} else {
/* sync mode */