summaryrefslogtreecommitdiffstats
path: root/src/notification_proxy.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2011-09-03 02:07:09 +0200
committerGravatar Martin Szulecki2012-03-18 20:40:54 +0100
commit6a83ef58a1032e3b336587e2f3a19659ae325c25 (patch)
tree27e12297bc66bd22a0cfc86459413a49a0d998f2 /src/notification_proxy.c
parentb586203dbef26f9e94325b57867478eda504e5a1 (diff)
downloadlibimobiledevice-6a83ef58a1032e3b336587e2f3a19659ae325c25.tar.gz
libimobiledevice-6a83ef58a1032e3b336587e2f3a19659ae325c25.tar.bz2
Remove gthread dependency and use pthreads instead
Diffstat (limited to 'src/notification_proxy.c')
-rw-r--r--src/notification_proxy.c27
1 files changed, 10 insertions, 17 deletions
diff --git a/src/notification_proxy.c b/src/notification_proxy.c
index a883cfa..792a165 100644
--- a/src/notification_proxy.c
+++ b/src/notification_proxy.c
@@ -42,7 +42,7 @@ struct np_thread {
42static void np_lock(np_client_t client) 42static void np_lock(np_client_t client)
43{ 43{
44 debug_info("NP: Locked"); 44 debug_info("NP: Locked");
45 g_mutex_lock(client->mutex); 45 pthread_mutex_lock(&client->mutex);
46} 46}
47 47
48/** 48/**
@@ -53,7 +53,7 @@ static void np_lock(np_client_t client)
53static void np_unlock(np_client_t client) 53static void np_unlock(np_client_t client)
54{ 54{
55 debug_info("NP: Unlocked"); 55 debug_info("NP: Unlocked");
56 g_mutex_unlock(client->mutex); 56 pthread_mutex_unlock(&client->mutex);
57} 57}
58 58
59/** 59/**
@@ -96,10 +96,6 @@ static np_error_t np_error(property_list_service_error_t err)
96 */ 96 */
97np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client) 97np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client)
98{ 98{
99 /* makes sure thread environment is available */
100 if (!g_thread_supported())
101 g_thread_init(NULL);
102
103 if (!device) 99 if (!device)
104 return NP_E_INVALID_ARG; 100 return NP_E_INVALID_ARG;
105 101
@@ -111,9 +107,9 @@ np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client)
111 np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_private)); 107 np_client_t client_loc = (np_client_t) malloc(sizeof(struct np_client_private));
112 client_loc->parent = plistclient; 108 client_loc->parent = plistclient;
113 109
114 client_loc->mutex = g_mutex_new(); 110 pthread_mutex_init(&client_loc->mutex, NULL);
115 111
116 client_loc->notifier = NULL; 112 client_loc->notifier = (pthread_t)NULL;
117 113
118 *client = client_loc; 114 *client = client_loc;
119 return NP_E_SUCCESS; 115 return NP_E_SUCCESS;
@@ -136,11 +132,9 @@ np_error_t np_client_free(np_client_t client)
136 client->parent = NULL; 132 client->parent = NULL;
137 if (client->notifier) { 133 if (client->notifier) {
138 debug_info("joining np callback"); 134 debug_info("joining np callback");
139 g_thread_join(client->notifier); 135 pthread_join(client->notifier, NULL);
140 }
141 if (client->mutex) {
142 g_mutex_free(client->mutex);
143 } 136 }
137 pthread_mutex_destroy(&client->mutex);
144 free(client); 138 free(client);
145 139
146 return NP_E_SUCCESS; 140 return NP_E_SUCCESS;
@@ -344,7 +338,7 @@ static int np_get_notification(np_client_t client, char **notification)
344/** 338/**
345 * Internally used thread function. 339 * Internally used thread function.
346 */ 340 */
347gpointer np_notifier( gpointer arg ) 341void* np_notifier( void* arg )
348{ 342{
349 char *notification = NULL; 343 char *notification = NULL;
350 struct np_thread *npt = (struct np_thread*)arg; 344 struct np_thread *npt = (struct np_thread*)arg;
@@ -399,8 +393,8 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb,
399 debug_info("callback already set, removing\n"); 393 debug_info("callback already set, removing\n");
400 property_list_service_client_t parent = client->parent; 394 property_list_service_client_t parent = client->parent;
401 client->parent = NULL; 395 client->parent = NULL;
402 g_thread_join(client->notifier); 396 pthread_join(client->notifier, NULL);
403 client->notifier = NULL; 397 client->notifier = (pthread_t)NULL;
404 client->parent = parent; 398 client->parent = parent;
405 } 399 }
406 400
@@ -411,8 +405,7 @@ np_error_t np_set_notify_callback( np_client_t client, np_notify_cb_t notify_cb,
411 npt->cbfunc = notify_cb; 405 npt->cbfunc = notify_cb;
412 npt->user_data = user_data; 406 npt->user_data = user_data;
413 407
414 client->notifier = g_thread_create(np_notifier, npt, TRUE, NULL); 408 if (pthread_create(&client->notifier, NULL, np_notifier, npt) == 0) {
415 if (client->notifier) {
416 res = NP_E_SUCCESS; 409 res = NP_E_SUCCESS;
417 } 410 }
418 } 411 }