Lely core libraries
2.2.5
|
Go to the documentation of this file.
25 #define LELY_CAN_BUF_INLINE extern inline
33 #ifndef LELY_CAN_BUF_SIZE
34 #define LELY_CAN_BUF_SIZE 16
45 while (buf->
size - 1 < size)
55 #ifdef LELY_NO_ATOMICS
59 atomic_init(&buf->
begin, 0);
60 atomic_init(&buf->
end, 0);
79 struct can_buf *buf = malloc(
sizeof(*buf));
100 can_buf_destroy(
struct can_buf *buf)
115 #ifdef LELY_NO_ATOMICS
120 size_t end = atomic_load(&buf->
end) & buf->
size;
129 while (
size - 1 < buf->
size - capacity + n)
135 realloc(buf->
ptr, (size + 1) *
sizeof(
struct can_msg));
147 begin += size - buf->
size;
149 memmove(dst, src, (end - src) *
sizeof(
struct can_msg));
153 #ifdef LELY_NO_ATOMICS
157 atomic_store(&buf->
begin, begin);
158 atomic_store(&buf->
end, end);
161 return (begin - end - 1) & buf->
size;
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.
struct can_msg * ptr
A pointer to the allocated memory for the buffer.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
void can_buf_fini(struct can_buf *buf)
Finalizes a CAN frame buffer.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
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.
int can_buf_init(struct can_buf *buf, size_t size)
Initializes a CAN frame buffer.
#define LELY_CAN_BUF_SIZE
The minimum size (in number of frames) of a CAN frame buffer.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
size_t begin
The offset (with respect to ptr) of the first value available for reading (and two past the last avai...
struct can_buf * can_buf_create(size_t size)
Allocates and initializes a CAN frame buffer.
size_t end
The offset (with respect to ptr) of one past the last value available for reading (and the first avai...