From 64337a484065a0a1c9b423528c87d10961ea75cf Mon Sep 17 00:00:00 2001 From: bosilca Date: Tue, 9 May 2017 10:12:20 -0400 Subject: [PATCH] Add volatile to the pointer in the list_item structure. (#3468) 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 (cherry picked from commit d7ebcca93fc86796e0d43997935539b1e922a1f1) Signed-off-by: Jeff Squyres --- 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 a4e106343a8..4c148007382 100644 --- a/opal/class/opal_lifo.h +++ b/opal/class/opal_lifo.h @@ -46,7 +46,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 @@ -134,14 +134,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 dd21763dbb8..b7e48fe91b2 100644 --- a/opal/class/opal_list.h +++ b/opal/class/opal_list.h @@ -101,9 +101,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;