From 4f85e0d833203924599d33f8b45c4f2b2b70b256 Mon Sep 17 00:00:00 2001 From: Edgar Gabriel Date: Fri, 24 Jul 2015 10:23:43 -0500 Subject: [PATCH] add the configure logic to check for sem_open and sem_init. Change the code to rely on HAVE_SEM_OPEN etc. instead of my internal macro. --- ompi/mca/sharedfp/sm/configure.m4 | 38 +++++++++++++++++++ ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c | 22 +++++------ .../sm/sharedfp_sm_request_position.c | 12 +++--- ompi/mca/sharedfp/sm/sharedfp_sm_seek.c | 12 +++--- 4 files changed, 61 insertions(+), 23 deletions(-) create mode 100644 ompi/mca/sharedfp/sm/configure.m4 diff --git a/ompi/mca/sharedfp/sm/configure.m4 b/ompi/mca/sharedfp/sm/configure.m4 new file mode 100644 index 0000000000..2ec2cd5499 --- /dev/null +++ b/ompi/mca/sharedfp/sm/configure.m4 @@ -0,0 +1,38 @@ +# -*- shell-script -*- +# +# Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana +# University Research and Technology +# Corporation. All rights reserved. +# Copyright (c) 2004-2005 The University of Tennessee and The University +# of Tennessee Research Foundation. All rights +# reserved. +# Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, +# University of Stuttgart. All rights reserved. +# Copyright (c) 2004-2012 The Regents of the University of California. +# All rights reserved. +# Copyright (c) 2010-2014 Cisco Systems, Inc. All rights reserved. +# Copyright (c) 2008-2015 University of Houston. All rights reserved. +# $COPYRIGHT$ +# +# Additional copyrights may follow +# +# $HEADER$ +# + +# MCA_sharedfp_sm_CONFIG(action-if-can-compile, +# [action-if-cant-compile]) +# ------------------------------------------------ +AC_DEFUN([MCA_ompi_sharedfp_sm_CONFIG],[ + AC_CONFIG_FILES([ompi/mca/sharedfp/sm/Makefile]) + + sharedfp_sm_happy=no + AC_CHECK_HEADER([semaphore.h], + [AC_CHECK_FUNCS([sem_open],[sharedfp_sm_happy=yes],[])]) + + AC_CHECK_HEADER([semaphore.h], + [AC_CHECK_FUNCS([sem_init],[sharedfp_sm_happy=yes],[])]) + + AS_IF([test "$sharedfp_sm_happy" = "yes"], + [$1], + [$2]) +])dnl diff --git a/ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c b/ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c index bf8eca5015..71856c418e 100644 --- a/ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c +++ b/ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c @@ -164,13 +164,13 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm, /* Initialize semaphore so that is shared between processes. */ /* the semaphore is shared by keeping it in the shared memory segment */ -#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES - if(sem_init(&sm_offset_ptr->mutex, 1, 1) != -1){ -#else +#if defined(HAVE_SEM_OPEN) sm_data->sem_name = (char*) malloc( sizeof(char) * (strlen(filename_basename)+32) ); sprintf(sm_data->sem_name,"OMPIO_sharedfp_sem_%s",filename_basename); if( (sm_data->mutex = sem_open(sm_data->sem_name, O_CREAT, 0644, 1)) != SEM_FAILED ) { +#elif defined(HAVE_SEM_INIT) + if(sem_init(&sm_offset_ptr->mutex, 1, 1) != -1){ #endif /*If opening was successful*/ /*Store the new file handle*/ @@ -184,14 +184,14 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm, if(rank==0){ MPI_Offset position=0; -#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES - sem_wait(&sm_offset_ptr->mutex); - sm_offset_ptr->offset=position; - sem_post(&sm_offset_ptr->mutex); -#else +#if defined(HAVE_SEM_OPEN) sem_wait(sm_data->mutex); sm_offset_ptr->offset=position; sem_post(sm_data->mutex); +#elif defined(HAVE_SEM_INIT) + sem_wait(&sm_offset_ptr->mutex); + sm_offset_ptr->offset=position; + sem_post(&sm_offset_ptr->mutex); #endif } }else{ @@ -235,11 +235,11 @@ int mca_sharedfp_sm_file_close (mca_io_ompio_file_t *fh) /*Close sm handle*/ if (file_data->sm_offset_ptr) { /* destroy semaphore */ -#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES - sem_destroy(&file_data->sm_offset_ptr->mutex); -#else +#if defined(HAVE_SEM_OPEN) sem_unlink (file_data->sem_name); free (file_data->sem_name); +#elif defined(HAVE_SEM_INIT) + sem_destroy(&file_data->sm_offset_ptr->mutex); #endif /*Release the shared memory segment.*/ munmap(file_data->sm_offset_ptr,sizeof(struct mca_sharedfp_sm_offset)); diff --git a/ompi/mca/sharedfp/sm/sharedfp_sm_request_position.c b/ompi/mca/sharedfp/sm/sharedfp_sm_request_position.c index 7cfa26b9c2..6e02fb7df6 100644 --- a/ompi/mca/sharedfp/sm/sharedfp_sm_request_position.c +++ b/ompi/mca/sharedfp/sm/sharedfp_sm_request_position.c @@ -48,10 +48,10 @@ int mca_sharedfp_sm_request_position(struct mca_sharedfp_base_data_t * sh, /* Aquire an exclusive lock */ -#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES - sem_wait(&sm_offset_ptr->mutex); -#else +#if defined(HAVE_SEM_OPEN) sem_wait(sm_data->mutex); +#elif defined(HAVE_SEM_INIT) + sem_wait(&sm_offset_ptr->mutex); #endif if ( mca_sharedfp_sm_verbose ) { @@ -74,10 +74,10 @@ int mca_sharedfp_sm_request_position(struct mca_sharedfp_base_data_t * sh, printf("Releasing sm lock...rank=%d",rank); } -#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES - sem_post(&sm_offset_ptr->mutex); -#else +#if defined(HAVE_SEM_OPEN) sem_post(sm_data->mutex); +#elif defined(HAVE_SEM_INIT) + sem_post(&sm_offset_ptr->mutex); #endif if ( mca_sharedfp_sm_verbose ) { printf("Released lock! released lock.for rank=%d\n",rank); diff --git a/ompi/mca/sharedfp/sm/sharedfp_sm_seek.c b/ompi/mca/sharedfp/sm/sharedfp_sm_seek.c index 3d74776263..535e08816b 100644 --- a/ompi/mca/sharedfp/sm/sharedfp_sm_seek.c +++ b/ompi/mca/sharedfp/sm/sharedfp_sm_seek.c @@ -121,10 +121,10 @@ mca_sharedfp_sm_seek (mca_io_ompio_file_t *fh, /* Aquire an exclusive lock */ sm_offset_ptr = sm_data->sm_offset_ptr; -#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES - sem_wait(&sm_offset_ptr->mutex); -#else +#if defined(HAVE_SEM_OPEN) sem_wait(sm_data->mutex); +#elif defined(HAVE_SEM_INIT) + sem_wait(&sm_offset_ptr->mutex); #endif if ( mca_sharedfp_sm_verbose ) { @@ -134,10 +134,10 @@ mca_sharedfp_sm_seek (mca_io_ompio_file_t *fh, if ( mca_sharedfp_sm_verbose ) { printf("sharedfp_sm_seek: Releasing sm lock...rank=%d",rank); fflush(stdout); } -#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES - sem_post(&sm_offset_ptr->mutex); -#else +#if defined(HAVE_SEM_OPEN) sem_post(sm_data->mutex); +#elif defined(HAVE_SEM_INIT) + sem_post(&sm_offset_ptr->mutex); #endif }