1
1

From an initial patch from George, update all the set/get errhandler

functions to use atomics in order to be thread safe.

This commit was SVN r18807.
Этот коммит содержится в:
Jeff Squyres 2008-07-03 19:28:02 +00:00
родитель 1b3b8732ca
Коммит 74aa9689e4
6 изменённых файлов: 77 добавлений и 22 удалений

Просмотреть файл

@ -9,7 +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 Cisco, Inc. All rights reserved.
* Copyright (c) 2007-2008 Cisco, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -36,6 +36,8 @@ static const char FUNC_NAME[] = "MPI_Comm_get_errhandler";
int MPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler *errhandler)
{
MPI_Errhandler tmp;
/* Error checking */
MEMCHECKER(
memchecker_comm(comm);
@ -56,10 +58,16 @@ int MPI_Comm_get_errhandler(MPI_Comm comm, MPI_Errhandler *errhandler)
}
}
/* Retain the errhandler, corresponding to object refcount
decrease in errhandler_free.c. */
OBJ_RETAIN(comm->error_handler);
*errhandler = comm->error_handler;
/* On 64 bits environments we have to make sure the reading of the
error_handler became atomic. */
do {
tmp = comm->error_handler;
} while (!OPAL_ATOMIC_CMPSET(&(comm->error_handler), tmp, tmp));
/* Retain the errhandler, corresponding to object refcount decrease
in errhandler_free.c. */
*errhandler = tmp;
OBJ_RETAIN(tmp);
/* All done */

Просмотреть файл

@ -34,6 +34,8 @@ static const char FUNC_NAME[] = "MPI_Comm_set_errhandler";
int MPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler)
{
MPI_Errhandler tmp;
/* Error checking */
MEMCHECKER(
memchecker_comm(comm);
@ -57,14 +59,22 @@ int MPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler)
}
}
/* Ditch the old errhandler, and decrement its refcount */
/* Ditch the old errhandler, and decrement its refcount. On 64
bits environments we have to make sure the reading of the
error_handler became atomic. */
do {
tmp = comm->error_handler;
} while (!OPAL_ATOMIC_CMPSET(&(comm->error_handler), tmp, tmp));
OBJ_RELEASE(tmp);
OBJ_RELEASE(comm->error_handler);
/* We have a valid comm and errhandler, so increment its refcount */
/* Now set the new errhandler and increase its refcount */
do {
comm->error_handler = errhandler;
} while (!OPAL_ATOMIC_CMPSET(&(errhandler), comm->error_handler,
comm->error_handler));
comm->error_handler = errhandler;
OBJ_RETAIN(comm->error_handler);
OBJ_RETAIN(errhandler);
/* All done */

Просмотреть файл

@ -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) 2008 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -34,6 +35,7 @@ static const char FUNC_NAME[] = "MPI_File_get_errhandler";
int MPI_File_get_errhandler( MPI_File file, MPI_Errhandler *errhandler)
{
MPI_Errhandler tmp;
OPAL_CR_NOOP_PROGRESS();
@ -55,10 +57,16 @@ int MPI_File_get_errhandler( MPI_File file, MPI_Errhandler *errhandler)
}
}
/* On 64 bits environments we have to make sure the reading of the
error_handler became atomic. */
do {
tmp = file->error_handler;
} while (!OPAL_ATOMIC_CMPSET(&(file->error_handler), tmp, tmp));
/* Retain the errhandler, corresponding to object refcount
decrease in errhandler_free.c. */
OBJ_RETAIN(file->error_handler);
*errhandler = file->error_handler;
*errhandler = tmp;
OBJ_RETAIN(tmp);
/* All done */

Просмотреть файл

@ -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) 2008 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -34,6 +35,7 @@ static const char FUNC_NAME[] = "MPI_File_set_errhandler";
int MPI_File_set_errhandler( MPI_File file, MPI_Errhandler errhandler)
{
MPI_Errhandler tmp;
OPAL_CR_NOOP_PROGRESS();
@ -57,14 +59,21 @@ int MPI_File_set_errhandler( MPI_File file, MPI_Errhandler errhandler)
}
}
/* Ditch the old errhandler, and decrement its refcount */
OBJ_RELEASE(file->error_handler);
/* We have a valid comm and errhandler, so increment its refcount */
/* Ditch the old errhandler, and decrement its refcount. On 64
bits environments we have to make sure the reading of the
error_handler became atomic. */
do {
tmp = file->error_handler;
} while (!OPAL_ATOMIC_CMPSET(&(file->error_handler), tmp, tmp));
OBJ_RELEASE(tmp);
/* Now set the new errhandler and increase its refcount */
do {
file->error_handler = errhandler;
} while (!OPAL_ATOMIC_CMPSET(&(errhandler), file->error_handler,
file->error_handler));
file->error_handler = errhandler;
OBJ_RETAIN(file->error_handler);
OBJ_RETAIN(errhandler);
/* All done */

Просмотреть файл

@ -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) 2008 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -34,6 +35,8 @@ static const char FUNC_NAME[] = "MPI_Win_get_errhandler";
int MPI_Win_get_errhandler(MPI_Win win, MPI_Errhandler *errhandler)
{
MPI_Errhandler tmp;
OPAL_CR_NOOP_PROGRESS();
if (MPI_PARAM_CHECK) {
@ -47,6 +50,12 @@ int MPI_Win_get_errhandler(MPI_Win win, MPI_Errhandler *errhandler)
}
}
/* On 64 bits environments we have to make sure the reading of the
error_handler became atomic. */
do {
tmp = win->error_handler;
} while (!OPAL_ATOMIC_CMPSET(&(win->error_handler), tmp, tmp));
/* Retain the errhandler, corresponding to object refcount
decrease in errhandler_free.c. */
OBJ_RETAIN(win->error_handler);

Просмотреть файл

@ -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) 2008 Cisco Systems, Inc. All rights reserved.
* $COPYRIGHT$
*
* Additional copyrights may follow
@ -34,6 +35,7 @@ static const char FUNC_NAME[] = "MPI_Win_set_errhandler";
int MPI_Win_set_errhandler(MPI_Win win, MPI_Errhandler errhandler)
{
MPI_Errhandler tmp;
OPAL_CR_NOOP_PROGRESS();
@ -50,12 +52,21 @@ int MPI_Win_set_errhandler(MPI_Win win, MPI_Errhandler errhandler)
}
}
/* Ditch the old errhandler, and decrement its refcount */
OBJ_RELEASE(win->error_handler);
/* Ditch the old errhandler, and decrement its refcount. On 64
bits environments we have to make sure the reading of the
error_handler became atomic. */
do {
tmp = win->error_handler;
} while (!OPAL_ATOMIC_CMPSET(&(win->error_handler), tmp, tmp));
OBJ_RELEASE(tmp);
/* We have a valid comm and errhandler, so increment its refcount */
/* Now set the new errhandler and increase its refcount */
do {
win->error_handler = errhandler;
} while (!OPAL_ATOMIC_CMPSET(&(errhandler), win->error_handler,
win->error_handler));
win->error_handler = errhandler;
OBJ_RETAIN(win->error_handler);
OBJ_RETAIN(errhandler);
/* All done */
return MPI_SUCCESS;