From 9244ea10fb74ce8007388d1869a7c51ba3865b2d Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Tue, 28 Jun 2011 19:46:48 +0000 Subject: [PATCH] Provide a way to look at the head of the ring This commit was SVN r24832. --- opal/class/opal_ring_buffer.c | 7 +++++++ opal/class/opal_ring_buffer.h | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/opal/class/opal_ring_buffer.c b/opal/class/opal_ring_buffer.c index 87cf467766..77767726be 100644 --- a/opal/class/opal_ring_buffer.c +++ b/opal/class/opal_ring_buffer.c @@ -144,6 +144,13 @@ void* opal_ring_buffer_pop(opal_ring_buffer_t *ring) OPAL_ACQUIRE_THREAD(&(ring->lock), &(ring->cond), &(ring->in_use)); if (ring->size <= i || -1 == ring->tail) { p = NULL; + } else if (i < 0) { + /* return the value at the head of the ring */ + if (ring->head == 0) { + p = ring->addr[ring->size - 1]; + } else { + p = ring->addr[ring->head - 1]; + } } else { /* calculate the offset of the tail in the ring */ offset = ring->tail + i; diff --git a/opal/class/opal_ring_buffer.h b/opal/class/opal_ring_buffer.h index afbb43c225..a0e23865af 100644 --- a/opal/class/opal_ring_buffer.h +++ b/opal/class/opal_ring_buffer.h @@ -95,7 +95,8 @@ OPAL_DECLSPEC void* opal_ring_buffer_pop(opal_ring_buffer_t *ring); /* * Access an element of the ring, without removing it, indexed - * starting at the tail + * starting at the tail - a value of -1 will return the element + * at the head of the ring */ OPAL_DECLSPEC void* opal_ring_buffer_poke(opal_ring_buffer_t *ring, int i);