From: Arlin Davis Date: Tue, 15 Jul 2014 20:41:10 +0000 (-0700) Subject: common: init rbuf memory, assign hd/tl pos in range X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=95935ce4a2017836fe6a29946a145929d242531c;p=~ardavis%2Fdapl.git common: init rbuf memory, assign hd/tl pos in range Signed-off-by: Arlin Davis --- diff --git a/dapl/common/dapl_ring_buffer_util.c b/dapl/common/dapl_ring_buffer_util.c index 53e6426..f2fdd56 100644 --- a/dapl/common/dapl_ring_buffer_util.c +++ b/dapl/common/dapl_ring_buffer_util.c @@ -73,6 +73,7 @@ DAT_RETURN dapls_rbuf_alloc(INOUT DAPL_RING_BUFFER * rbuf, IN DAT_COUNT size) } rbuf->base = (void *)dapl_os_alloc(rsize * sizeof(void *)); + dapl_os_memzero (rbuf->base, rsize * sizeof(void *)); if (rbuf->base != NULL) { rbuf->lim = rsize - 1; dapl_os_atomic_set(&rbuf->head, 0); @@ -193,19 +194,18 @@ DAT_RETURN dapls_rbuf_add(IN DAPL_RING_BUFFER * rbuf, IN void *entry) int pos; int val; - while (((dapl_os_atomic_read(&rbuf->head) + 1) & rbuf->lim) != - (dapl_os_atomic_read(&rbuf->tail) & rbuf->lim)) { + while ((dapl_os_atomic_read(&rbuf->head) + 1) != + dapl_os_atomic_read(&rbuf->tail)) { pos = dapl_os_atomic_read(&rbuf->head); - val = dapl_os_atomic_assign(&rbuf->head, pos, pos + 1); + val = dapl_os_atomic_assign(&rbuf->head, pos, ((pos + 1) & rbuf->lim)); if (val == pos) { pos = (pos + 1) & rbuf->lim; /* verify in range */ - rbuf->base[pos] = entry; /* FIXME: there a race condition between this line and the line in dapls_rbuf_remove */ + rbuf->base[pos] = entry; return DAT_SUCCESS; } } return DAT_ERROR(DAT_INSUFFICIENT_RESOURCES, DAT_RESOURCE_MEMORY); - } /* @@ -222,7 +222,6 @@ DAT_RETURN dapls_rbuf_add(IN DAPL_RING_BUFFER * rbuf, IN void *entry) * Returns: * DAT_SUCCESS * DAT_QUEUE_EMPTY - */ void *dapls_rbuf_remove(IN DAPL_RING_BUFFER * rbuf) { @@ -232,16 +231,14 @@ void *dapls_rbuf_remove(IN DAPL_RING_BUFFER * rbuf) while (dapl_os_atomic_read(&rbuf->head) != dapl_os_atomic_read(&rbuf->tail)) { pos = dapl_os_atomic_read(&rbuf->tail); - val = dapl_os_atomic_assign(&rbuf->tail, pos, pos + 1); + val = dapl_os_atomic_assign(&rbuf->tail, pos, ((pos + 1) & rbuf->lim)); if (val == pos) { pos = (pos + 1) & rbuf->lim; /* verify in range */ - - return (rbuf->base[pos]); /* FIXME: there a race condition between this line and the line in dapls_rbuf_add */ + return (rbuf->base[pos]); } } return NULL; - } /* diff --git a/dapl/include/dapl.h b/dapl/include/dapl.h index 09b7a98..210f1b3 100755 --- a/dapl/include/dapl.h +++ b/dapl/include/dapl.h @@ -365,7 +365,6 @@ struct dapl_evd DAT_EVENT *events; DAPL_RING_BUFFER free_event_queue; DAPL_RING_BUFFER pending_event_queue; - DAPL_OS_LOCK pending_event_queue_lock; /* temporary workaround for the ring buffer race condition */ /* CQ Completions are not placed into 'deferred_events' ** rather they are simply left on the Completion Queue