diff --git a/src/communicator/comm.c b/src/communicator/comm.c index 55d60eb70c..793c94084f 100644 --- a/src/communicator/comm.c +++ b/src/communicator/comm.c @@ -515,12 +515,16 @@ int ompi_comm_split ( ompi_communicator_t* comm, int color, int key, int ompi_comm_set_name (ompi_communicator_t *comm, char *name ) { +#ifdef USE_MUTEX_FOR_COMMS OMPI_THREAD_LOCK(&(comm->c_lock)); +#endif memset(comm->c_name, 0, MPI_MAX_OBJECT_NAME); strncpy(comm->c_name, name, MPI_MAX_OBJECT_NAME); comm->c_name[MPI_MAX_OBJECT_NAME - 1] = 0; comm->c_flags |= OMPI_COMM_NAMEISSET; +#ifdef USE_MUTEX_FOR_COMMS OMPI_THREAD_UNLOCK(&(comm->c_lock)); +#endif return OMPI_SUCCESS; } diff --git a/src/communicator/communicator.h b/src/communicator/communicator.h index 8f110a521a..0783fdc9bd 100644 --- a/src/communicator/communicator.h +++ b/src/communicator/communicator.h @@ -50,7 +50,9 @@ extern ompi_pointer_array_t ompi_mpi_communicators; struct ompi_communicator_t { ompi_object_t c_base; +#ifdef USE_MUTEX_FOR_COMMS ompi_mutex_t c_lock; /* mutex for name and attributes */ +#endif char c_name[MPI_MAX_OBJECT_NAME]; uint32_t c_contextid; int c_my_rank; diff --git a/src/mpi/c/comm_get_name.c b/src/mpi/c/comm_get_name.c index 7af65a5e64..6cb9e9e612 100644 --- a/src/mpi/c/comm_get_name.c +++ b/src/mpi/c/comm_get_name.c @@ -39,8 +39,9 @@ int MPI_Comm_get_name(MPI_Comm comm, char *name, int *length) return OMPI_ERRHANDLER_INVOKE ( comm, MPI_ERR_ARG, FUNC_NAME); } - +#ifdef USE_MUTEX_FOR_COMMS OMPI_THREAD_LOCK(&(comm->c_lock)); +#endif if ( comm->c_flags & OMPI_COMM_NAMEISSET ) { strncpy ( name, comm->c_name, MPI_MAX_OBJECT_NAME ); *length = strlen ( comm->c_name ); @@ -49,7 +50,9 @@ int MPI_Comm_get_name(MPI_Comm comm, char *name, int *length) memset ( name, 0, MPI_MAX_OBJECT_NAME ); *length = 0; } +#ifdef USE_MUTEX_FOR_COMMS OMPI_THREAD_UNLOCK(&(comm->c_lock)); +#endif return MPI_SUCCESS; }