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.c49
1 files changed, 7 insertions, 42 deletions
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 {
46static void np_lock(np_client_t client) 46static void np_lock(np_client_t client)
47{ 47{
48 debug_info("NP: Locked"); 48 debug_info("NP: Locked");
49#ifdef WIN32 49 mutex_lock(&client->mutex);
50 EnterCriticalSection(&client->mutex);
51#else
52 pthread_mutex_lock(&client->mutex);
53#endif
54} 50}
55 51
56/** 52/**
@@ -61,11 +57,7 @@ static void np_lock(np_client_t client)
61static void np_unlock(np_client_t client) 57static void np_unlock(np_client_t client)
62{ 58{
63 debug_info("NP: Unlocked"); 59 debug_info("NP: Unlocked");
64#ifdef WIN32 60 mutex_unlock(&client->mutex);
65 LeaveCriticalSection(&client->mutex);
66#else
67 pthread_mutex_unlock(&client->mutex);
68#endif
69} 61}
70 62
71/** 63/**
@@ -117,13 +109,8 @@ np_error_t np_client_new(idevice_t device, lockdownd_service_descriptor_t servic
117 np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_private)); 109 np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_private));
118 client_loc->parent = plistclient; 110 client_loc->parent = plistclient;
119 111
120#ifdef WIN32 112 mutex_init(&client_loc->mutex);
121 InitializeCriticalSection(&client_loc->mutex);
122 client_loc->notifier = NULL; 113 client_loc->notifier = NULL;
123#else
124 pthread_mutex_init(&client_loc->mutex, NULL);
125 client_loc->notifier = (pthread_t)NULL;
126#endif
127 114
128 *client = client_loc; 115 *client = client_loc;
129 return NP_E_SUCCESS; 116 return NP_E_SUCCESS;
@@ -146,17 +133,9 @@ np_error_t np_client_free(np_client_t client)
146 client->parent = NULL; 133 client->parent = NULL;
147 if (client->notifier) { 134 if (client->notifier) {
148 debug_info("joining np callback"); 135 debug_info("joining np callback");
149#ifdef WIN32 136 thread_join(client->notifier);
150 WaitForSingleObject(client->notifier, INFINITE);
151#else
152 pthread_join(client->notifier, NULL);
153#endif
154 } 137 }
155#ifdef WIN32 138 mutex_destroy(&client->mutex);
156 DeleteCriticalSection(&client->mutex);
157#else
158 pthread_mutex_destroy(&client->mutex);
159#endif
160 free(client); 139 free(client);
161 140
162 return NP_E_SUCCESS; 141 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,
415 debug_info("callback already set, removing\n"); 394 debug_info("callback already set, removing\n");
416 property_list_service_client_t parent = client->parent; 395 property_list_service_client_t parent = client->parent;
417 client->parent = NULL; 396 client->parent = NULL;
418#ifdef WIN32 397 thread_join(client->notifier);
419 WaitForSingleObject(client->notifier, INFINITE);
420 client->notifier = NULL; 398 client->notifier = NULL;
421#else
422 pthread_join(client->notifier, NULL);
423 client->notifier = (pthread_t)NULL;
424#endif
425 client->parent = parent; 399 client->parent = parent;
426 } 400 }
427 401
@@ -432,18 +406,9 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb,
432 npt->cbfunc = notify_cb; 406 npt->cbfunc = notify_cb;
433 npt->user_data = user_data; 407 npt->user_data = user_data;
434 408
435#ifdef WIN32 409 if (thread_create(&client->notifier, np_notifier, npt) == 0) {
436 client->notifier = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)np_notifier, npt, 0, NULL);
437 if (client->notifier != INVALID_HANDLE_VALUE) {
438 res = NP_E_SUCCESS;
439 } else {
440 client->notifier = NULL;
441 }
442#else
443 if (pthread_create(&client->notifier, NULL, np_notifier, npt) == 0) {
444 res = NP_E_SUCCESS; 410 res = NP_E_SUCCESS;
445 } 411 }
446#endif
447 } 412 }
448 } else { 413 } else {
449 debug_info("no callback set"); 414 debug_info("no callback set");