diff options
author | Nikias Bassen | 2011-09-03 02:07:09 +0200 |
---|---|---|
committer | Martin Szulecki | 2012-03-18 20:40:54 +0100 |
commit | 6a83ef58a1032e3b336587e2f3a19659ae325c25 (patch) | |
tree | 27e12297bc66bd22a0cfc86459413a49a0d998f2 /src | |
parent | b586203dbef26f9e94325b57867478eda504e5a1 (diff) | |
download | libimobiledevice-6a83ef58a1032e3b336587e2f3a19659ae325c25.tar.gz libimobiledevice-6a83ef58a1032e3b336587e2f3a19659ae325c25.tar.bz2 |
Remove gthread dependency and use pthreads instead
Diffstat (limited to 'src')
-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 |
10 files changed, 44 insertions, 80 deletions
@@ -39,7 +39,7 @@ static const int MAXIMUM_PACKET_SIZE = (2 << 15); static void afc_lock(afc_client_t client) { debug_info("Locked"); - g_mutex_lock(client->mutex); + pthread_mutex_lock(&client->mutex); } /** @@ -50,7 +50,7 @@ static void afc_lock(afc_client_t client) static void afc_unlock(afc_client_t client) { debug_info("Unlocked"); - g_mutex_unlock(client->mutex); + pthread_mutex_unlock(&client->mutex); } /** @@ -69,10 +69,6 @@ static void afc_unlock(afc_client_t client) afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_client_t *client) { - /* makes sure thread environment is available */ - if (!g_thread_supported()) - g_thread_init(NULL); - if (!connection) return AFC_E_INVALID_ARG; @@ -93,7 +89,7 @@ afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_ memcpy(client_loc->afc_packet->magic, AFC_MAGIC, AFC_MAGIC_LEN); client_loc->file_handle = 0; client_loc->lock = 0; - client_loc->mutex = g_mutex_new(); + pthread_mutex_init(&client_loc->mutex, NULL); *client = client_loc; return AFC_E_SUCCESS; @@ -117,10 +113,6 @@ afc_error_t afc_client_new_from_connection(idevice_connection_t connection, afc_ */ afc_error_t afc_client_new(idevice_t device, uint16_t port, afc_client_t * client) { - /* makes sure thread environment is available */ - if (!g_thread_supported()) - g_thread_init(NULL); - if (!device || port==0) return AFC_E_INVALID_ARG; @@ -155,9 +147,7 @@ afc_error_t afc_client_free(afc_client_t client) client->connection = NULL; } free(client->afc_packet); - if (client->mutex) { - g_mutex_free(client->mutex); - } + pthread_mutex_destroy(&client->mutex); free(client); return AFC_E_SUCCESS; } @@ -19,8 +19,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <glib.h> #include <stdint.h> +#include <pthread.h> #include "libimobiledevice/afc.h" @@ -53,7 +53,7 @@ struct afc_client_private { AFCPacket *afc_packet; int file_handle; int lock; - GMutex *mutex; + pthread_mutex_t mutex; int own_connection; }; 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 { static void instproxy_lock(instproxy_client_t client) { debug_info("InstallationProxy: Locked"); - g_mutex_lock(client->mutex); + pthread_mutex_lock(&client->mutex); } /** @@ -54,7 +54,7 @@ static void instproxy_lock(instproxy_client_t client) static void instproxy_unlock(instproxy_client_t client) { debug_info("InstallationProxy: Unlocked"); - g_mutex_unlock(client->mutex); + pthread_mutex_unlock(&client->mutex); } /** @@ -96,10 +96,6 @@ static instproxy_error_t instproxy_error(property_list_service_error_t err) */ instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instproxy_client_t *client) { - /* makes sure thread environment is available */ - if (!g_thread_supported()) - g_thread_init(NULL); - if (!device) return INSTPROXY_E_INVALID_ARG; @@ -110,8 +106,8 @@ instproxy_error_t instproxy_client_new(idevice_t device, uint16_t port, instprox instproxy_client_t client_loc = (instproxy_client_t) malloc(sizeof(struct instproxy_client_private)); client_loc->parent = plistclient; - client_loc->mutex = g_mutex_new(); - client_loc->status_updater = NULL; + pthread_mutex_init(&client_loc->mutex, NULL); + client_loc->status_updater = (pthread_t)NULL; *client = client_loc; return INSTPROXY_E_SUCCESS; @@ -135,11 +131,9 @@ instproxy_error_t instproxy_client_free(instproxy_client_t client) client->parent = NULL; if (client->status_updater) { debug_info("joining status_updater"); - g_thread_join(client->status_updater); - } - if (client->mutex) { - g_mutex_free(client->mutex); + pthread_join(client->status_updater, NULL); } + pthread_mutex_destroy(&client->mutex); free(client); return INSTPROXY_E_SUCCESS; @@ -349,7 +343,7 @@ static instproxy_error_t instproxy_perform_operation(instproxy_client_t client, * * @return Always NULL. */ -static gpointer instproxy_status_updater(gpointer arg) +static void* instproxy_status_updater(void* arg) { struct instproxy_status_data *data = (struct instproxy_status_data*)arg; @@ -362,7 +356,7 @@ static gpointer instproxy_status_updater(gpointer arg) if (data->operation) { free(data->operation); } - data->client->status_updater = NULL; + data->client->status_updater = (pthread_t)NULL; instproxy_unlock(data->client); free(data); @@ -397,8 +391,7 @@ static instproxy_error_t instproxy_create_status_updater(instproxy_client_t clie data->operation = strdup(operation); data->user_data = user_data; - client->status_updater = g_thread_create(instproxy_status_updater, data, TRUE, NULL); - if (client->status_updater) { + if (pthread_create(&client->status_updater, NULL, instproxy_status_updater, data) == 0) { res = INSTPROXY_E_SUCCESS; } } 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 @@ #ifndef IINSTALLATION_PROXY_H #define IINSTALLATION_PROXY_H -#include <glib.h> +#include <pthread.h> #include "libimobiledevice/installation_proxy.h" #include "property_list_service.h" struct instproxy_client_private { property_list_service_client_t parent; - GMutex *mutex; - GThread *status_updater; + pthread_mutex_t mutex; + pthread_t status_updater; }; #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 @@ */ static void mobile_image_mounter_lock(mobile_image_mounter_client_t client) { - g_mutex_lock(client->mutex); + pthread_mutex_lock(&client->mutex); } /** @@ -45,7 +45,7 @@ static void mobile_image_mounter_lock(mobile_image_mounter_client_t client) */ static void mobile_image_mounter_unlock(mobile_image_mounter_client_t client) { - g_mutex_unlock(client->mutex); + pthread_mutex_unlock(&client->mutex); } /** @@ -90,10 +90,6 @@ static mobile_image_mounter_error_t mobile_image_mounter_error(property_list_ser */ mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, uint16_t port, mobile_image_mounter_client_t *client) { - /* makes sure thread environment is available */ - if (!g_thread_supported()) - g_thread_init(NULL); - if (!device) return MOBILE_IMAGE_MOUNTER_E_INVALID_ARG; @@ -105,7 +101,7 @@ mobile_image_mounter_error_t mobile_image_mounter_new(idevice_t device, uint16_t mobile_image_mounter_client_t client_loc = (mobile_image_mounter_client_t) malloc(sizeof(struct mobile_image_mounter_client_private)); client_loc->parent = plistclient; - client_loc->mutex = g_mutex_new(); + pthread_mutex_init(&client_loc->mutex, NULL); *client = client_loc; return MOBILE_IMAGE_MOUNTER_E_SUCCESS; @@ -127,9 +123,7 @@ mobile_image_mounter_error_t mobile_image_mounter_free(mobile_image_mounter_clie property_list_service_client_free(client->parent); client->parent = NULL; - if (client->mutex) { - g_mutex_free(client->mutex); - } + pthread_mutex_destroy(&client->mutex); free(client); 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 @@ #ifndef IMOBILE_IMAGE_MOUNTER_H #define IMOBILE_IMAGE_MOUNTER_H -#include <glib.h> +#include <pthread.h> #include "libimobiledevice/mobile_image_mounter.h" #include "property_list_service.h" struct mobile_image_mounter_client_private { property_list_service_client_t parent; - GMutex *mutex; + pthread_mutex_t mutex; }; #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 { static void np_lock(np_client_t client) { debug_info("NP: Locked"); - g_mutex_lock(client->mutex); + pthread_mutex_lock(&client->mutex); } /** @@ -53,7 +53,7 @@ static void np_lock(np_client_t client) static void np_unlock(np_client_t client) { debug_info("NP: Unlocked"); - g_mutex_unlock(client->mutex); + pthread_mutex_unlock(&client->mutex); } /** @@ -96,10 +96,6 @@ static np_error_t np_error(property_list_service_error_t err) */ np_error_t np_client_new(idevice_t device, uint16_t port, np_client_t *client) { - /* makes sure thread environment is available */ - if (!g_thread_supported()) - g_thread_init(NULL); - if (!device) return NP_E_INVALID_ARG; @@ -111,9 +107,9 @@ 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; - client_loc->mutex = g_mutex_new(); + pthread_mutex_init(&client_loc->mutex, NULL); - client_loc->notifier = NULL; + client_loc->notifier = (pthread_t)NULL; *client = client_loc; return NP_E_SUCCESS; @@ -136,11 +132,9 @@ np_error_t np_client_free(np_client_t client) client->parent = NULL; if (client->notifier) { debug_info("joining np callback"); - g_thread_join(client->notifier); - } - if (client->mutex) { - g_mutex_free(client->mutex); + pthread_join(client->notifier, NULL); } + pthread_mutex_destroy(&client->mutex); free(client); return NP_E_SUCCESS; @@ -344,7 +338,7 @@ static int np_get_notification(np_client_t client, char **notification) /** * Internally used thread function. */ -gpointer np_notifier( gpointer arg ) +void* np_notifier( void* arg ) { char *notification = NULL; 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, debug_info("callback already set, removing\n"); property_list_service_client_t parent = client->parent; client->parent = NULL; - g_thread_join(client->notifier); - client->notifier = NULL; + pthread_join(client->notifier, NULL); + client->notifier = (pthread_t)NULL; client->parent = parent; } @@ -411,8 +405,7 @@ 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; - client->notifier = g_thread_create(np_notifier, npt, TRUE, NULL); - if (client->notifier) { + if (pthread_create(&client->notifier, NULL, np_notifier, npt) == 0) { res = NP_E_SUCCESS; } } 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 @@ #ifndef INOTIFICATION_PROXY_H #define INOTIFICATION_PROXY_H -#include <glib.h> +#include <pthread.h> #include "libimobiledevice/notification_proxy.h" #include "property_list_service.h" struct np_client_private { property_list_service_client_t parent; - GMutex *mutex; - GThread *notifier; + pthread_mutex_t mutex; + pthread_t notifier; }; -gpointer np_notifier(gpointer arg); +void* np_notifier(void* arg); #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 @@ static void sbs_lock(sbservices_client_t client) { debug_info("SBServices: Locked"); - g_mutex_lock(client->mutex); + pthread_mutex_lock(&client->mutex); } /** @@ -47,7 +47,7 @@ static void sbs_lock(sbservices_client_t client) static void sbs_unlock(sbservices_client_t client) { debug_info("SBServices: Unlocked"); - g_mutex_unlock(client->mutex); + pthread_mutex_unlock(&client->mutex); } /** @@ -89,10 +89,6 @@ static sbservices_error_t sbservices_error(property_list_service_error_t err) */ sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbservices_client_t *client) { - /* makes sure thread environment is available */ - if (!g_thread_supported()) - g_thread_init(NULL); - if (!device) return SBSERVICES_E_INVALID_ARG; @@ -104,7 +100,7 @@ sbservices_error_t sbservices_client_new(idevice_t device, uint16_t port, sbserv sbservices_client_t client_loc = (sbservices_client_t) malloc(sizeof(struct sbservices_client_private)); client_loc->parent = plistclient; - client_loc->mutex = g_mutex_new(); + pthread_mutex_init(&client_loc->mutex, NULL); *client = client_loc; return SBSERVICES_E_SUCCESS; @@ -126,9 +122,7 @@ sbservices_error_t sbservices_client_free(sbservices_client_t client) sbservices_error_t err = sbservices_error(property_list_service_client_free(client->parent)); client->parent = NULL; - if (client->mutex) { - g_mutex_free(client->mutex); - } + pthread_mutex_destroy(&client->mutex); free(client); 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 @@ #ifndef ISBSERVICES_H #define ISBSERVICES_H -#include <glib.h> +#include <pthread.h> #include "libimobiledevice/sbservices.h" #include "property_list_service.h" struct sbservices_client_private { property_list_service_client_t parent; - GMutex *mutex; + pthread_mutex_t mutex; }; #endif |