10 return data[(pos->
head + index) % pos->
count];
21 rb->
data = kmalloc(capacity);
60 if (new_capacity < buffer->pos.count)
62 void *new_data = kmalloc(new_capacity);
66 while (i < buffer->pos.count)
74 buffer->pos.capacity = new_capacity;
87 size_t second_part =
size - first_part_size;
88 memcpy(data + first_part_i, target, first_part_size);
89 memcpy(data, target + first_part_size, second_part);
103 size_t second_part_i = 0;
104 size_t second_part_size =
size - first_part_size;
106 memcpy(target, data + first_part_i, first_part_size);
107 memcpy(target + first_part_size, data + second_part_i, second_part_size);
123 size_t second_part_i = 0;
124 size_t second_part_size =
size - first_part_size;
126 memcpy(data + first_part_i, target, first_part_size);
127 memcpy(data + second_part_i, target + first_part_size, second_part_size);
139 size_t first_part_i = pos->
head;
142 size_t second_part_i = 0;
143 size_t second_part_size =
size - first_part_size;
145 memcpy(target, data + first_part_i, first_part_size);
146 memcpy(target + first_part_size, data + second_part_i, second_part_size);
void ring_buffer_destroy(ring_buffer_t *buffer)
ring_buffer_t * ring_buffer_create_at(void *data, size_t capacity)
size_t ring_buffer_pos_pop_back(u8 *data, ring_buffer_pos_t *pos, u8 *target, size_t size)
size_t ring_buffer_pos_pop_front(u8 *data, ring_buffer_pos_t *pos, u8 *target, size_t size)
size_t ring_buffer_pos_push_front(u8 *data, ring_buffer_pos_t *pos, const u8 *target, size_t size)
bool ring_buffer_resize(ring_buffer_t *buffer, size_t new_capacity)
void ring_buffer_pos_init(ring_buffer_pos_t *pos, size_t capacity)
ring_buffer_t * ring_buffer_create(size_t capacity)
size_t ring_buffer_pos_push_back(u8 *data, ring_buffer_pos_t *pos, const u8 *target, size_t size)
static void * memcpy(void *s1, const void *s2, size_t n)
static u8 ring_buffer_get(u8 *data, ring_buffer_pos_t *pos, size_t index)