diff options
Diffstat (limited to 'src/AFC.c')
| -rw-r--r-- | src/AFC.c | 17 |
1 files changed, 12 insertions, 5 deletions
| @@ -34,10 +34,11 @@ const int MAXIMUM_PACKET_SIZE = (2 << 15) - 32; | |||
| 34 | static void afc_lock(iphone_afc_client_t client) | 34 | static void afc_lock(iphone_afc_client_t client) |
| 35 | { | 35 | { |
| 36 | log_debug_msg("Locked\n"); | 36 | log_debug_msg("Locked\n"); |
| 37 | while (client->lock) { | 37 | /*while (client->lock) { |
| 38 | usleep(500); // they say it's obsolete, but whatever | 38 | usleep(500); // they say it's obsolete, but whatever |
| 39 | } | 39 | } |
| 40 | client->lock = 1; | 40 | client->lock = 1; */ |
| 41 | g_mutex_lock(client->mutex); | ||
| 41 | } | 42 | } |
| 42 | 43 | ||
| 43 | /** Unlocks an AFC client, done for thread safety stuff. | 44 | /** Unlocks an AFC client, done for thread safety stuff. |
| @@ -47,7 +48,8 @@ static void afc_lock(iphone_afc_client_t client) | |||
| 47 | static void afc_unlock(iphone_afc_client_t client) | 48 | static void afc_unlock(iphone_afc_client_t client) |
| 48 | { // just to be pretty | 49 | { // just to be pretty |
| 49 | log_debug_msg("Unlocked\n"); | 50 | log_debug_msg("Unlocked\n"); |
| 50 | client->lock = 0; | 51 | //client->lock = 0; |
| 52 | g_mutex_unlock(client->mutex); | ||
| 51 | } | 53 | } |
| 52 | 54 | ||
| 53 | /** Makes a connection to the AFC service on the phone. | 55 | /** Makes a connection to the AFC service on the phone. |
| @@ -61,6 +63,10 @@ static void afc_unlock(iphone_afc_client_t client) | |||
| 61 | iphone_error_t iphone_afc_new_client(iphone_device_t device, int src_port, int dst_port, iphone_afc_client_t * client) | 63 | iphone_error_t iphone_afc_new_client(iphone_device_t device, int src_port, int dst_port, iphone_afc_client_t * client) |
| 62 | { | 64 | { |
| 63 | int ret = IPHONE_E_SUCCESS; | 65 | int ret = IPHONE_E_SUCCESS; |
| 66 | |||
| 67 | //makes sure thread environment is available | ||
| 68 | if (!g_thread_supported()) | ||
| 69 | g_thread_init(NULL); | ||
| 64 | iphone_afc_client_t client_loc = (iphone_afc_client_t) malloc(sizeof(struct iphone_afc_client_int)); | 70 | iphone_afc_client_t client_loc = (iphone_afc_client_t) malloc(sizeof(struct iphone_afc_client_int)); |
| 65 | 71 | ||
| 66 | if (!device) | 72 | if (!device) |
| @@ -92,6 +98,7 @@ iphone_error_t iphone_afc_new_client(iphone_device_t device, int src_port, int d | |||
| 92 | client_loc->afc_packet->header2 = 0x4141504C; | 98 | client_loc->afc_packet->header2 = 0x4141504C; |
| 93 | client_loc->file_handle = 0; | 99 | client_loc->file_handle = 0; |
| 94 | client_loc->lock = 0; | 100 | client_loc->lock = 0; |
| 101 | client_loc->mutex = g_mutex_new(); | ||
| 95 | 102 | ||
| 96 | *client = client_loc; | 103 | *client = client_loc; |
| 97 | return IPHONE_E_SUCCESS; | 104 | return IPHONE_E_SUCCESS; |
