12 return data[(pos->
head + index) % pos->
count];
23 rb->
data = (
u8 *) kcalloc<u8>(capacity);
62 if (new_capacity < buffer->pos.count)
64 void *new_data = kcalloc<char>(new_capacity);
68 while (i < buffer->pos.count)
76 buffer->pos.capacity = new_capacity;
89 size_t second_part =
size - first_part_size;
90 memcpy(data + first_part_i, target, first_part_size);
91 memcpy(data, target + first_part_size, second_part);
103 size_t first_part_size = std::min(
size, pos->
capacity - first_part_i);
105 size_t second_part_i = 0;
106 size_t second_part_size =
size - first_part_size;
108 memcpy(target, data + first_part_i, first_part_size);
109 memcpy(target + first_part_size, data + second_part_i, second_part_size);
123 size_t first_part_size = std::min(
size, pos->
capacity - first_part_i);
125 size_t second_part_i = 0;
126 size_t second_part_size =
size - first_part_size;
128 memcpy(data + first_part_i, target, first_part_size);
129 memcpy(data + second_part_i, target + first_part_size, second_part_size);
141 size_t first_part_i = pos->
head;
142 size_t first_part_size = std::min(
size, pos->
capacity - first_part_i);
144 size_t second_part_i = 0;
145 size_t second_part_size =
size - first_part_size;
147 memcpy(target, data + first_part_i, first_part_size);
148 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)
T * create(Args &&...args)
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)