|
PatchworkOS
966e257
A non-POSIX operating system.
|
Ring buffer. More...
Ring buffer.
Data Structures | |
| struct | ring_t |
| Ring buffer structure. More... | |
Macros | |
| #define | RING_CREATE(bufferPtr, bufferSize) {.buffer = bufferPtr, .size = bufferSize, .readIndex = 0, .writeIndex = 0, .dataLength = 0} |
| Create a ring buffer initializer. | |
Functions | |
| static void | ring_init (ring_t *ring, void *buffer, uint64_t size) |
| Initialize a ring buffer. | |
| static uint64_t | ring_data_length (const ring_t *ring) |
| Get the length of data currently stored in the ring buffer. | |
| static uint64_t | ring_free_length (const ring_t *ring) |
| Get the length of free space in the ring buffer. | |
| static uint64_t | ring_write (ring_t *ring, const void *buffer, uint64_t count) |
| Write data to the ring buffer. | |
| static uint64_t | ring_read (ring_t *ring, void *buffer, uint64_t count) |
| Read data from the ring buffer. | |
| static uint64_t | ring_read_at (const ring_t *ring, uint64_t offset, void *buffer, uint64_t count) |
| Read data from the ring buffer at a specific offset without modifying the read index. | |
| static void | ring_move_read_forward (ring_t *ring, uint64_t offset) |
| Move the read index forward by a specified offset. | |
| static uint64_t | ring_get_byte (const ring_t *ring, uint64_t offset, uint8_t *byte) |
| Get a byte from the ring buffer at a specific offset without modifying the read index. | |
| #define RING_CREATE | ( | bufferPtr, | |
| bufferSize | |||
| ) | {.buffer = bufferPtr, .size = bufferSize, .readIndex = 0, .writeIndex = 0, .dataLength = 0} |
Write data to the ring buffer.
If the data to be written exceeds the free space in the buffer, the oldest data will be overwritten.
| ring | Pointer to the ring buffer. |
| buffer | Pointer to the data to write. |
| count | Number of bytes to write. |
Definition at line 85 of file ring.h.
Read data from the ring buffer.
| ring | Pointer to the ring buffer. |
| buffer | Pointer to the buffer to store the read data. |
| count | Number of bytes to read. |
Definition at line 121 of file ring.h.
|
inlinestatic |
Read data from the ring buffer at a specific offset without modifying the read index.
| ring | Pointer to the ring buffer. |
| offset | Offset from the current read index to start reading. |
| buffer | Pointer to the buffer to store the read data. |
| count | Number of bytes to read. |
Definition at line 156 of file ring.h.
Move the read index forward by a specified offset.
If the offset exceeds the current data length, no action is taken.
| ring | Pointer to the ring buffer. |
| offset | Number of bytes to move the read index forward. |
Definition at line 191 of file ring.h.
Get a byte from the ring buffer at a specific offset without modifying the read index.
| ring | Pointer to the ring buffer. |
| offset | Offset from the current read index to get the byte. |
| byte | Pointer to store the retrieved byte. |
ERR if offset is out of bounds. Definition at line 210 of file ring.h.