mbox.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Kaspar Schleiser <kaspar@schleiser.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
22 #ifndef MBOX_H
23 #define MBOX_H
24 
25 #include "list.h"
26 #include "cib.h"
27 #include "msg.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
34 #define MBOX_INIT(queue, queue_size) { \
35  { 0 }, { 0 }, CIB_INIT(queue_size), queue \
36 }
37 
41 typedef struct {
46 } mbox_t;
47 
48 enum {
51 };
52 
62 static inline void mbox_init(mbox_t *mbox, msg_t *queue,
63  unsigned int queue_size)
64 {
65  mbox_t m = MBOX_INIT(queue, queue_size);
66 
67  *mbox = m;
68 }
69 
84 int _mbox_put(mbox_t *mbox, msg_t *msg, int blocking);
85 
100 int _mbox_get(mbox_t *mbox, msg_t *msg, int blocking);
101 
111 static inline void mbox_put(mbox_t *mbox, msg_t *msg)
112 {
113  _mbox_put(mbox, msg, BLOCKING);
114 }
115 
127 static inline int mbox_try_put(mbox_t *mbox, msg_t *msg)
128 {
129  return _mbox_put(mbox, msg, NON_BLOCKING);
130 }
131 
141 static inline void mbox_get(mbox_t *mbox, msg_t *msg)
142 {
143  _mbox_get(mbox, msg, BLOCKING);
144 }
145 
157 static inline int mbox_try_get(mbox_t *mbox, msg_t *msg)
158 {
159  return _mbox_get(mbox, msg, NON_BLOCKING);
160 }
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
167 #endif /* MBOX_H */
Mailbox struct definition.
Definition: mbox.h:41
blocking mode
Definition: mbox.h:50
list_node_t writers
list of threads waiting to send
Definition: mbox.h:43
#define MBOX_INIT(queue, queue_size)
Static initializer for mbox objects.
Definition: mbox.h:34
circular integer buffer structure
Definition: cib.h:34
static void mbox_get(mbox_t *mbox, msg_t *msg)
Get message from mailbox.
Definition: mbox.h:141
static void mbox_put(mbox_t *mbox, msg_t *msg)
Add message to mailbox.
Definition: mbox.h:111
static int mbox_try_get(mbox_t *mbox, msg_t *msg)
Get message from mailbox.
Definition: mbox.h:157
non-blocking mode
Definition: mbox.h:49
static int mbox_try_put(mbox_t *mbox, msg_t *msg)
Add message to mailbox.
Definition: mbox.h:127
int _mbox_put(mbox_t *mbox, msg_t *msg, int blocking)
Add message to mailbox.
Messaging API for inter process communication.
Intrusive linked list.
list_node_t readers
list of threads waiting for message
Definition: mbox.h:42
Describes a message object which can be sent between threads.
Definition: msg.h:184
List node structure.
Definition: list.h:40
msg_t * msg_array
ptr to array of msg queue
Definition: mbox.h:45
Circular integer buffer interface.
cib_t cib
cib for msg array
Definition: mbox.h:44
int _mbox_get(mbox_t *mbox, msg_t *msg, int blocking)
Get message from mailbox.
static void mbox_init(mbox_t *mbox, msg_t *queue, unsigned int queue_size)
Initialize mbox object.
Definition: mbox.h:62