Skip to content

Commit bfecb77

Browse files
teburdMaureenHelm
authored andcommitted
rtio: Make rtio_mpsc.h C++ friendly
C++ requires casting void * as the implicit cast isn't enough and the C++ sample app fails to build without duplicating type information here. Do that, and wrap it in extern C allowing the C++ to include rtio_mpsc.h directly or indirectly. Signed-off-by: Tom Burdick <[email protected]>
1 parent 610d307 commit bfecb77

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

include/zephyr/rtio/rtio_mpsc.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include <zephyr/sys/atomic.h>
1515
#include <zephyr/kernel.h>
1616

17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
1721
/**
1822
* @brief RTIO Multiple Producer Single Consumer (MPSC) Queue API
1923
* @defgroup rtio_mpsc RTIO MPSC API
@@ -94,7 +98,7 @@ static inline void rtio_mpsc_push(struct rtio_mpsc *q, struct rtio_mpsc_node *n)
9498
atomic_ptr_set(&n->next, NULL);
9599

96100
key = arch_irq_lock();
97-
prev = atomic_ptr_set(&q->head, n);
101+
prev = (struct rtio_mpsc_node *)atomic_ptr_set(&q->head, n);
98102
atomic_ptr_set(&prev->next, n);
99103
arch_irq_unlock(key);
100104
}
@@ -109,7 +113,7 @@ static inline struct rtio_mpsc_node *rtio_mpsc_pop(struct rtio_mpsc *q)
109113
{
110114
struct rtio_mpsc_node *head;
111115
struct rtio_mpsc_node *tail = q->tail;
112-
struct rtio_mpsc_node *next = atomic_ptr_get(&tail->next);
116+
struct rtio_mpsc_node *next = (struct rtio_mpsc_node *)atomic_ptr_get(&tail->next);
113117

114118
/* Skip over the stub/sentinel */
115119
if (tail == &q->stub) {
@@ -119,7 +123,7 @@ static inline struct rtio_mpsc_node *rtio_mpsc_pop(struct rtio_mpsc *q)
119123

120124
q->tail = next;
121125
tail = next;
122-
next = atomic_ptr_get(&next->next);
126+
next = (struct rtio_mpsc_node *)atomic_ptr_get(&next->next);
123127
}
124128

125129
/* If next is non-NULL then a valid node is found, return it */
@@ -128,7 +132,7 @@ static inline struct rtio_mpsc_node *rtio_mpsc_pop(struct rtio_mpsc *q)
128132
return tail;
129133
}
130134

131-
head = atomic_ptr_get(&q->head);
135+
head = (struct rtio_mpsc_node *)atomic_ptr_get(&q->head);
132136

133137
/* If next is NULL, and the tail != HEAD then the queue has pending
134138
* updates that can't yet be accessed.
@@ -139,7 +143,7 @@ static inline struct rtio_mpsc_node *rtio_mpsc_pop(struct rtio_mpsc *q)
139143

140144
rtio_mpsc_push(q, &q->stub);
141145

142-
next = atomic_ptr_get(&tail->next);
146+
next = (struct rtio_mpsc_node *)atomic_ptr_get(&tail->next);
143147

144148
if (next != NULL) {
145149
q->tail = next;
@@ -153,4 +157,9 @@ static inline struct rtio_mpsc_node *rtio_mpsc_pop(struct rtio_mpsc *q)
153157
* @}
154158
*/
155159

160+
#ifdef __cplusplus
161+
}
162+
#endif
163+
164+
156165
#endif /* ZEPHYR_RTIO_MPSC_H_ */

0 commit comments

Comments
 (0)