Lines Matching refs:cbuf

445 	ocs_cbuf_t *cbuf;  in ocs_cbuf_alloc()  local
447 cbuf = ocs_malloc(os, sizeof(*cbuf), OCS_M_NOWAIT | OCS_M_ZERO); in ocs_cbuf_alloc()
448 if (cbuf == NULL) { in ocs_cbuf_alloc()
452 cbuf->os = os; in ocs_cbuf_alloc()
453 cbuf->entry_count = entry_count; in ocs_cbuf_alloc()
454 cbuf->pidx = 0; in ocs_cbuf_alloc()
455 cbuf->cidx = 0; in ocs_cbuf_alloc()
457 ocs_lock_init(NULL, &cbuf->cbuf_clock, "cbuf_c:%p", cbuf); in ocs_cbuf_alloc()
458 ocs_lock_init(NULL, &cbuf->cbuf_plock, "cbuf_p:%p", cbuf); in ocs_cbuf_alloc()
459 ocs_sem_init(&cbuf->cbuf_csem, 0, "cbuf:%p", cbuf); in ocs_cbuf_alloc()
460 ocs_sem_init(&cbuf->cbuf_psem, cbuf->entry_count, "cbuf:%p", cbuf); in ocs_cbuf_alloc()
462 cbuf->array = ocs_malloc(os, entry_count * sizeof(*cbuf->array), OCS_M_NOWAIT | OCS_M_ZERO); in ocs_cbuf_alloc()
463 if (cbuf->array == NULL) { in ocs_cbuf_alloc()
464 ocs_cbuf_free(cbuf); in ocs_cbuf_alloc()
468 return cbuf; in ocs_cbuf_alloc()
481 ocs_cbuf_free(ocs_cbuf_t *cbuf) in ocs_cbuf_free() argument
483 if (cbuf != NULL) { in ocs_cbuf_free()
484 if (cbuf->array != NULL) { in ocs_cbuf_free()
485 ocs_free(cbuf->os, cbuf->array, sizeof(*cbuf->array) * cbuf->entry_count); in ocs_cbuf_free()
487 ocs_lock_free(&cbuf->cbuf_clock); in ocs_cbuf_free()
488 ocs_lock_free(&cbuf->cbuf_plock); in ocs_cbuf_free()
489 ocs_free(cbuf->os, cbuf, sizeof(*cbuf)); in ocs_cbuf_free()
504 ocs_cbuf_get(ocs_cbuf_t *cbuf, int32_t timeout_usec) in ocs_cbuf_get() argument
508 if (likely(ocs_sem_p(&cbuf->cbuf_csem, timeout_usec) == 0)) { in ocs_cbuf_get()
509 ocs_lock(&cbuf->cbuf_clock); in ocs_cbuf_get()
510 ret = cbuf->array[cbuf->cidx]; in ocs_cbuf_get()
511 if (unlikely(++cbuf->cidx >= cbuf->entry_count)) { in ocs_cbuf_get()
512 cbuf->cidx = 0; in ocs_cbuf_get()
514 ocs_unlock(&cbuf->cbuf_clock); in ocs_cbuf_get()
515 ocs_sem_v(&cbuf->cbuf_psem); in ocs_cbuf_get()
531 ocs_cbuf_put(ocs_cbuf_t *cbuf, void *elem) in ocs_cbuf_put() argument
535 if (likely(ocs_sem_p(&cbuf->cbuf_psem, -1) == 0)) { in ocs_cbuf_put()
536 ocs_lock(&cbuf->cbuf_plock); in ocs_cbuf_put()
537 cbuf->array[cbuf->pidx] = elem; in ocs_cbuf_put()
538 if (unlikely(++cbuf->pidx >= cbuf->entry_count)) { in ocs_cbuf_put()
539 cbuf->pidx = 0; in ocs_cbuf_put()
541 ocs_unlock(&cbuf->cbuf_plock); in ocs_cbuf_put()
542 ocs_sem_v(&cbuf->cbuf_csem); in ocs_cbuf_put()
560 ocs_cbuf_prime(ocs_cbuf_t *cbuf, ocs_array_t *array) in ocs_cbuf_prime() argument
563 uint32_t count = MIN(ocs_array_get_count(array), cbuf->entry_count); in ocs_cbuf_prime()
566 ocs_cbuf_put(cbuf, ocs_array_get(array, i)); in ocs_cbuf_prime()
863 char *cbuf; in ocs_dump32() local
890 cbuf = (char*)wbuf; in ocs_dump32()
892 …pbuf += ocs_snprintf(pbuf, sizeof(linebuf) - (pbuf-linebuf), "%c", _isprint(cbuf[i]) ? cbuf[i] : '… in ocs_dump32()