]> git.meshlink.io Git - meshlink/commitdiff
Add thread mutex
authorSaverio Proto <zioproto@gmail.com>
Wed, 28 May 2014 20:14:49 +0000 (22:14 +0200)
committerSaverio Proto <zioproto@gmail.com>
Wed, 28 May 2014 20:14:49 +0000 (22:14 +0200)
src/meshlink.c
src/meshlink_internal.h

index 34c3816e43b13b96b2ec5cde3bd17da9e3babef5..eac80c278dea42d2502bcc833779f5c59fea2cf5 100644 (file)
@@ -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
 
index 39793a015827097431464d81670c7abcf205d7fa..c75311bb55a620a3500576daf5792d875edebb2c 100644 (file)
@@ -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;