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__
42#ifndef LELY_CAN_BUF_INLINE
43#define LELY_CAN_BUF_INLINE static inline
88 NULL, 0, ATOMIC_VAR_INIT(0), ATOMIC_VAR_INIT(0) \
127void can_buf_destroy(
struct can_buf *buf);
201#ifdef LELY_NO_ATOMICS
212#ifdef LELY_NO_ATOMICS
216 size_t begin = atomic_load_explicit(
218 size_t end = atomic_load_explicit(
228#ifdef LELY_NO_ATOMICS
232 size_t begin = atomic_load_explicit(
234 size_t end = atomic_load_explicit(
244#ifdef LELY_NO_ATOMICS
249 for (
size_t i = 0; i < n; i++) {
250#ifdef LELY_NO_ATOMICS
253 size_t end = atomic_load_explicit(
270#ifdef LELY_NO_ATOMICS
275 for (
size_t i = 0; i < n; i++) {
276#ifdef LELY_NO_ATOMICS
279 size_t end = atomic_load_explicit(
289#ifdef LELY_NO_ATOMICS
302#ifdef LELY_NO_ATOMICS
307 for (
size_t i = 0; i < n; i++) {
308#ifdef LELY_NO_ATOMICS
311 size_t begin = atomic_load_explicit(
319#ifdef LELY_NO_ATOMICS
void can_buf_clear(struct can_buf *buf)
Clears a CAN frame buffer.
struct can_buf * can_buf_create(size_t size)
Allocates and initializes 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....
@ memory_order_release
A store operation performs a release operation on the affected memory location.
@ memory_order_acquire
A load operation performs an acquire operation on the affected memory location.
#define atomic_store_explicit(object, desired, order)
Atomically replaces the value at object with the value of desired.
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.