|
PatchworkOS
|
Ring buffer. More...
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. | |
Ring buffer.
| #define RING_CREATE | ( | bufferPtr, | |
| bufferSize | |||
| ) | {.buffer = bufferPtr, .size = bufferSize, .readIndex = 0, .writeIndex = 0, .dataLength = 0} |
Get the length of data currently stored in the ring buffer.
| ring | Pointer to the ring buffer. |
Definition at line 58 of file ring.h.
References ring_t::dataLength, and ring.
Referenced by local_socket_poll(), local_socket_recv(), log_file_flush_to_screen(), pipe_poll(), pipe_read(), ring_move_read_forward(), and ring_read().
Get the length of free space in the ring buffer.
| ring | Pointer to the ring buffer. |
Definition at line 69 of file ring.h.
References ring_t::dataLength, ring, and ring_t::size.
Referenced by local_socket_poll(), local_socket_send(), pipe_poll(), pipe_write(), and ring_write().
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.
References ring_t::buffer, ring_t::dataLength, ERR, ring_t::readIndex, ring, and ring_t::size.
Referenced by log_file_flush_to_screen().
Initialize a ring buffer.
| ring | Pointer to the ring buffer to initialize. |
| buffer | Pointer to the buffer memory. |
| size | Size of the buffer memory in bytes. |
Definition at line 43 of file ring.h.
References ring_t::buffer, buffer, ring_t::dataLength, ring_t::readIndex, ring, ring_t::size, and ring_t::writeIndex.
Referenced by local_conn_new(), pipe_open(), and pipe_open2().
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.
References ring_t::dataLength, ring_t::readIndex, ring, ring_data_length(), and ring_t::size.
Referenced by local_socket_recv().
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.
References ring_t::buffer, buffer, count, ring_t::dataLength, ERR, memcpy(), ring_t::readIndex, ring, ring_data_length(), and ring_t::size.
Referenced by local_socket_recv(), and pipe_read().
|
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.
References ring_t::buffer, buffer, count, ring_t::dataLength, memcpy(), ring_t::readIndex, ring, and ring_t::size.
Referenced by local_socket_recv(), log_file_flush_to_screen(), and log_file_op_read().
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.
References ring_t::buffer, buffer, count, ring_t::dataLength, memcpy(), ring_t::readIndex, ring, ring_free_length(), ring_t::size, and ring_t::writeIndex.
Referenced by local_socket_send(), log_file_write(), and pipe_write().