summaryrefslogtreecommitdiffstats
path: root/src/notification_proxy.c
diff options
context:
space:
mode:
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");