Really handy to see if the peer is "connected".
Signed-off-by: Angus Salkeld asalkeld@redhat.com --- include/qb/qbrb.h | 8 ++++++++ lib/ringbuffer.c | 6 ++++++ 2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/include/qb/qbrb.h b/include/qb/qbrb.h index b57f2b3..b50359c 100644 --- a/include/qb/qbrb.h +++ b/include/qb/qbrb.h @@ -221,6 +221,14 @@ 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. * * @note Some of this space will be consumed by the chunk headers. diff --git a/lib/ringbuffer.c b/lib/ringbuffer.c index ad3c50d..7524c73 100644 --- a/lib/ringbuffer.c +++ b/lib/ringbuffer.c @@ -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;