RB: add a function to get the reference count.

Really handy to see if the peer is "connected".

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
This commit is contained in:
Angus Salkeld 2010-12-16 11:16:03 +11:00
parent a2b2ed7988
commit fa892f679c
2 changed files with 14 additions and 0 deletions

View File

@ -220,6 +220,14 @@ void qb_rb_chunk_reclaim(qb_ringbuffer_t * rb);
ssize_t qb_rb_chunk_read(qb_ringbuffer_t * rb, void *data_out, size_t len,
int32_t ms_timeout);
/**
* Get the reference count.
*
* @param rb ringbuffer instance
* @return the number of references
*/
int32_t qb_rb_refcount_get(qb_ringbuffer_t * rb);
/**
* The amount of free space in the ring buffer.
*

View File

@ -214,6 +214,7 @@ void qb_rb_close(qb_ringbuffer_t * rb)
"Destroying ringbuffer: %s",
rb->shared_hdr->hdr_path);
(void)qb_atomic_int_dec_and_test(&rb->shared_hdr->ref_count);
(void)rb->sem_destroy_fn(rb);
unlink(rb->shared_hdr->data_path);
unlink(rb->shared_hdr->hdr_path);
@ -232,6 +233,11 @@ void *qb_rb_shared_user_data_get(qb_ringbuffer_t * rb)
return rb->shared_hdr->user_data;
}
int32_t qb_rb_refcount_get(qb_ringbuffer_t * rb)
{
return qb_atomic_int_get(&rb->shared_hdr->ref_count);
}
ssize_t qb_rb_space_free(qb_ringbuffer_t * rb)
{
uint32_t write_size;