diff options
| author | 2011-09-03 02:07:09 +0200 | |
|---|---|---|
| committer | 2012-03-18 20:40:54 +0100 | |
| commit | 6a83ef58a1032e3b336587e2f3a19659ae325c25 (patch) | |
| tree | 27e12297bc66bd22a0cfc86459413a49a0d998f2 | |
| parent | b586203dbef26f9e94325b57867478eda504e5a1 (diff) | |
| download | libimobiledevice-6a83ef58a1032e3b336587e2f3a19659ae325c25.tar.gz libimobiledevice-6a83ef58a1032e3b336587e2f3a19659ae325c25.tar.bz2 | |
Remove gthread dependency and use pthreads instead
| -rw-r--r-- | configure.ac | 1 | ||||
| -rw-r--r-- | dev/afccheck.c | 17 | ||||
| -rw-r--r-- | src/afc.c | 18 | ||||
| -rw-r--r-- | src/afc.h | 4 | ||||
| -rw-r--r-- | src/installation_proxy.c | 25 | ||||
| -rw-r--r-- | src/installation_proxy.h | 6 | ||||
| -rw-r--r-- | src/mobile_image_mounter.c | 14 | ||||
| -rw-r--r-- | src/mobile_image_mounter.h | 4 | ||||
| -rw-r--r-- | src/notification_proxy.c | 27 | ||||
| -rw-r--r-- | src/notification_proxy.h | 8 | ||||
| -rw-r--r-- | src/sbservices.c | 14 | ||||
| -rw-r--r-- | src/sbservices.h | 4 |
12 files changed, 50 insertions, 92 deletions
diff --git a/configure.ac b/configure.ac index cdfaa36..5078afd 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -28,7 +28,6 @@ AC_PROG_LIBTOOL | |||
| 28 | # Checks for libraries. | 28 | # Checks for libraries. |
| 29 | PKG_CHECK_MODULES(libusbmuxd, libusbmuxd >= 0.1.4) | 29 | PKG_CHECK_MODULES(libusbmuxd, libusbmuxd >= 0.1.4) |
| 30 | PKG_CHECK_MODULES(libglib2, glib-2.0 >= 2.14.1) | 30 | PKG_CHECK_MODULES(libglib2, glib-2.0 >= 2.14.1) |
| 31 | PKG_CHECK_MODULES(libgthread2, gthread-2.0 >= 2.14.1) | ||
| 32 | PKG_CHECK_MODULES(libgnutls, gnutls >= 2.2.0) | 31 | PKG_CHECK_MODULES(libgnutls, gnutls >= 2.2.0) |
| 33 | PKG_CHECK_MODULES(libtasn1, libtasn1 >= 1.1) | 32 | PKG_CHECK_MODULES(libtasn1, libtasn1 >= 1.1) |
| 34 | PKG_CHECK_MODULES(libplist, libplist >= 0.15) | 33 | PKG_CHECK_MODULES(libplist, libplist >= 0.15) |
diff --git a/dev/afccheck.c b/dev/afccheck.c index b4d8910..2dab6db 100644 --- a/dev/afccheck.c +++ b/dev/afccheck.c | |||
| @@ -22,7 +22,7 @@ | |||
| 22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
| 23 | #include <stdio.h> | 23 | #include <stdio.h> |
| 24 | #include <string.h> | 24 | #include <string.h> |
| 25 | #include <glib.h> | 25 | #include <pthread.h> |
| 26 | 26 | ||
| 27 | #include <libimobiledevice/libimobiledevice.h> | 27 | #include <libimobiledevice/libimobiledevice.h> |
| 28 | #include <libimobiledevice/lockdown.h> | 28 | #include <libimobiledevice/lockdown.h> |
| @@ -38,7 +38,7 @@ typedef struct { | |||
| 38 | } param; | 38 | } param; |
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | static void check_afc(gpointer data) | 41 | static void* check_afc(void *data) |
| 42 | { | 42 | { |
| 43 | //prepare a buffer | 43 | //prepare a buffer |
| 44 | unsigned int buffersize = BUFFER_SIZE * sizeof(unsigned int); | 44 | unsigned int buffersize = BUFFER_SIZE * sizeof(unsigned int); |
| @@ -85,14 +85,13 @@ static void check_afc(gpointer data) | |||
| 85 | 85 | ||
| 86 | //cleanup | 86 | //cleanup |
| 87 | afc_remove_path(((param *) data)->afc, path); | 87 | afc_remove_path(((param *) data)->afc, path); |
| 88 | g_thread_exit(0); | 88 | pthread_exit(0); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | int main(int argc, char *argv[]) | 91 | int main(int argc, char *argv[]) |
| 92 | { | 92 | { |
| 93 | lockdownd_client_t client = NULL; | 93 | lockdownd_client_t client = NULL; |
| 94 | idevice_t phone = NULL; | 94 | idevice_t phone = NULL; |
| 95 | GError *err; | ||
| 96 | uint16_t port = 0; | 95 | uint16_t port = 0; |
| 97 | afc_client_t afc = NULL; | 96 | afc_client_t afc = NULL; |
| 98 | 97 | ||
| @@ -121,22 +120,18 @@ int main(int argc, char *argv[]) | |||
| 121 | 120 | ||
| 122 | afc_client_new(phone, port, &afc); | 121 | afc_client_new(phone, port, &afc); |
| 123 | 122 | ||
| 124 | //makes sure thread environment is available | 123 | pthread_t threads[NB_THREADS]; |
| 125 | if (!g_thread_supported()) | ||
| 126 | g_thread_init(NULL); | ||
| 127 | |||
| 128 | GThread *threads[NB_THREADS]; | ||
| 129 | param data[NB_THREADS]; | 124 | param data[NB_THREADS]; |
| 130 | 125 | ||
| 131 | int i = 0; | 126 | int i = 0; |
| 132 | for (i = 0; i < NB_THREADS; i++) { | 127 | for (i = 0; i < NB_THREADS; i++) { |
| 133 | data[i].afc = afc; | 128 | data[i].afc = afc; |
| 134 | data[i].id = i + 1; | 129 | data[i].id = i + 1; |
| 135 | threads[i] = g_thread_create((GThreadFunc) check_afc, data + i, TRUE, &err); | 130 | pthread_create(&threads[i], NULL, check_afc, data + i); |
| 136 | } | 131 | } |
| 137 | 132 | ||
| 138 | for (i = 0; i < NB_THREADS; i++) { | 133 | for (i = 0; i < NB_THREADS; i++) { |
| 139 | g_thread_join(threads[i]); | 134 | pthread_join(threads[i], NULL); |
| 140 | } | 135 | } |
| 141 | 136 | ||
| 142 | lockdownd_client_free(client); | 137 | lockdownd_client_free(client); |
| @@ -39,7 +39,7 @@ static const int MAXIMUM_PACKET_SIZE = (2 << 15); | |||
| 39 | static void afc_lock(afc_client_t client) | 39 | static void afc_lock(afc_client_t client) |
| 40 | { | 40 | { |
| 41 | debug_info("Locked"); | 41 | debug_info("Locked"); |
| 42 | g_mutex_lock(client->mutex); | 42 | pthread_mutex_lock(&client->mutex); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | /** | 45 | /** |
| @@ -50,7 +50,7 @@ static void afc_lock(afc_client_t client) | |||
| 50 | static void afc_unlock(afc_client_t client) | 50 | static void afc_unlock(afc_client_t client) |
| 51 | { | 51 | { |
| 52 | debug_info("Unlocked"); | 52 | debug_info("Unlocked"); |
| 53 | g_mutex_unlock(client->mutex); | 53 | pthread_mutex_unlock(&client->mutex); |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | /** | 56 | /** |
| @@ -69,10 +69,6 @@ static void afc_unlock(afc_client_t client) | |||
| 69 | 69 | ||
| 70 | afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_client_t *client) | 70 | afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_client_t *client) |
| 71 | { | 71 | { |
| 72 | /* makes sure thread environment is available */ | ||
| 73 | if (!g_thread_supported()) | ||
| 74 | g_thread_init(NULL); | ||
| 75 | |||
| 76 | if (!connection) | 72 | if (!connection) |
| 77 | return AFC_E_INVALID_ARG; | 73 | return AFC_E_INVALID_ARG; |
| 78 | 74 | ||
| @@ -93,7 +89,7 @@ afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_ | |||
| 93 | memcpy(client_loc->afc_packet->magic, AFC_MAGIC, AFC_MAGIC_LEN); | 89 | memcpy(client_loc->afc_packet->magic, AFC_MAGIC, AFC_MAGIC_LEN); |
| 94 | client_loc->file_handle = 0; | 90 | client_loc->file_handle = 0; |
| 95 | client_loc->lock = 0; | 91 | client_loc->lock = 0; |
| 96 | client_loc->mutex = g_mutex_new(); | 92 | pthread_mutex_init(&client_loc->mutex, NULL); |
| 97 | 93 | ||
| 98 | *client = client_loc; | 94 | *client = client_loc; |
| 99 | return AFC_E_SUCCESS; | 95 | return AFC_E_SUCCESS; |
| @@ -117,10 +113,6 @@ afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_ | |||
| 117 | */ | 113 | */ |
| 118 | afc_error_t afc_client_new(idevice_t device, uint16_t port, afc_client_t * client) | 114 | afc_error_t afc_client_new(idevice_t device, uint16_t port, afc_client_t * client) |
| 119 | { | 115 | { |
| 120 | /* makes sure thread environment is available */ | ||
| 121 | if (!g_thread_supported()) | ||
| 122 | g_thread_init(NULL); | ||
| 123 | |||
| 124 | if (!device || port==0) | 116 | if (!device || port==0) |
| 125 | return AFC_E_INVALID_ARG; | 117 | return AFC_E_INVALID_ARG; |
| 126 | 118 | ||
| @@ -155,9 +147,7 @@ afc_error_t afc_client_free(afc_client_t client) | |||
| 155 | client->connection = NULL; | 147 | client->connection = NULL; |
| 156 | } | 148 | } |
| 157 | free(client->afc_packet); | 149 | free(client->afc_packet); |
| 158 | if (client->mutex) { | 150 | pthread_mutex_destroy(&client->mutex); |
| 159 | g_mutex_free(client->mutex); | ||
| 160 | } | ||
| 161 | free(client); | 151 | free(client); |
| 162 | return AFC_E_SUCCESS; | 152 | return AFC_E_SUCCESS; |
| 163 | } | 153 | } |
| @@ -19,8 +19,8 @@ | |||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ | 20 | */ |
| 21 | 21 | ||
| 22 | #include <glib.h> | ||
| 23 | #include <stdint.h> | 22 | #include <stdint.h> |
| 23 | #include <pthread.h> | ||
| 24 | 24 | ||
| 25 | #include "libimobiledevice/afc.h" | 25 | #include "libimobiledevice/afc.h" |
| 26 | 26 | ||
| @@ -53,7 +53,7 @@ struct afc_client_private { | |||
| 53 | AFCPacket *afc_packet; | 53 | AFCPacket *afc_packet; |
| 54 | int file_handle; | 54 | int file_handle; |
| 55 | int lock; | 55 | int lock; |
| 56 | GMutex *mutex; | 56 | pthread_mutex_t mutex; |
| 57 | int own_connection; | 57 | int own_connection; |
| 58 | }; | 58 | }; |
| 59 | 59 | ||
diff --git a/src/installation_proxy.c b/src/installation_proxy.c index 4a76dd2..e26a77d 100644 --- a/src/installation_proxy.c +++ b/src/installation_proxy.c | |||
| @@ -43,7 +43,7 @@ struct instproxy_status_data { | |||
| 43 | static void instproxy_lock(instproxy_client_t client) | 43 | static void instproxy_lock(instproxy_client_t client) |
| 44 | { | 44 | { |
| 45 | debug_info("InstallationProxy: Locked"); | 45 | debug_info("InstallationProxy: Locked"); |
| 46 | g_mutex_lock(client->mutex); | 46 | pthread_mutex_lock(&client->mutex); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | /** | 49 | /** |
| @@ -54,7 +54,7 @@ static void instproxy_lock(instproxy_client_t client) | |||
| 54 | static void instproxy_unlock(instproxy_client_t client) | 54 | static void instproxy_unlock(instproxy_client_t client) |
| 55 | { | 55 | { |
| 56 | debug_info("InstallationProxy: Unlocked"); | 56 | debug_info("InstallationProxy: Unlocked"); |
| 57 | g_mutex_unlock(client->mutex); | 57 | pthread_mutex_unlock(&client->mutex); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | /** | 60 | /** |
| @@ -96,10 +96,6 @@ static instproxy_error_t instproxy_error(property_list_service_error_t err) | |||
| 96 | */ | 96 | */ |
| 97 | instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instproxy_client_t *client) | 97 | instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instproxy_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 INSTPROXY_E_INVALID_ARG; | 100 | return INSTPROXY_E_INVALID_ARG; |
| 105 | 101 | ||
| @@ -110,8 +106,8 @@ instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instprox | |||
| 110 | 106 | ||
| 111 | instproxy_client_t client_loc = (instproxy_client_t) malloc(sizeof(struct instproxy_client_private)); | 107 | instproxy_client_t client_loc = (instproxy_client_t) malloc(sizeof(struct instproxy_client_private)); |
| 112 | client_loc->parent = plistclient; | 108 | client_loc->parent = plistclient; |
| 113 | client_loc->mutex = g_mutex_new(); | 109 | pthread_mutex_init(&client_loc->mutex, NULL); |
| 114 | client_loc->status_updater = NULL; | 110 | client_loc->status_updater = (pthread_t)NULL; |
| 115 | 111 | ||
| 116 | *client = client_loc; | 112 | *client = client_loc; |
| 117 | return INSTPROXY_E_SUCCESS; | 113 | return INSTPROXY_E_SUCCESS; |
| @@ -135,11 +131,9 @@ instproxy_error_t instproxy_client_free(instproxy_client_t client) | |||
| 135 | client->parent = NULL; | 131 | client->parent = NULL; |
| 136 | if (client->status_updater) { | 132 | if (client->status_updater) { |
| 137 | debug_info("joining status_updater"); | 133 | debug_info("joining status_updater"); |
| 138 | g_thread_join(client->status_updater); | 134 | pthread_join(client->status_updater, NULL); |
| 139 | } | ||
| 140 | if (client->mutex) { | ||
| 141 | g_mutex_free(client->mutex); | ||
| 142 | } | 135 | } |
| 136 | pthread_mutex_destroy(&client->mutex); | ||
| 143 | free(client); | 137 | free(client); |
| 144 | 138 | ||
| 145 | return INSTPROXY_E_SUCCESS; | 139 | return INSTPROXY_E_SUCCESS; |
| @@ -349,7 +343,7 @@ static instproxy_error_t instproxy_perform_operation(instproxy_client_t client, | |||
| 349 | * | 343 | * |
| 350 | * @return Always NULL. | 344 | * @return Always NULL. |
| 351 | */ | 345 | */ |
| 352 | static gpointer instproxy_status_updater(gpointer arg) | 346 | static void* instproxy_status_updater(void* arg) |
| 353 | { | 347 | { |
| 354 | struct instproxy_status_data *data = (struct instproxy_status_data*)arg; | 348 | struct instproxy_status_data *data = (struct instproxy_status_data*)arg; |
| 355 | 349 | ||
| @@ -362,7 +356,7 @@ static gpointer instproxy_status_updater(gpointer arg) | |||
| 362 | if (data->operation) { | 356 | if (data->operation) { |
| 363 | free(data->operation); | 357 | free(data->operation); |
| 364 | } | 358 | } |
| 365 | data->client->status_updater = NULL; | 359 | data->client->status_updater = (pthread_t)NULL; |
| 366 | instproxy_unlock(data->client); | 360 | instproxy_unlock(data->client); |
| 367 | free(data); | 361 | free(data); |
| 368 | 362 | ||
| @@ -397,8 +391,7 @@ static instproxy_error_t instproxy_create_status_updater(instproxy_client_t clie | |||
| 397 | data->operation = strdup(operation); | 391 | data->operation = strdup(operation); |
| 398 | data->user_data = user_data; | 392 | data->user_data = user_data; |
| 399 | 393 | ||
| 400 | client->status_updater = g_thread_create(instproxy_status_updater, data, TRUE, NULL); | 394 | if (pthread_create(&client->status_updater, NULL, instproxy_status_updater, data) == 0) { |
| 401 | if (client->status_updater) { | ||
| 402 | res = INSTPROXY_E_SUCCESS; | 395 | res = INSTPROXY_E_SUCCESS; |
| 403 | } | 396 | } |
| 404 | } | 397 | } |
diff --git a/src/installation_proxy.h b/src/installation_proxy.h index b497d62..811ead6 100644 --- a/src/installation_proxy.h +++ b/src/installation_proxy.h | |||
| @@ -21,15 +21,15 @@ | |||
| 21 | #ifndef IINSTALLATION_PROXY_H | 21 | #ifndef IINSTALLATION_PROXY_H |
| 22 | #define IINSTALLATION_PROXY_H | 22 | #define IINSTALLATION_PROXY_H |
| 23 | 23 | ||
| 24 | #include <glib.h> | 24 | #include <pthread.h> |
| 25 | 25 | ||
| 26 | #include "libimobiledevice/installation_proxy.h" | 26 | #include "libimobiledevice/installation_proxy.h" |
| 27 | #include "property_list_service.h" | 27 | #include "property_list_service.h" |
| 28 | 28 | ||
| 29 | struct instproxy_client_private { | 29 | struct instproxy_client_private { |
| 30 | property_list_service_client_t parent; | 30 | property_list_service_client_t parent; |
| 31 | GMutex *mutex; | 31 | pthread_mutex_t mutex; |
| 32 | GThread *status_updater; | 32 | pthread_t status_updater; |
| 33 | }; | 33 | }; |
| 34 | 34 | ||
| 35 | #endif | 35 | #endif |
diff --git a/src/mobile_image_mounter.c b/src/mobile_image_mounter.c index 367bee0..18caf73 100644 --- a/src/mobile_image_mounter.c +++ b/src/mobile_image_mounter.c | |||
| @@ -35,7 +35,7 @@ | |||
| 35 | */ | 35 | */ |
| 36 | static void mobile_image_mounter_lock(mobile_image_mounter_client_t client) | 36 | static void mobile_image_mounter_lock(mobile_image_mounter_client_t client) |
| 37 | { | 37 | { |
| 38 | g_mutex_lock(client->mutex); | 38 | pthread_mutex_lock(&client->mutex); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | /** | 41 | /** |
| @@ -45,7 +45,7 @@ static void mobile_image_mounter_lock(mobile_image_mounter_client_t client) | |||
| 45 | */ | 45 | */ |
| 46 | static void mobile_image_mounter_unlock(mobile_image_mounter_client_t client) | 46 | static void mobile_image_mounter_unlock(mobile_image_mounter_client_t client) |
| 47 | { | 47 | { |
| 48 | g_mutex_unlock(client->mutex); | 48 | pthread_mutex_unlock(&client->mutex); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | /** | 51 | /** |
| @@ -90,10 +90,6 @@ static mobile_image_mounter_error_t mobile_image_mounter_error(property_list_ser | |||
| 90 | */ | 90 | */ |
| 91 | mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, uint16_t port, mobile_image_mounter_client_t *client) | 91 | mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, uint16_t port, mobile_image_mounter_client_t *client) |
| 92 | { | 92 | { |
| 93 | /* makes sure thread environment is available */ | ||
| 94 | if (!g_thread_supported()) | ||
| 95 | g_thread_init(NULL); | ||
| 96 | |||
| 97 | if (!device) | 93 | if (!device) |
| 98 | return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; | 94 | return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; |
| 99 | 95 | ||
| @@ -105,7 +101,7 @@ mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, uint16_t | |||
| 105 | mobile_image_mounter_client_t client_loc = (mobile_image_mounter_client_t) malloc(sizeof(struct mobile_image_mounter_client_private)); | 101 | mobile_image_mounter_client_t client_loc = (mobile_image_mounter_client_t) malloc(sizeof(struct mobile_image_mounter_client_private)); |
| 106 | client_loc->parent = plistclient; | 102 | client_loc->parent = plistclient; |
| 107 | 103 | ||
| 108 | client_loc->mutex = g_mutex_new(); | 104 | pthread_mutex_init(&client_loc->mutex, NULL); |
| 109 | 105 | ||
| 110 | *client = client_loc; | 106 | *client = client_loc; |
| 111 | return MOBILE_IMAGE_MOUNTER_E_SUCCESS; | 107 | return MOBILE_IMAGE_MOUNTER_E_SUCCESS; |
| @@ -127,9 +123,7 @@ mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_clie | |||
| 127 | 123 | ||
| 128 | property_list_service_client_free(client->parent); | 124 | property_list_service_client_free(client->parent); |
| 129 | client->parent = NULL; | 125 | client->parent = NULL; |
| 130 | if (client->mutex) { | 126 | pthread_mutex_destroy(&client->mutex); |
| 131 | g_mutex_free(client->mutex); | ||
| 132 | } | ||
| 133 | free(client); | 127 | free(client); |
| 134 | 128 | ||
| 135 | return MOBILE_IMAGE_MOUNTER_E_SUCCESS; | 129 | return MOBILE_IMAGE_MOUNTER_E_SUCCESS; |
diff --git a/src/mobile_image_mounter.h b/src/mobile_image_mounter.h index 2615dbc..e0828f9 100644 --- a/src/mobile_image_mounter.h +++ b/src/mobile_image_mounter.h | |||
| @@ -21,14 +21,14 @@ | |||
| 21 | #ifndef IMOBILE_IMAGE_MOUNTER_H | 21 | #ifndef IMOBILE_IMAGE_MOUNTER_H |
| 22 | #define IMOBILE_IMAGE_MOUNTER_H | 22 | #define IMOBILE_IMAGE_MOUNTER_H |
| 23 | 23 | ||
| 24 | #include <glib.h> | 24 | #include <pthread.h> |
| 25 | 25 | ||
| 26 | #include "libimobiledevice/mobile_image_mounter.h" | 26 | #include "libimobiledevice/mobile_image_mounter.h" |
| 27 | #include "property_list_service.h" | 27 | #include "property_list_service.h" |
| 28 | 28 | ||
| 29 | struct mobile_image_mounter_client_private { | 29 | struct mobile_image_mounter_client_private { |
| 30 | property_list_service_client_t parent; | 30 | property_list_service_client_t parent; |
| 31 | GMutex *mutex; | 31 | pthread_mutex_t mutex; |
| 32 | }; | 32 | }; |
| 33 | 33 | ||
| 34 | #endif | 34 | #endif |
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 { | |||
| 42 | static void np_lock(np_client_t client) | 42 | static 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) | |||
| 53 | static void np_unlock(np_client_t client) | 53 | static 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 | */ |
| 97 | np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client) | 97 | np_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 | */ |
| 347 | gpointer np_notifier( gpointer arg ) | 341 | void* 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 | } |
diff --git a/src/notification_proxy.h b/src/notification_proxy.h index 8d5cd24..4a9cdad 100644 --- a/src/notification_proxy.h +++ b/src/notification_proxy.h | |||
| @@ -21,17 +21,17 @@ | |||
| 21 | #ifndef INOTIFICATION_PROXY_H | 21 | #ifndef INOTIFICATION_PROXY_H |
| 22 | #define INOTIFICATION_PROXY_H | 22 | #define INOTIFICATION_PROXY_H |
| 23 | 23 | ||
| 24 | #include <glib.h> | 24 | #include <pthread.h> |
| 25 | 25 | ||
| 26 | #include "libimobiledevice/notification_proxy.h" | 26 | #include "libimobiledevice/notification_proxy.h" |
| 27 | #include "property_list_service.h" | 27 | #include "property_list_service.h" |
| 28 | 28 | ||
| 29 | struct np_client_private { | 29 | struct np_client_private { |
| 30 | property_list_service_client_t parent; | 30 | property_list_service_client_t parent; |
| 31 | GMutex *mutex; | 31 | pthread_mutex_t mutex; |
| 32 | GThread *notifier; | 32 | pthread_t notifier; |
| 33 | }; | 33 | }; |
| 34 | 34 | ||
| 35 | gpointer np_notifier(gpointer arg); | 35 | void* np_notifier(void* arg); |
| 36 | 36 | ||
| 37 | #endif | 37 | #endif |
diff --git a/src/sbservices.c b/src/sbservices.c index 3596cbd..dd5f571 100644 --- a/src/sbservices.c +++ b/src/sbservices.c | |||
| @@ -36,7 +36,7 @@ | |||
| 36 | static void sbs_lock(sbservices_client_t client) | 36 | static void sbs_lock(sbservices_client_t client) |
| 37 | { | 37 | { |
| 38 | debug_info("SBServices: Locked"); | 38 | debug_info("SBServices: Locked"); |
| 39 | g_mutex_lock(client->mutex); | 39 | pthread_mutex_lock(&client->mutex); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | /** | 42 | /** |
| @@ -47,7 +47,7 @@ static void sbs_lock(sbservices_client_t client) | |||
| 47 | static void sbs_unlock(sbservices_client_t client) | 47 | static void sbs_unlock(sbservices_client_t client) |
| 48 | { | 48 | { |
| 49 | debug_info("SBServices: Unlocked"); | 49 | debug_info("SBServices: Unlocked"); |
| 50 | g_mutex_unlock(client->mutex); | 50 | pthread_mutex_unlock(&client->mutex); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | /** | 53 | /** |
| @@ -89,10 +89,6 @@ static sbservices_error_t sbservices_error(property_list_service_error_t err) | |||
| 89 | */ | 89 | */ |
| 90 | sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client) | 90 | sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client) |
| 91 | { | 91 | { |
| 92 | /* makes sure thread environment is available */ | ||
| 93 | if (!g_thread_supported()) | ||
| 94 | g_thread_init(NULL); | ||
| 95 | |||
| 96 | if (!device) | 92 | if (!device) |
| 97 | return SBSERVICES_E_INVALID_ARG; | 93 | return SBSERVICES_E_INVALID_ARG; |
| 98 | 94 | ||
| @@ -104,7 +100,7 @@ sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbserv | |||
| 104 | 100 | ||
| 105 | sbservices_client_t client_loc = (sbservices_client_t) malloc(sizeof(struct sbservices_client_private)); | 101 | sbservices_client_t client_loc = (sbservices_client_t) malloc(sizeof(struct sbservices_client_private)); |
| 106 | client_loc->parent = plistclient; | 102 | client_loc->parent = plistclient; |
| 107 | client_loc->mutex = g_mutex_new(); | 103 | pthread_mutex_init(&client_loc->mutex, NULL); |
| 108 | 104 | ||
| 109 | *client = client_loc; | 105 | *client = client_loc; |
| 110 | return SBSERVICES_E_SUCCESS; | 106 | return SBSERVICES_E_SUCCESS; |
| @@ -126,9 +122,7 @@ sbservices_error_t sbservices_client_free(sbservices_client_t client) | |||
| 126 | 122 | ||
| 127 | sbservices_error_t err = sbservices_error(property_list_service_client_free(client->parent)); | 123 | sbservices_error_t err = sbservices_error(property_list_service_client_free(client->parent)); |
| 128 | client->parent = NULL; | 124 | client->parent = NULL; |
| 129 | if (client->mutex) { | 125 | pthread_mutex_destroy(&client->mutex); |
| 130 | g_mutex_free(client->mutex); | ||
| 131 | } | ||
| 132 | free(client); | 126 | free(client); |
| 133 | 127 | ||
| 134 | return err; | 128 | return err; |
diff --git a/src/sbservices.h b/src/sbservices.h index 3a4120f..1c85fe8 100644 --- a/src/sbservices.h +++ b/src/sbservices.h | |||
| @@ -21,14 +21,14 @@ | |||
| 21 | #ifndef ISBSERVICES_H | 21 | #ifndef ISBSERVICES_H |
| 22 | #define ISBSERVICES_H | 22 | #define ISBSERVICES_H |
| 23 | 23 | ||
| 24 | #include <glib.h> | 24 | #include <pthread.h> |
| 25 | 25 | ||
| 26 | #include "libimobiledevice/sbservices.h" | 26 | #include "libimobiledevice/sbservices.h" |
| 27 | #include "property_list_service.h" | 27 | #include "property_list_service.h" |
| 28 | 28 | ||
| 29 | struct sbservices_client_private { | 29 | struct sbservices_client_private { |
| 30 | property_list_service_client_t parent; | 30 | property_list_service_client_t parent; |
| 31 | GMutex *mutex; | 31 | pthread_mutex_t mutex; |
| 32 | }; | 32 | }; |
| 33 | 33 | ||
| 34 | #endif | 34 | #endif |
