From: Saverio Proto Date: Wed, 28 May 2014 20:14:49 +0000 (+0200) Subject: Add thread mutex X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=19de00686f3972fbdf6d27213b892dfec9b2172e;p=meshlink Add thread mutex --- diff --git a/src/meshlink.c b/src/meshlink.c index 34c3816e..eac80c27 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -734,6 +734,7 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name) { meshlink_handle_t *mesh = xzalloc(sizeof *mesh); mesh->confbase = xstrdup(confbase); mesh->name = xstrdup(name); + pthread_mutex_init ( &(mesh->outpacketqueue_mutex), NULL); event_loop_init(&mesh->loop); mesh->loop.data = mesh; @@ -853,7 +854,9 @@ bool meshlink_send(meshlink_handle_t *mesh, meshlink_node_t *destination, const packet_in_queue->destination=destination; packet_in_queue->data=data; packet_in_queue->len=len; + pthread_mutex_lock(&(mesh->outpacketqueue_mutex)); list_insert_tail(mesh->outpacketqueue,packet_in_queue); + pthread_mutex_unlock(&(mesh->outpacketqueue_mutex)); //notify event loop diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index 39793a01..c75311bb 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -60,6 +60,7 @@ struct meshlink_handle { meshlink_log_level_t log_level; pthread_t thread; + pthread_mutex_t outpacketqueue_mutex; event_loop_t loop; listen_socket_t listen_socket[MAXSOCKETS]; int listen_sockets;