Lines Matching refs:rbc
101 struct ring_buf_cb *rbc; in ring_buffer_init() local
104 rbc = (struct ring_buf_cb *)malloc(sizeof(struct ring_buf_cb)); in ring_buffer_init()
105 if (rbc == NULL) { in ring_buffer_init()
109 memset(rbc, 0, sizeof(struct ring_buf_cb)); in ring_buffer_init()
111 rbc->bufs = (rb_entry_t *)malloc(num_bufs * sizeof(rb_entry_t)); in ring_buffer_init()
112 if (rbc->bufs == NULL) { in ring_buffer_init()
113 free(rbc); in ring_buffer_init()
117 memset(rbc->bufs, 0, (num_bufs * sizeof(rb_entry_t))); in ring_buffer_init()
119 rbc->each_buf_size = size_of_buf; in ring_buffer_init()
120 rbc->max_num_bufs = num_bufs; in ring_buffer_init()
122 status = pthread_mutex_init(&rbc->rb_rw_lock, NULL); in ring_buffer_init()
127 rbc->threshold_reached = RB_FALSE; in ring_buffer_init()
128 return rbc; in ring_buffer_init()
133 rbc_t *rbc = (rbc_t *)ctx; in ring_buffer_deinit() local
137 status = pthread_mutex_destroy(&rbc->rb_rw_lock); in ring_buffer_deinit()
142 for (buf_no = 0; buf_no < rbc->max_num_bufs; buf_no++) { in ring_buffer_deinit()
143 free(rbc->bufs[buf_no].data); in ring_buffer_deinit()
145 free(rbc->bufs); in ring_buffer_deinit()
146 free(rbc); in ring_buffer_deinit()
156 rbc_t *rbc = (rbc_t *)ctx; in rb_write() local
162 if (record_length > rbc->each_buf_size) { in rb_write()
170 if (rbc->bufs[rbc->wr_buf_no].full == 1) in rb_write()
173 if (rbc->wr_buf_no == rbc->rd_buf_no) { in rb_write()
174 if ((rbc->cur_wr_buf_idx == rbc->cur_rd_buf_idx) && in rb_write()
175 rbc->cur_valid_bytes) { in rb_write()
177 } else if (rbc->cur_wr_buf_idx < rbc->cur_rd_buf_idx) { in rb_write()
179 (rbc->cur_rd_buf_idx - rbc->cur_wr_buf_idx)) { in rb_write()
183 if (record_length > (rbc->each_buf_size - rbc->cur_wr_buf_idx)) { in rb_write()
187 unsigned int next_buf_no = rbc->wr_buf_no + 1; in rb_write()
189 if (next_buf_no >= rbc->max_num_bufs) { in rb_write()
192 if (rbc->bufs[next_buf_no].full == 1) { in rb_write()
197 } else if (record_length > (rbc->each_buf_size - rbc->cur_wr_buf_idx)) { in rb_write()
201 unsigned int next_buf_no = rbc->wr_buf_no + 1; in rb_write()
203 if (next_buf_no >= rbc->max_num_bufs) { in rb_write()
206 if (rbc->bufs[next_buf_no].full == 1) { in rb_write()
215 if (record_length > (rbc->each_buf_size - rbc->cur_wr_buf_idx)) { in rb_write()
216 rbc->bufs[rbc->wr_buf_no].full = 1; in rb_write()
217 rbc->bufs[rbc->wr_buf_no].last_wr_index = rbc->cur_wr_buf_idx; in rb_write()
218 rbc->wr_buf_no++; in rb_write()
219 if (rbc->wr_buf_no == rbc->max_num_bufs) { in rb_write()
220 rbc->wr_buf_no = 0; in rb_write()
222 rbc->cur_wr_buf_idx = 0; in rb_write()
232 if (rbc->bufs[rbc->wr_buf_no].data == NULL) { in rb_write()
233 rbc->bufs[rbc->wr_buf_no].data = (u8 *)malloc(rbc->each_buf_size); in rb_write()
234 if (rbc->bufs[rbc->wr_buf_no].data == NULL) { in rb_write()
244 cur_copy_len = RB_MIN((rbc->each_buf_size - rbc->cur_wr_buf_idx), in rb_write()
247 rb_lock(&rbc->rb_rw_lock); in rb_write()
250 if (rbc->rd_buf_no == rbc->wr_buf_no) { in rb_write()
251 if ((rbc->cur_rd_buf_idx > rbc->cur_wr_buf_idx) || in rb_write()
252 ((rbc->cur_rd_buf_idx == rbc->cur_wr_buf_idx) && in rb_write()
253 rbc->cur_valid_bytes)) { in rb_write()
259 if ((rbc->cur_rd_buf_idx - rbc->cur_wr_buf_idx) < in rb_write()
262 (rbc->cur_rd_buf_idx - rbc->cur_wr_buf_idx); in rb_write()
263 rbc->cur_rd_buf_idx = rbc->cur_wr_buf_idx + cur_copy_len; in rb_write()
264 if (rbc->cur_rd_buf_idx >= in rb_write()
265 rbc->bufs[rbc->rd_buf_no].last_wr_index) { in rb_write()
266 rbc->cur_rd_buf_idx = 0; in rb_write()
267 rbc->rd_buf_no++; in rb_write()
268 if (rbc->rd_buf_no == rbc->max_num_bufs) { in rb_write()
269 rbc->rd_buf_no = 0; in rb_write()
275 rbc->bufs[rbc->wr_buf_no].full = 0; in rb_write()
280 rb_unlock(&rbc->rb_rw_lock); in rb_write()
285 memcpy((rbc->bufs[rbc->wr_buf_no].data + rbc->cur_wr_buf_idx), in rb_write()
289 rb_lock(&rbc->rb_rw_lock); in rb_write()
291 rbc->cur_wr_buf_idx += cur_copy_len; in rb_write()
292 if (rbc->cur_wr_buf_idx == rbc->each_buf_size) { in rb_write()
294 rbc->bufs[rbc->wr_buf_no].full = 1; in rb_write()
295 rbc->bufs[rbc->wr_buf_no].last_wr_index = rbc->cur_wr_buf_idx; in rb_write()
296 rbc->wr_buf_no++; in rb_write()
297 if (rbc->wr_buf_no == rbc->max_num_bufs) { in rb_write()
299 rbc->wr_buf_no = 0; in rb_write()
302 rbc->cur_wr_buf_idx = 0; in rb_write()
305 if ((rbc->cur_valid_bytes + (cur_copy_len - push_in_rd_ptr)) > in rb_write()
306 (rbc->max_num_bufs * rbc->each_buf_size)) { in rb_write()
313 rbc->cur_valid_bytes += cur_copy_len - push_in_rd_ptr; in rb_write()
317 rb_unlock(&rbc->rb_rw_lock); in rb_write()
321 rb_lock(&rbc->rb_rw_lock); in rb_write()
322 rbc->total_bytes_written += bytes_written - total_push_in_rd_ptr; in rb_write()
323 rbc->total_bytes_overwritten += total_push_in_rd_ptr; in rb_write()
326 if ((rbc->threshold_reached == RB_FALSE) && in rb_write()
327 (rbc->cur_valid_bytes >= rbc->num_min_bytes) && in rb_write()
329 rbc->threshold_cb) { in rb_write()
333 rbc->threshold_reached = RB_TRUE; in rb_write()
334 rb_unlock(&rbc->rb_rw_lock); in rb_write()
335 rbc->threshold_cb(rbc->cb_ctx); in rb_write()
337 rb_unlock(&rbc->rb_rw_lock); in rb_write()
344 rbc_t *rbc = (rbc_t *)ctx; in rb_read() local
348 rb_lock(&rbc->rb_rw_lock); in rb_read()
352 if (rbc->bufs[rbc->rd_buf_no].data == NULL) { in rb_read()
357 if (rbc->rd_buf_no == rbc->wr_buf_no) { in rb_read()
358 if (rbc->cur_rd_buf_idx < rbc->cur_wr_buf_idx) { in rb_read()
363 if ((rbc->cur_wr_buf_idx - rbc->cur_rd_buf_idx) < in rb_read()
365 cur_cpy_len = rbc->cur_wr_buf_idx - rbc->cur_rd_buf_idx; in rb_read()
374 if (rbc->cur_valid_bytes <= bytes_read) { in rb_read()
379 cur_cpy_len = RB_MIN((rbc->each_buf_size - rbc->cur_rd_buf_idx), in rb_read()
387 cur_cpy_len = RB_MIN((rbc->each_buf_size - rbc->cur_rd_buf_idx), in rb_read()
392 (rbc->bufs[rbc->rd_buf_no].data + rbc->cur_rd_buf_idx), in rb_read()
396 rbc->cur_rd_buf_idx += cur_cpy_len; in rb_read()
397 if (rbc->cur_rd_buf_idx == rbc->each_buf_size) { in rb_read()
399 if (rbc->rd_buf_no != rbc->wr_buf_no) { in rb_read()
400 free(rbc->bufs[rbc->rd_buf_no].data); in rb_read()
401 rbc->bufs[rbc->rd_buf_no].data = NULL; in rb_read()
403 rbc->rd_buf_no++; in rb_read()
404 if (rbc->rd_buf_no == rbc->max_num_bufs) { in rb_read()
406 rbc->rd_buf_no = 0; in rb_read()
409 rbc->cur_rd_buf_idx = 0; in rb_read()
418 rbc->total_bytes_read += bytes_read; in rb_read()
419 if (rbc->cur_valid_bytes < bytes_read) { in rb_read()
424 rbc->cur_valid_bytes -= bytes_read; in rb_read()
428 if (rbc->threshold_reached == RB_TRUE) { in rb_read()
429 if (rbc->cur_valid_bytes < rbc->num_min_bytes) { in rb_read()
430 rbc->threshold_reached = RB_FALSE; in rb_read()
433 rb_unlock(&rbc->rb_rw_lock); in rb_read()
439 rbc_t *rbc = (rbc_t *)ctx; in rb_get_read_buf() local
444 if (rbc->bufs[rbc->rd_buf_no].data == NULL) { in rb_get_read_buf()
449 rb_lock(&rbc->rb_rw_lock); in rb_get_read_buf()
450 if ((rbc->bufs[rbc->rd_buf_no].full == 1) && in rb_get_read_buf()
451 (rbc->cur_rd_buf_idx == rbc->bufs[rbc->rd_buf_no].last_wr_index)) { in rb_get_read_buf()
452 if (rbc->wr_buf_no != rbc->rd_buf_no) { in rb_get_read_buf()
453 free(rbc->bufs[rbc->rd_buf_no].data); in rb_get_read_buf()
454 rbc->bufs[rbc->rd_buf_no].data = NULL; in rb_get_read_buf()
456 rbc->bufs[rbc->rd_buf_no].full = 0; in rb_get_read_buf()
457 rbc->rd_buf_no++; in rb_get_read_buf()
458 if (rbc->rd_buf_no == rbc->max_num_bufs) { in rb_get_read_buf()
459 rbc->rd_buf_no = 0; in rb_get_read_buf()
461 rbc->cur_rd_buf_idx = 0; in rb_get_read_buf()
464 if (rbc->wr_buf_no == rbc->rd_buf_no) { in rb_get_read_buf()
467 if ((rbc->cur_rd_buf_idx == rbc->cur_wr_buf_idx) && in rb_get_read_buf()
468 (rbc->cur_valid_bytes == 0)) { in rb_get_read_buf()
471 rb_unlock(&rbc->rb_rw_lock); in rb_get_read_buf()
473 } else if (rbc->cur_rd_buf_idx < rbc->cur_wr_buf_idx) { in rb_get_read_buf()
475 cur_read_len = rbc->cur_wr_buf_idx - rbc->cur_rd_buf_idx; in rb_get_read_buf()
478 cur_read_len = rbc->bufs[rbc->rd_buf_no].last_wr_index - rbc->cur_rd_buf_idx; in rb_get_read_buf()
481 if (rbc->cur_rd_buf_idx == 0) { in rb_get_read_buf()
483 cur_read_len = rbc->bufs[rbc->rd_buf_no].last_wr_index; in rb_get_read_buf()
486 cur_read_len = rbc->bufs[rbc->rd_buf_no].last_wr_index - rbc->cur_rd_buf_idx; in rb_get_read_buf()
490 if ((rbc->bufs[rbc->rd_buf_no].full == 1) && in rb_get_read_buf()
491 (rbc->cur_rd_buf_idx == 0)) { in rb_get_read_buf()
493 buf = rbc->bufs[rbc->rd_buf_no].data; in rb_get_read_buf()
494 rbc->bufs[rbc->rd_buf_no].data = NULL; in rb_get_read_buf()
497 rbc->bufs[rbc->rd_buf_no].full = 0; in rb_get_read_buf()
498 rbc->rd_buf_no++; in rb_get_read_buf()
499 if (rbc->rd_buf_no == rbc->max_num_bufs) { in rb_get_read_buf()
501 rbc->rd_buf_no = 0; in rb_get_read_buf()
511 rb_unlock(&rbc->rb_rw_lock); in rb_get_read_buf()
515 (rbc->bufs[rbc->rd_buf_no].data + rbc->cur_rd_buf_idx), in rb_get_read_buf()
519 if (rbc->bufs[rbc->rd_buf_no].full == 1) { in rb_get_read_buf()
520 if (rbc->wr_buf_no != rbc->rd_buf_no) { in rb_get_read_buf()
521 free(rbc->bufs[rbc->rd_buf_no].data); in rb_get_read_buf()
522 rbc->bufs[rbc->rd_buf_no].data = NULL; in rb_get_read_buf()
524 rbc->bufs[rbc->rd_buf_no].full = 0; in rb_get_read_buf()
525 rbc->rd_buf_no++; in rb_get_read_buf()
526 if (rbc->rd_buf_no == rbc->max_num_bufs) { in rb_get_read_buf()
527 rbc->rd_buf_no = 0; in rb_get_read_buf()
529 rbc->cur_rd_buf_idx = 0; in rb_get_read_buf()
531 rbc->cur_rd_buf_idx += cur_read_len; in rb_get_read_buf()
535 rbc->total_bytes_read += cur_read_len; in rb_get_read_buf()
536 if (rbc->cur_valid_bytes < cur_read_len) { in rb_get_read_buf()
541 rbc->cur_valid_bytes -= cur_read_len; in rb_get_read_buf()
545 if (rbc->threshold_reached == RB_TRUE) { in rb_get_read_buf()
546 if (rbc->cur_valid_bytes < rbc->num_min_bytes) { in rb_get_read_buf()
547 rbc->threshold_reached = RB_FALSE; in rb_get_read_buf()
550 rb_unlock(&rbc->rb_rw_lock); in rb_get_read_buf()
561 rbc_t *rbc = (rbc_t *)ctx; in rb_config_threshold() local
563 rbc->num_min_bytes = num_min_bytes; in rb_config_threshold()
564 rbc->threshold_cb = callback; in rb_config_threshold()
565 rbc->cb_ctx = cb_ctx; in rb_config_threshold()
570 rbc_t *rbc = (rbc_t *)ctx; in rb_get_stats() local
572 rbs->total_bytes_written = rbc->total_bytes_written; in rb_get_stats()
573 rbs->total_bytes_read = rbc->total_bytes_read; in rb_get_stats()
574 rbs->cur_valid_bytes = rbc->cur_valid_bytes; in rb_get_stats()
575 rbs->each_buf_size = rbc->each_buf_size; in rb_get_stats()
576 rbs->max_num_bufs = rbc->max_num_bufs; in rb_get_stats()