libosmocore  1.5.1
Osmocom core library
it_q.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <osmocom/core/select.h>
5 #include <pthread.h>
6 
16 struct osmo_it_q {
17  /* entry in global list of message queues */
18  struct llist_head entry;
19 
20  /* the actual list of user structs. HEAD: first in queue; TAIL: last in queue */
21  struct llist_head list;
22  /* A pthread mutex to safeguard accesses to the queue. No rwlock as we always write. */
23  pthread_mutex_t mutex;
24  /* Current count of messages in the queue */
25  unsigned int current_length;
26  /* osmo-fd wrapped eventfd */
27  struct osmo_fd event_ofd;
28 
29  /* a user-defined name for this queue */
30  const char *name;
31  /* maximum permitted length of queue */
32  unsigned int max_length;
33  /* read call-back, called for each de-queued message */
34  void (*read_cb)(struct osmo_it_q *q, struct llist_head *item);
35  /* opaque data pointer passed through to call-back function */
36  void *data;
37 };
38 
39 struct osmo_it_q *osmo_it_q_by_name(const char *name);
40 
41 int _osmo_it_q_enqueue(struct osmo_it_q *queue, struct llist_head *item);
42 #define osmo_it_q_enqueue(queue, item, member) \
43  _osmo_it_q_enqueue(queue, &(item)->member)
44 
45 struct llist_head *_osmo_it_q_dequeue(struct osmo_it_q *queue);
46 #define osmo_it_q_dequeue(queue, item, member) do { \
47  struct llist_head *l = _osmo_it_q_dequeue(queue); \
48  if (!l) \
49  *item = NULL; \
50  else \
51  *item = llist_entry(l, typeof(**item), member); \
52 } while (0)
53 
54 
55 struct osmo_it_q *osmo_it_q_alloc(void *ctx, const char *name, unsigned int max_length,
56 
57  void (*read_cb)(struct osmo_it_q *q, struct llist_head *item),
58  void *data);
59 void osmo_it_q_destroy(struct osmo_it_q *q);
60 void osmo_it_q_flush(struct osmo_it_q *q);
61 
osmo_it_q::list
struct llist_head list
Definition: it_q.h:21
osmo_it_q::mutex
pthread_mutex_t mutex
Definition: it_q.h:23
osmo_it_q::entry
struct llist_head entry
Definition: it_q.h:18
osmo_it_q
One instance of an inter-thread queue.
Definition: it_q.h:16
_osmo_it_q_enqueue
int _osmo_it_q_enqueue(struct osmo_it_q *queue, struct llist_head *item)
Thread-safe en-queue to an inter-thread message queue.
Definition: it_q.c:231
name
const char * name
osmo_it_q::name
const char * name
Definition: it_q.h:30
osmo_it_q_alloc
struct osmo_it_q * osmo_it_q_alloc(void *ctx, const char *name, unsigned int max_length, void(*read_cb)(struct osmo_it_q *q, struct llist_head *item), void *data)
Allocate a new inter-thread message queue.
Definition: it_q.c:126
data
uint8_t data[0]
osmo_it_q::current_length
unsigned int current_length
Definition: it_q.h:25
osmo_it_q_by_name
struct osmo_it_q * osmo_it_q_by_name(const char *name)
resolve it-queue by its [globally unique] name
Definition: it_q.c:83
osmo_it_q::data
void * data
Definition: it_q.h:36
llist_head
(double) linked list header structure
Definition: linuxlist.h:46
osmo_it_q_flush
void osmo_it_q_flush(struct osmo_it_q *q)
Flush all messages currently present in queue.
Definition: it_q.c:199
osmo_it_q::max_length
unsigned int max_length
Definition: it_q.h:32
select.h
osmo_fd
Structure representing a file dsecriptor.
Definition: select.h:31
osmo_it_q_destroy
void osmo_it_q_destroy(struct osmo_it_q *q)
Destroy a message queue.
Definition: it_q.c:209
_osmo_it_q_dequeue
struct llist_head * _osmo_it_q_dequeue(struct osmo_it_q *queue)
Thread-safe de-queue from an inter-thread message queue.
Definition: it_q.c:255
linuxlist.h
osmo_it_q::event_ofd
struct osmo_fd event_ofd
Definition: it_q.h:27
osmo_it_q::read_cb
void(* read_cb)(struct osmo_it_q *q, struct llist_head *item)
Definition: it_q.h:34