From 343f819f5a4e7cd1396cd9f31070fa6520d308e7 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 4 Apr 2019 11:04:54 +0200 Subject: WIP: osmo_it_msgq: Osmocom Inter-thread Message Queue This implements an inter-thread message queue based on top of osmocom msgb, linked lists, eventfd and pthread mutex. Change-Id: I30a7233cb0b51a883ad85c8c4165270b32c4be61 --- include/osmocom/core/it_msgq.h | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 include/osmocom/core/it_msgq.h (limited to 'include/osmocom/core/it_msgq.h') diff --git a/include/osmocom/core/it_msgq.h b/include/osmocom/core/it_msgq.h new file mode 100644 index 00000000..17d80d36 --- /dev/null +++ b/include/osmocom/core/it_msgq.h @@ -0,0 +1,44 @@ +#pragma once + +#include +#include +#include +#include + +/*! \defgroup it_msgq Inter-ThreadMessage Queue + * @{ + * \file it_msgq.h */ + +struct osmo_it_msgq { + /* entry in global list of message queues */ + struct llist_head entry; + + /* the actual list of msgb's. HEAD: first in queue; TAIL: last in queue */ + struct llist_head list; + /* A pthread mutex to safeguard accesses to the queue. No rwlock as we always write. */ + pthread_mutex_t mutex; + /* Current count of messages in the queue */ + unsigned int current_length; + /* osmo-fd wrapped eventfd */ + struct osmo_fd event_ofd; + + /* a user-defined name for this queue */ + const char *name; + /* maximum permitted length of queue */ + unsigned int max_length; + /* read call-back, called for each de-queued message */ + void (*read_cb)(struct osmo_it_msgq *q, struct msgb *msg); + /* opaque data pointer passed through to call-back function */ + void *data; +}; + +struct osmo_it_msgq *osmo_it_msgq_by_name(const char *name); +int osmo_it_msgq_enqueue(struct osmo_it_msgq *queue, struct msgb *msg); +struct msgb *osmo_it_msgq_dequeue(struct osmo_it_msgq *queue); +struct osmo_it_msgq *osmo_it_msgq_alloc(void *ctx, const char *name, unsigned int max_length, + void (*read_cb)(struct osmo_it_msgq *q, struct msgb *msg), + void *data); +void osmo_it_msgq_destroy(struct osmo_it_msgq *q); +void osmo_it_msgq_flush(struct osmo_it_msgq *q); + +/*! @} */ -- cgit v1.2.3