From 401678a4acfcadfdabbe064617b1a4e2a6ea1488 Mon Sep 17 00:00:00 2001 From: George Bosilca Date: Sun, 7 May 2017 22:59:12 -0400 Subject: [PATCH] Add volatile to the pointer in the list_item structure. This change has the side effect of improving the performance of all atomic data structures (in addition to making the code crrect under a certain interpretation of the volatile usage). This commit fixes #3450. Signed-off-by: George Bosilca --- opal/class/opal_lifo.h | 6 +++--- opal/class/opal_list.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/opal/class/opal_lifo.h b/opal/class/opal_lifo.h index 0bf2cd20960..af3dedd9272 100644 --- a/opal/class/opal_lifo.h +++ b/opal/class/opal_lifo.h @@ -48,7 +48,7 @@ union opal_counted_pointer_t { /** update counter used when cmpset_128 is available */ uint64_t counter; /** list item pointer */ - opal_list_item_t *item; + volatile opal_list_item_t * volatile item; } data; #if OPAL_HAVE_ATOMIC_CMPSET_128 && HAVE_OPAL_INT128_T /** used for atomics when there is a cmpset that can operate on @@ -138,14 +138,14 @@ static inline opal_list_item_t *opal_lifo_push_atomic (opal_lifo_t *lifo, */ static inline opal_list_item_t *opal_lifo_pop_atomic (opal_lifo_t* lifo) { + opal_counted_pointer_t old_head; opal_list_item_t *item; do { - opal_counted_pointer_t old_head; old_head.data.counter = lifo->opal_lifo_head.data.counter; opal_atomic_rmb (); - item = old_head.data.item = lifo->opal_lifo_head.data.item; + old_head.data.item = item = (opal_list_item_t*)lifo->opal_lifo_head.data.item; if (item == &lifo->opal_lifo_ghost) { return NULL; diff --git a/opal/class/opal_list.h b/opal/class/opal_list.h index 1e91604ca9f..cafc96dfb78 100644 --- a/opal/class/opal_list.h +++ b/opal/class/opal_list.h @@ -103,9 +103,9 @@ struct opal_list_item_t { opal_object_t super; /**< Generic parent class for all Open MPI objects */ - volatile struct opal_list_item_t *opal_list_next; + volatile struct opal_list_item_t * volatile opal_list_next; /**< Pointer to next list item */ - volatile struct opal_list_item_t *opal_list_prev; + volatile struct opal_list_item_t * volatile opal_list_prev; /**< Pointer to previous list item */ int32_t item_free;