Lines Matching refs:rbc
102 struct ring_buf_cb *rbc; in ring_buffer_init() local
105 rbc = (struct ring_buf_cb *)malloc(sizeof(struct ring_buf_cb)); in ring_buffer_init()
106 if (rbc == NULL) { in ring_buffer_init()
110 memset(rbc, 0, sizeof(struct ring_buf_cb)); in ring_buffer_init()
112 rbc->bufs = (rb_entry_t *)malloc(num_bufs * sizeof(rb_entry_t)); in ring_buffer_init()
113 if (rbc->bufs == NULL) { in ring_buffer_init()
114 free(rbc); in ring_buffer_init()
118 memset(rbc->bufs, 0, (num_bufs * sizeof(rb_entry_t))); in ring_buffer_init()
120 rbc->each_buf_size = size_of_buf; in ring_buffer_init()
121 rbc->max_num_bufs = num_bufs; in ring_buffer_init()
123 status = pthread_mutex_init(&rbc->rb_rw_lock, NULL); in ring_buffer_init()
128 rbc->threshold_reached = RB_FALSE; in ring_buffer_init()
129 return rbc; in ring_buffer_init()
134 rbc_t *rbc = (rbc_t *)ctx; in ring_buffer_deinit() local
138 status = pthread_mutex_destroy(&rbc->rb_rw_lock); in ring_buffer_deinit()
143 for (buf_no = 0; buf_no < rbc->max_num_bufs; buf_no++) { in ring_buffer_deinit()
144 free(rbc->bufs[buf_no].data); in ring_buffer_deinit()
146 free(rbc->bufs); in ring_buffer_deinit()
147 free(rbc); in ring_buffer_deinit()
157 rbc_t *rbc = (rbc_t *)ctx; in rb_write() local
163 if (record_length > rbc->each_buf_size) { in rb_write()
171 if (rbc->bufs[rbc->wr_buf_no].full == 1) in rb_write()
174 if (rbc->wr_buf_no == rbc->rd_buf_no) { in rb_write()
175 if ((rbc->cur_wr_buf_idx == rbc->cur_rd_buf_idx) && in rb_write()
176 rbc->cur_valid_bytes) { in rb_write()
178 } else if (rbc->cur_wr_buf_idx < rbc->cur_rd_buf_idx) { in rb_write()
180 (rbc->cur_rd_buf_idx - rbc->cur_wr_buf_idx)) { in rb_write()
184 if (record_length > (rbc->each_buf_size - rbc->cur_wr_buf_idx)) { in rb_write()
188 unsigned int next_buf_no = rbc->wr_buf_no + 1; in rb_write()
190 if (next_buf_no >= rbc->max_num_bufs) { in rb_write()
193 if (rbc->bufs[next_buf_no].full == 1) { in rb_write()
198 } else if (record_length > (rbc->each_buf_size - rbc->cur_wr_buf_idx)) { in rb_write()
202 unsigned int next_buf_no = rbc->wr_buf_no + 1; in rb_write()
204 if (next_buf_no >= rbc->max_num_bufs) { in rb_write()
207 if (rbc->bufs[next_buf_no].full == 1) { in rb_write()
216 if (record_length > (rbc->each_buf_size - rbc->cur_wr_buf_idx)) { in rb_write()
217 rbc->bufs[rbc->wr_buf_no].full = 1; in rb_write()
218 rbc->bufs[rbc->wr_buf_no].last_wr_index = rbc->cur_wr_buf_idx; in rb_write()
219 rbc->wr_buf_no++; in rb_write()
220 if (rbc->wr_buf_no == rbc->max_num_bufs) { in rb_write()
221 rbc->wr_buf_no = 0; in rb_write()
223 rbc->cur_wr_buf_idx = 0; in rb_write()
233 if (rbc->bufs[rbc->wr_buf_no].data == NULL) { in rb_write()
234 rbc->bufs[rbc->wr_buf_no].data = (u8 *)malloc(rbc->each_buf_size); in rb_write()
235 if (rbc->bufs[rbc->wr_buf_no].data == NULL) { in rb_write()
245 cur_copy_len = RB_MIN((rbc->each_buf_size - rbc->cur_wr_buf_idx), in rb_write()
248 rb_lock(&rbc->rb_rw_lock); in rb_write()
251 if (rbc->rd_buf_no == rbc->wr_buf_no) { in rb_write()
252 if ((rbc->cur_rd_buf_idx > rbc->cur_wr_buf_idx) || in rb_write()
253 ((rbc->cur_rd_buf_idx == rbc->cur_wr_buf_idx) && in rb_write()
254 rbc->cur_valid_bytes)) { in rb_write()
260 if ((rbc->cur_rd_buf_idx - rbc->cur_wr_buf_idx) < in rb_write()
263 (rbc->cur_rd_buf_idx - rbc->cur_wr_buf_idx); in rb_write()
264 rbc->cur_rd_buf_idx = rbc->cur_wr_buf_idx + cur_copy_len; in rb_write()
265 if (rbc->cur_rd_buf_idx >= in rb_write()
266 rbc->bufs[rbc->rd_buf_no].last_wr_index) { in rb_write()
267 rbc->cur_rd_buf_idx = 0; in rb_write()
268 rbc->rd_buf_no++; in rb_write()
269 if (rbc->rd_buf_no == rbc->max_num_bufs) { in rb_write()
270 rbc->rd_buf_no = 0; in rb_write()
276 rbc->bufs[rbc->wr_buf_no].full = 0; in rb_write()
281 rb_unlock(&rbc->rb_rw_lock); in rb_write()
286 memcpy((rbc->bufs[rbc->wr_buf_no].data + rbc->cur_wr_buf_idx), in rb_write()
290 rb_lock(&rbc->rb_rw_lock); in rb_write()
292 rbc->cur_wr_buf_idx += cur_copy_len; in rb_write()
293 if (rbc->cur_wr_buf_idx == rbc->each_buf_size) { in rb_write()
295 rbc->bufs[rbc->wr_buf_no].full = 1; in rb_write()
296 rbc->bufs[rbc->wr_buf_no].last_wr_index = rbc->cur_wr_buf_idx; in rb_write()
297 rbc->wr_buf_no++; in rb_write()
298 if (rbc->wr_buf_no == rbc->max_num_bufs) { in rb_write()
300 rbc->wr_buf_no = 0; in rb_write()
303 rbc->cur_wr_buf_idx = 0; in rb_write()
306 if ((rbc->cur_valid_bytes + (cur_copy_len - push_in_rd_ptr)) > in rb_write()
307 (rbc->max_num_bufs * rbc->each_buf_size)) { in rb_write()
314 rbc->cur_valid_bytes += cur_copy_len - push_in_rd_ptr; in rb_write()
318 rb_unlock(&rbc->rb_rw_lock); in rb_write()
322 rb_lock(&rbc->rb_rw_lock); in rb_write()
323 rbc->total_bytes_written += bytes_written - total_push_in_rd_ptr; in rb_write()
324 rbc->total_bytes_overwritten += total_push_in_rd_ptr; in rb_write()
327 if ((rbc->threshold_reached == RB_FALSE) && in rb_write()
328 (rbc->cur_valid_bytes >= rbc->num_min_bytes) && in rb_write()
330 rbc->threshold_cb) { in rb_write()
334 rbc->threshold_reached = RB_TRUE; in rb_write()
335 rb_unlock(&rbc->rb_rw_lock); in rb_write()
336 rbc->threshold_cb(rbc->cb_ctx); in rb_write()
338 rb_unlock(&rbc->rb_rw_lock); in rb_write()
345 rbc_t *rbc = (rbc_t *)ctx; in rb_read() local
349 rb_lock(&rbc->rb_rw_lock); in rb_read()
353 if (rbc->bufs[rbc->rd_buf_no].data == NULL) { in rb_read()
358 if (rbc->rd_buf_no == rbc->wr_buf_no) { in rb_read()
359 if (rbc->cur_rd_buf_idx < rbc->cur_wr_buf_idx) { in rb_read()
364 if ((rbc->cur_wr_buf_idx - rbc->cur_rd_buf_idx) < in rb_read()
366 cur_cpy_len = rbc->cur_wr_buf_idx - rbc->cur_rd_buf_idx; in rb_read()
375 if (rbc->cur_valid_bytes <= bytes_read) { in rb_read()
380 cur_cpy_len = RB_MIN((rbc->each_buf_size - rbc->cur_rd_buf_idx), in rb_read()
388 cur_cpy_len = RB_MIN((rbc->each_buf_size - rbc->cur_rd_buf_idx), in rb_read()
393 (rbc->bufs[rbc->rd_buf_no].data + rbc->cur_rd_buf_idx), in rb_read()
397 rbc->cur_rd_buf_idx += cur_cpy_len; in rb_read()
398 if (rbc->cur_rd_buf_idx == rbc->each_buf_size) { in rb_read()
400 if (rbc->rd_buf_no != rbc->wr_buf_no) { in rb_read()
401 free(rbc->bufs[rbc->rd_buf_no].data); in rb_read()
402 rbc->bufs[rbc->rd_buf_no].data = NULL; in rb_read()
404 rbc->rd_buf_no++; in rb_read()
405 if (rbc->rd_buf_no == rbc->max_num_bufs) { in rb_read()
407 rbc->rd_buf_no = 0; in rb_read()
410 rbc->cur_rd_buf_idx = 0; in rb_read()
419 rbc->total_bytes_read += bytes_read; in rb_read()
420 if (rbc->cur_valid_bytes < bytes_read) { in rb_read()
425 rbc->cur_valid_bytes -= bytes_read; in rb_read()
429 if (rbc->threshold_reached == RB_TRUE) { in rb_read()
430 if (rbc->cur_valid_bytes < rbc->num_min_bytes) { in rb_read()
431 rbc->threshold_reached = RB_FALSE; in rb_read()
434 rb_unlock(&rbc->rb_rw_lock); in rb_read()
440 rbc_t *rbc = (rbc_t *)ctx; in rb_get_read_buf() local
445 if (!rbc || rbc->bufs[rbc->rd_buf_no].data == NULL) { in rb_get_read_buf()
450 rb_lock(&rbc->rb_rw_lock); in rb_get_read_buf()
451 if ((rbc->bufs[rbc->rd_buf_no].full == 1) && in rb_get_read_buf()
452 (rbc->cur_rd_buf_idx == rbc->bufs[rbc->rd_buf_no].last_wr_index)) { in rb_get_read_buf()
453 if (rbc->wr_buf_no != rbc->rd_buf_no) { in rb_get_read_buf()
454 free(rbc->bufs[rbc->rd_buf_no].data); in rb_get_read_buf()
455 rbc->bufs[rbc->rd_buf_no].data = NULL; in rb_get_read_buf()
457 rbc->bufs[rbc->rd_buf_no].full = 0; in rb_get_read_buf()
458 rbc->rd_buf_no++; in rb_get_read_buf()
459 if (rbc->rd_buf_no == rbc->max_num_bufs) { in rb_get_read_buf()
460 rbc->rd_buf_no = 0; in rb_get_read_buf()
462 rbc->cur_rd_buf_idx = 0; in rb_get_read_buf()
465 if (rbc->wr_buf_no == rbc->rd_buf_no) { in rb_get_read_buf()
468 if ((rbc->cur_rd_buf_idx == rbc->cur_wr_buf_idx) && in rb_get_read_buf()
469 (rbc->cur_valid_bytes == 0)) { in rb_get_read_buf()
472 rb_unlock(&rbc->rb_rw_lock); in rb_get_read_buf()
474 } else if (rbc->cur_rd_buf_idx < rbc->cur_wr_buf_idx) { in rb_get_read_buf()
476 cur_read_len = rbc->cur_wr_buf_idx - rbc->cur_rd_buf_idx; in rb_get_read_buf()
479 cur_read_len = rbc->bufs[rbc->rd_buf_no].last_wr_index - rbc->cur_rd_buf_idx; in rb_get_read_buf()
482 if (rbc->cur_rd_buf_idx == 0) { in rb_get_read_buf()
484 cur_read_len = rbc->bufs[rbc->rd_buf_no].last_wr_index; in rb_get_read_buf()
487 cur_read_len = rbc->bufs[rbc->rd_buf_no].last_wr_index - rbc->cur_rd_buf_idx; in rb_get_read_buf()
491 if ((rbc->bufs[rbc->rd_buf_no].full == 1) && in rb_get_read_buf()
492 (rbc->cur_rd_buf_idx == 0)) { in rb_get_read_buf()
494 buf = rbc->bufs[rbc->rd_buf_no].data; in rb_get_read_buf()
495 rbc->bufs[rbc->rd_buf_no].data = NULL; in rb_get_read_buf()
498 rbc->bufs[rbc->rd_buf_no].full = 0; in rb_get_read_buf()
499 rbc->rd_buf_no++; in rb_get_read_buf()
500 if (rbc->rd_buf_no == rbc->max_num_bufs) { in rb_get_read_buf()
502 rbc->rd_buf_no = 0; in rb_get_read_buf()
512 rb_unlock(&rbc->rb_rw_lock); in rb_get_read_buf()
516 (rbc->bufs[rbc->rd_buf_no].data + rbc->cur_rd_buf_idx), in rb_get_read_buf()
520 if (rbc->bufs[rbc->rd_buf_no].full == 1) { in rb_get_read_buf()
521 if (rbc->wr_buf_no != rbc->rd_buf_no) { in rb_get_read_buf()
522 free(rbc->bufs[rbc->rd_buf_no].data); in rb_get_read_buf()
523 rbc->bufs[rbc->rd_buf_no].data = NULL; in rb_get_read_buf()
525 rbc->bufs[rbc->rd_buf_no].full = 0; in rb_get_read_buf()
526 rbc->rd_buf_no++; in rb_get_read_buf()
527 if (rbc->rd_buf_no == rbc->max_num_bufs) { in rb_get_read_buf()
528 rbc->rd_buf_no = 0; in rb_get_read_buf()
530 rbc->cur_rd_buf_idx = 0; in rb_get_read_buf()
532 rbc->cur_rd_buf_idx += cur_read_len; in rb_get_read_buf()
536 rbc->total_bytes_read += cur_read_len; in rb_get_read_buf()
537 if (rbc->cur_valid_bytes < cur_read_len) { in rb_get_read_buf()
542 rbc->cur_valid_bytes -= cur_read_len; in rb_get_read_buf()
546 if (rbc->threshold_reached == RB_TRUE) { in rb_get_read_buf()
547 if (rbc->cur_valid_bytes < rbc->num_min_bytes) { in rb_get_read_buf()
548 rbc->threshold_reached = RB_FALSE; in rb_get_read_buf()
551 rb_unlock(&rbc->rb_rw_lock); in rb_get_read_buf()
562 rbc_t *rbc = (rbc_t *)ctx; in rb_config_threshold() local
564 rbc->num_min_bytes = num_min_bytes; in rb_config_threshold()
565 rbc->threshold_cb = callback; in rb_config_threshold()
566 rbc->cb_ctx = cb_ctx; in rb_config_threshold()
571 rbc_t *rbc = (rbc_t *)ctx; in rb_get_stats() local
573 rbs->total_bytes_written = rbc->total_bytes_written; in rb_get_stats()
574 rbs->total_bytes_read = rbc->total_bytes_read; in rb_get_stats()
575 rbs->cur_valid_bytes = rbc->cur_valid_bytes; in rb_get_stats()
576 rbs->each_buf_size = rbc->each_buf_size; in rb_get_stats()
577 rbs->max_num_bufs = rbc->max_num_bufs; in rb_get_stats()