summaryrefslogtreecommitdiffstats
path: root/src/AFC.c
diff options
context:
space:
mode:
authorGravatar Jonathan Beck2008-09-14 22:23:01 +0200
committerGravatar Jonathan Beck2008-10-25 17:43:47 +0200
commit587990158fe0a7ee9a8ee086d83d1d61d61cc56b (patch)
treeedbb0422140e5df84b3e547984b7f87833619757 /src/AFC.c
parent0691e6e4cee6f0e54b432fbf0e478d699e964eaf (diff)
downloadlibplist-587990158fe0a7ee9a8ee086d83d1d61d61cc56b.tar.gz
libplist-587990158fe0a7ee9a8ee086d83d1d61d61cc56b.tar.bz2
Change lock to mutex and add tool to check AFC in multithreaded env.
Diffstat (limited to 'src/AFC.c')
-rw-r--r--src/AFC.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/AFC.c b/src/AFC.c
index 4d6b269..144efe1 100644
--- a/src/AFC.c
+++ b/src/AFC.c
@@ -34,10 +34,11 @@ const int MAXIMUM_PACKET_SIZE = (2 << 15) - 32;
static void afc_lock(iphone_afc_client_t client)
{
log_debug_msg("Locked\n");
- while (client->lock) {
- usleep(500); // they say it's obsolete, but whatever
- }
- client->lock = 1;
+ /*while (client->lock) {
+ usleep(500); // they say it's obsolete, but whatever
+ }
+ client->lock = 1; */
+ g_mutex_lock(client->mutex);
}
/** Unlocks an AFC client, done for thread safety stuff.
@@ -47,7 +48,8 @@ static void afc_lock(iphone_afc_client_t client)
static void afc_unlock(iphone_afc_client_t client)
{ // just to be pretty
log_debug_msg("Unlocked\n");
- client->lock = 0;
+ //client->lock = 0;
+ g_mutex_unlock(client->mutex);
}
/** Makes a connection to the AFC service on the phone.
@@ -61,6 +63,10 @@ static void afc_unlock(iphone_afc_client_t client)
iphone_error_t iphone_afc_new_client(iphone_device_t device, int src_port, int dst_port, iphone_afc_client_t * client)
{
int ret = IPHONE_E_SUCCESS;
+
+ //makes sure thread environment is available
+ if (!g_thread_supported())
+ g_thread_init(NULL);
iphone_afc_client_t client_loc = (iphone_afc_client_t) malloc(sizeof(struct iphone_afc_client_int));
if (!device)
@@ -92,6 +98,7 @@ iphone_error_t iphone_afc_new_client(iphone_device_t device, int src_port, int d
client_loc->afc_packet->header2 = 0x4141504C;
client_loc->file_handle = 0;
client_loc->lock = 0;
+ client_loc->mutex = g_mutex_new();
*client = client_loc;
return IPHONE_E_SUCCESS;