The friendly Operating System for the Internet of Things
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) {{0}, {0}, CIB_INIT(queue_size), queue}
35 
39 typedef struct {
44 } mbox_t;
45 
46 enum {
49 };
50 
60 static inline void mbox_init(mbox_t *mbox, msg_t *queue, unsigned int queue_size)
61 {
62  mbox_t m = MBOX_INIT(queue, queue_size);
63  *mbox = m;
64 }
65 
80 int _mbox_put(mbox_t *mbox, msg_t *msg, int blocking);
81 
96 int _mbox_get(mbox_t *mbox, msg_t *msg, int blocking);
97 
107 static inline void mbox_put(mbox_t *mbox, msg_t *msg)
108 {
109  _mbox_put(mbox, msg, BLOCKING);
110 }
111 
123 static inline int mbox_try_put(mbox_t *mbox, msg_t *msg)
124 {
125  return _mbox_put(mbox, msg, NON_BLOCKING);
126 }
127 
137 static inline void mbox_get(mbox_t *mbox, msg_t *msg)
138 {
139  _mbox_get(mbox, msg, BLOCKING);
140 }
141 
153 static inline int mbox_try_get(mbox_t *mbox, msg_t *msg)
154 {
155  return _mbox_get(mbox, msg, NON_BLOCKING);
156 }
157 
158 #ifdef __cplusplus
159 }
160 #endif
161 
163 #endif /* MBOX_H */
Mailbox struct definition.
Definition: mbox.h:39
blocking mode
Definition: mbox.h:48
list_node_t writers
list of threads waiting to send
Definition: mbox.h:41
#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:137
static void mbox_put(mbox_t *mbox, msg_t *msg)
Add message to mailbox.
Definition: mbox.h:107
static int mbox_try_get(mbox_t *mbox, msg_t *msg)
Get message from mailbox.
Definition: mbox.h:153
non-blocking mode
Definition: mbox.h:47
static int mbox_try_put(mbox_t *mbox, msg_t *msg)
Add message to mailbox.
Definition: mbox.h:123
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:40
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:43
Circular integer buffer interface.
cib_t cib
cib for msg array
Definition: mbox.h:42
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:60