summaryrefslogtreecommitdiffstats
path: root/src/client.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2014-11-12 21:58:30 +0100
committerGravatar Nikias Bassen2014-12-02 19:22:25 +0100
commita25009872304f17514089afb48a3e860e7cb9cfe (patch)
tree5a431f341c94b5de628fac67cbdc43de244fe5a7 /src/client.c
parent34e6eeef656a205d4f65f128cb17bc81cca3b4d3 (diff)
downloadusbmuxd-a25009872304f17514089afb48a3e860e7cb9cfe.tar.gz
usbmuxd-a25009872304f17514089afb48a3e860e7cb9cfe.tar.bz2
common: Add thread+mutex implementation and use it where applicablerefactor
Diffstat (limited to 'src/client.c')
-rw-r--r--src/client.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/client.c b/src/client.c
index 4ec4025..baef4c8 100644
--- a/src/client.c
+++ b/src/client.c
@@ -32,7 +32,6 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <arpa/inet.h>
-#include <pthread.h>
#include <fcntl.h>
#include <plist/plist.h>
@@ -43,6 +42,8 @@
#include "device.h"
#include "conf.h"
+#include "common/thread.h"
+
#define CMD_BUF_SIZE 0x10000
#define REPLY_BUF_SIZE 0x10000
@@ -71,7 +72,7 @@ struct mux_client {
};
static struct collection client_list;
-pthread_mutex_t client_list_mutex;
+mutex_t client_list_mutex;
/**
* Receive raw data from the client socket.
@@ -185,9 +186,9 @@ int client_accept(int listenfd)
client->state = CLIENT_COMMAND;
client->events = POLLIN;
- pthread_mutex_lock(&client_list_mutex);
+ mutex_lock(&client_list_mutex);
collection_add(&client_list, client);
- pthread_mutex_unlock(&client_list_mutex);
+ mutex_unlock(&client_list_mutex);
#ifdef SO_PEERCRED
if (log_level >= LL_INFO) {
@@ -220,19 +221,19 @@ void client_close(struct mux_client *client)
free(client->ob_buf);
if(client->ib_buf)
free(client->ib_buf);
- pthread_mutex_lock(&client_list_mutex);
+ mutex_lock(&client_list_mutex);
collection_remove(&client_list, client);
- pthread_mutex_unlock(&client_list_mutex);
+ mutex_unlock(&client_list_mutex);
free(client);
}
void client_get_fds(struct fdlist *list)
{
- pthread_mutex_lock(&client_list_mutex);
+ mutex_lock(&client_list_mutex);
FOREACH(struct mux_client *client, &client_list) {
fdlist_add(list, FD_CLIENT, client->fd, client->events);
} ENDFOREACH
- pthread_mutex_unlock(&client_list_mutex);
+ mutex_unlock(&client_list_mutex);
}
static int send_pkt(struct mux_client *client, uint32_t tag, enum usbmuxd_msgtype msg, void *payload, int payload_length)
@@ -758,14 +759,14 @@ static void process_recv(struct mux_client *client)
void client_process(int fd, short events)
{
struct mux_client *client = NULL;
- pthread_mutex_lock(&client_list_mutex);
+ mutex_lock(&client_list_mutex);
FOREACH(struct mux_client *lc, &client_list) {
if(lc->fd == fd) {
client = lc;
break;
}
} ENDFOREACH
- pthread_mutex_unlock(&client_list_mutex);
+ mutex_unlock(&client_list_mutex);
if(!client) {
usbmuxd_log(LL_INFO, "client_process: fd %d not found in client list", fd);
@@ -787,33 +788,33 @@ void client_process(int fd, short events)
void client_device_add(struct device_info *dev)
{
- pthread_mutex_lock(&client_list_mutex);
+ mutex_lock(&client_list_mutex);
usbmuxd_log(LL_DEBUG, "client_device_add: id %d, location 0x%x, serial %s", dev->id, dev->location, dev->serial);
device_set_visible(dev->id);
FOREACH(struct mux_client *client, &client_list) {
if(client->state == CLIENT_LISTEN)
notify_device_add(client, dev);
} ENDFOREACH
- pthread_mutex_unlock(&client_list_mutex);
+ mutex_unlock(&client_list_mutex);
}
void client_device_remove(int device_id)
{
- pthread_mutex_lock(&client_list_mutex);
+ mutex_lock(&client_list_mutex);
uint32_t id = device_id;
usbmuxd_log(LL_DEBUG, "client_device_remove: id %d", device_id);
FOREACH(struct mux_client *client, &client_list) {
if(client->state == CLIENT_LISTEN)
notify_device_remove(client, id);
} ENDFOREACH
- pthread_mutex_unlock(&client_list_mutex);
+ mutex_unlock(&client_list_mutex);
}
void client_init(void)
{
usbmuxd_log(LL_DEBUG, "client_init");
collection_init(&client_list);
- pthread_mutex_init(&client_list_mutex, NULL);
+ mutex_init(&client_list_mutex);
}
void client_shutdown(void)
@@ -822,6 +823,6 @@ void client_shutdown(void)
FOREACH(struct mux_client *client, &client_list) {
client_close(client);
} ENDFOREACH
- pthread_mutex_destroy(&client_list_mutex);
+ mutex_destroy(&client_list_mutex);
collection_free(&client_list);
}