From: Guus Sliepen Date: Thu, 9 Nov 2017 19:12:29 +0000 (+0100) Subject: Properly initialize mesh->outpacketqueue. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=a1b6ee1e25c9b0cbd2265d86a2d4020eddba735b;p=meshlink Properly initialize mesh->outpacketqueue. --- diff --git a/src/meshlink.c b/src/meshlink.c index d4a5b2a4..769e52c6 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1013,6 +1013,8 @@ meshlink_handle_t *meshlink_open(const char *confbase, const char *name, const c event_loop_init(&mesh->loop); mesh->loop.data = mesh; + meshlink_queue_init(&mesh->outpacketqueue); + // Check whether meshlink.conf already exists char filename[PATH_MAX]; diff --git a/src/meshlink_internal.h b/src/meshlink_internal.h index 15390253..a727bb53 100644 --- a/src/meshlink_internal.h +++ b/src/meshlink_internal.h @@ -76,7 +76,6 @@ struct meshlink_handle { pthread_t thread; bool threadstarted; - pthread_mutex_t outpacketqueue_mutex; pthread_mutex_t mesh_mutex; event_loop_t loop; listen_socket_t listen_socket[MAXSOCKETS]; diff --git a/src/meshlink_queue.h b/src/meshlink_queue.h index fc751a8f..99623180 100644 --- a/src/meshlink_queue.h +++ b/src/meshlink_queue.h @@ -36,6 +36,15 @@ typedef struct meshlink_queue_item { struct meshlink_queue_item *next; } meshlink_queue_item_t; +static inline void meshlink_queue_init(meshlink_queue_t *queue) { + queue->head = NULL; + queue->tail = NULL; + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT); + pthread_mutex_init(&queue->mutex, &attr); +} + static inline bool meshlink_queue_push(meshlink_queue_t *queue, void *data) { meshlink_queue_item_t *item = malloc(sizeof(*item)); diff --git a/src/net.h b/src/net.h index afefa17b..0ff313d0 100644 --- a/src/net.h +++ b/src/net.h @@ -110,8 +110,6 @@ extern void retry(struct meshlink_handle *mesh); #ifndef HAVE_MINGW #define closesocket(s) close(s) -#else -extern CRITICAL_SECTION mutex; #endif #endif