1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
2 /*
3 * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
4 * University Research and Technology
5 * Corporation. All rights reserved.
6 * Copyright (c) 2004-2005 The University of Tennessee and The University
7 * of Tennessee Research Foundation. All rights
8 * reserved.
9 * Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
10 * University of Stuttgart. All rights reserved.
11 * Copyright (c) 2004-2005 The Regents of the University of California.
12 * All rights reserved.
13 * Copyright (c) 2015-2017 Research Organization for Information Science
14 * and Technology (RIST). All rights reserved.
15 * Copyright (c) 2016-2017 Los Alamos National Security, LLC. All rights
16 * reserved.
17 * $COPYRIGHT$
18 *
19 * Additional copyrights may follow
20 *
21 * $HEADER$
22 */
23 #include "ompi_config.h"
24 #include <stdio.h>
25
26 #include "ompi/mpi/c/bindings.h"
27 #include "ompi/runtime/params.h"
28 #include "ompi/communicator/communicator.h"
29 #include "ompi/errhandler/errhandler.h"
30 #include "ompi/memchecker.h"
31
32 #if OMPI_BUILD_MPI_PROFILING
33 #if OPAL_HAVE_WEAK_SYMBOLS
34 #pragma weak MPI_Comm_set_errhandler = PMPI_Comm_set_errhandler
35 #endif
36 #define MPI_Comm_set_errhandler PMPI_Comm_set_errhandler
37 #endif
38
39 static const char FUNC_NAME[] = "MPI_Comm_set_errhandler";
40
41
42 int MPI_Comm_set_errhandler(MPI_Comm comm, MPI_Errhandler errhandler)
43 {
44 MPI_Errhandler tmp;
45
46 /* Error checking */
47 MEMCHECKER(
48 memchecker_comm(comm);
49 );
50
51 OPAL_CR_NOOP_PROGRESS();
52
53 /* Error checking */
54
55 if (MPI_PARAM_CHECK) {
56 OMPI_ERR_INIT_FINALIZE(FUNC_NAME);
57 if (ompi_comm_invalid(comm)) {
58 return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_COMM,
59 FUNC_NAME);
60 } else if (NULL == errhandler ||
61 MPI_ERRHANDLER_NULL == errhandler ||
62 ( OMPI_ERRHANDLER_TYPE_COMM != errhandler->eh_mpi_object_type &&
63 OMPI_ERRHANDLER_TYPE_PREDEFINED != errhandler->eh_mpi_object_type) ) {
64 return OMPI_ERRHANDLER_INVOKE(comm, MPI_ERR_ARG,
65 FUNC_NAME);
66 }
67 }
68
69 /* Prepare the new error handler */
70 OBJ_RETAIN(errhandler);
71
72 OPAL_THREAD_LOCK(&(comm->c_lock));
73 /* Ditch the old errhandler, and decrement its refcount. */
74 tmp = comm->error_handler;
75 comm->error_handler = errhandler;
76 OBJ_RELEASE(tmp);
77 OPAL_THREAD_UNLOCK(&(comm->c_lock));
78
79 /* All done */
80 return MPI_SUCCESS;
81 }