summaryrefslogtreecommitdiffstats
path: root/src/notification_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/notification_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/notification_proxy.c')
-rw-r--r--src/notification_proxy.c36
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 {
static void np_lock(np_client_t client)
{
debug_info("NP: Locked");
+#ifdef WIN32
+ EnterCriticalSection(&client->mutex);
+#else
pthread_mutex_lock(&client->mutex);
+#endif
}
/**
@@ -53,7 +57,11 @@ 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
}
/**
@@ -107,9 +115,13 @@ np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client)
np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_private));
client_loc->parent = plistclient;
+#ifdef WIN32
+ InitializeCriticalSection(&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;
@@ -132,9 +144,17 @@ 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
}
+#ifdef WIN32
+ DeleteCriticalSection(&client->mutex);
+#else
pthread_mutex_destroy(&client->mutex);
+#endif
free(client);
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,
debug_info("callback already set, removing\n");
property_list_service_client_t parent = client->parent;
client->parent = NULL;
+#ifdef WIN32
+ WaitForSingleObject(client->notifier, INFINITE);
+ client->notifier = NULL;
+#else
pthread_join(client->notifier, NULL);
client->notifier = (pthread_t)NULL;
+#endif
client->parent = parent;
}
@@ -405,9 +430,18 @@ 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) {
res = NP_E_SUCCESS;
}
+#endif
}
} else {
debug_info("no callback set");