28 #ifndef LELY_CAN_BUF_H_
29 #define LELY_CAN_BUF_H_
31 #ifndef LELY_NO_ATOMICS
32 #define LELY_NO_ATOMICS 1
33 #ifndef LELY_NO_THREADS
35 #ifndef __STDC_NO_ATOMICS__
36 #undef LELY_NO_ATOMICS
42 #ifndef LELY_CAN_BUF_INLINE
43 #define LELY_CAN_BUF_INLINE static inline
62 #ifdef LELY_NO_ATOMICS
72 #ifdef LELY_NO_ATOMICS
80 #ifdef LELY_NO_ATOMICS
81 #define CAN_BUF_INIT \
86 #define CAN_BUF_INIT \
88 NULL, 0, ATOMIC_VAR_INIT(0), ATOMIC_VAR_INIT(0) \
127 void can_buf_destroy(
struct can_buf *buf);
201 #ifdef LELY_NO_ATOMICS
204 size_t begin = atomic_load_explicit(&buf->
begin, memory_order_acquire);
205 atomic_store_explicit(&buf->
end,
begin, memory_order_release);
212 #ifdef LELY_NO_ATOMICS
216 size_t begin = atomic_load_explicit(
218 size_t end = atomic_load_explicit(
219 &((
struct can_buf *)buf)->
end, memory_order_acquire);
228 #ifdef LELY_NO_ATOMICS
232 size_t begin = atomic_load_explicit(
234 size_t end = atomic_load_explicit(
235 &((
struct can_buf *)buf)->
end, memory_order_acquire);
244 #ifdef LELY_NO_ATOMICS
247 size_t begin = atomic_load_explicit(&buf->
begin, memory_order_acquire);
249 for (
size_t i = 0; i < n; i++) {
250 #ifdef LELY_NO_ATOMICS
253 size_t end = atomic_load_explicit(
254 &buf->
end, memory_order_acquire);
270 #ifdef LELY_NO_ATOMICS
273 size_t begin = atomic_load_explicit(&buf->
begin, memory_order_acquire);
275 for (
size_t i = 0; i < n; i++) {
276 #ifdef LELY_NO_ATOMICS
279 size_t end = atomic_load_explicit(
280 &buf->
end, memory_order_acquire);
289 #ifdef LELY_NO_ATOMICS
292 atomic_store_explicit(&buf->
begin,
begin, memory_order_release);
302 #ifdef LELY_NO_ATOMICS
305 size_t end = atomic_load_explicit(&buf->
end, memory_order_acquire);
307 for (
size_t i = 0; i < n; i++) {
308 #ifdef LELY_NO_ATOMICS
311 size_t begin = atomic_load_explicit(
312 &buf->
begin, memory_order_acquire);
319 #ifdef LELY_NO_ATOMICS
322 atomic_store_explicit(&buf->
end,
end, memory_order_release);
struct can_buf * can_buf_create(size_t size)
Allocates and initializes a CAN frame buffer.
void can_buf_clear(struct can_buf *buf)
Clears a CAN frame buffer.
size_t can_buf_size(const struct can_buf *buf)
Returns the number of frames available for reading in a CAN buffer.
size_t can_buf_capacity(const struct can_buf *buf)
Returns the number of frames available for writing in a CAN buffer.
size_t can_buf_reserve(struct can_buf *buf, size_t n)
Resizes a CAN frame buffer, if necessary, to make room for at least n additional frames.
size_t can_buf_read(struct can_buf *buf, struct can_msg *ptr, size_t n)
Reads, and removes, frames from a CAN frame buffer.
int can_buf_init(struct can_buf *buf, size_t size)
Initializes a CAN frame buffer.
size_t can_buf_peek(struct can_buf *buf, struct can_msg *ptr, size_t n)
Reads, but does not remove, frames from a CAN frame buffer.
void can_buf_fini(struct can_buf *buf)
Finalizes a CAN frame buffer.
size_t can_buf_write(struct can_buf *buf, const struct can_msg *ptr, size_t n)
Writes frames to a CAN frame buffer.
This header file is part of the CAN library; it contains the CAN frame declarations.
This header file is part of the C11 and POSIX compatibility library; it includes <stdatomic....
struct can_msg * ptr
A pointer to the allocated memory for the buffer.
size_t end
The offset (with respect to ptr) of one past the last value available for reading (and the first avai...
size_t begin
The offset (with respect to ptr) of the first value available for reading (and two past the last avai...
size_t size
The total size (in number of frames) of the buffer, excluding the unused frame used to distinguish be...
A CAN or CAN FD format frame.