From 140dce7614371cb8885ca03308c1803cd04632e6 Mon Sep 17 00:00:00 2001 From: Gleb Natapov Date: Tue, 11 Sep 2007 15:40:30 +0000 Subject: [PATCH] Fix ABA problem in atomic_lifo code. This is temporary solution for now. We are looking for a better one. This commit was SVN r16091. --- opal/class/opal_atomic_lifo.h | 14 ++++++++++---- opal/class/opal_list.c | 2 ++ opal/class/opal_list.h | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/opal/class/opal_atomic_lifo.h b/opal/class/opal_atomic_lifo.h index caf35b10a0..25aa26fbc3 100644 --- a/opal/class/opal_atomic_lifo.h +++ b/opal/class/opal_atomic_lifo.h @@ -9,6 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2007 Voltaire All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -71,8 +72,10 @@ static inline opal_list_item_t* opal_atomic_lifo_push( opal_atomic_lifo_t* lifo, item->opal_list_next = lifo->opal_lifo_head; if( opal_atomic_cmpset_ptr( &(lifo->opal_lifo_head), (void*)item->opal_list_next, - item ) ) + item ) ) { + opal_atomic_cmpset_32((volatile int32_t*)&item->item_free, 1, 0); return (opal_list_item_t*)item->opal_list_next; + } /* DO some kind of pause to release the bus */ } while( 1 ); #else @@ -89,14 +92,17 @@ static inline opal_list_item_t* opal_atomic_lifo_pop( opal_atomic_lifo_t* lifo ) { opal_list_item_t* item; #if OMPI_HAVE_THREAD_SUPPORT - do { - item = lifo->opal_lifo_head; + while((item = lifo->opal_lifo_head) != &(lifo->opal_lifo_ghost)) + { + if(!opal_atomic_cmpset_32((volatile int32_t*)&item->item_free, 0, 1)) + continue; if( opal_atomic_cmpset_ptr( &(lifo->opal_lifo_head), item, (void*)item->opal_list_next ) ) break; + opal_atomic_cmpset_32((volatile int32_t*)&item->item_free, 1, 0); /* Do some kind of pause to release the bus */ - } while( 1 ); + } #else item = lifo->opal_lifo_head; lifo->opal_lifo_head = (opal_list_item_t*)item->opal_list_next; diff --git a/opal/class/opal_list.c b/opal/class/opal_list.c index c8a5568165..7231c5338c 100644 --- a/opal/class/opal_list.c +++ b/opal/class/opal_list.c @@ -9,6 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2007 Voltaire All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -55,6 +56,7 @@ OBJ_CLASS_INSTANCE( static void opal_list_item_construct(opal_list_item_t *item) { item->opal_list_next = item->opal_list_prev = NULL; + item->item_free = 1; #if OMPI_ENABLE_DEBUG item->opal_list_item_refcount = 0; item->opal_list_item_belong_to = NULL; diff --git a/opal/class/opal_list.h b/opal/class/opal_list.h index 83fa57ba68..ea9b327198 100644 --- a/opal/class/opal_list.h +++ b/opal/class/opal_list.h @@ -9,6 +9,7 @@ * University of Stuttgart. All rights reserved. * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. + * Copyright (c) 2007 Voltaire All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow @@ -102,6 +103,7 @@ struct opal_list_item_t /**< Pointer to next list item */ volatile struct opal_list_item_t *opal_list_prev; /**< Pointer to previous list item */ + int32_t item_free; #if OMPI_ENABLE_DEBUG /** Atomic reference count for debugging */