Skip to content

Commit 4f85e0d

Browse files
committed
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.
1 parent d1d2305 commit 4f85e0d

File tree

4 files changed

+61
-23
lines changed

4 files changed

+61
-23
lines changed

ompi/mca/sharedfp/sm/configure.m4

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- shell-script -*-
2+
#
3+
# Copyright (c) 2004-2005 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-2005 High Performance Computing Center Stuttgart,
10+
# University of Stuttgart. All rights reserved.
11+
# Copyright (c) 2004-2012 The Regents of the University of California.
12+
# All rights reserved.
13+
# Copyright (c) 2010-2014 Cisco Systems, Inc. All rights reserved.
14+
# Copyright (c) 2008-2015 University of Houston. All rights reserved.
15+
# $COPYRIGHT$
16+
#
17+
# Additional copyrights may follow
18+
#
19+
# $HEADER$
20+
#
21+
22+
# MCA_sharedfp_sm_CONFIG(action-if-can-compile,
23+
# [action-if-cant-compile])
24+
# ------------------------------------------------
25+
AC_DEFUN([MCA_ompi_sharedfp_sm_CONFIG],[
26+
AC_CONFIG_FILES([ompi/mca/sharedfp/sm/Makefile])
27+
28+
sharedfp_sm_happy=no
29+
AC_CHECK_HEADER([semaphore.h],
30+
[AC_CHECK_FUNCS([sem_open],[sharedfp_sm_happy=yes],[])])
31+
32+
AC_CHECK_HEADER([semaphore.h],
33+
[AC_CHECK_FUNCS([sem_init],[sharedfp_sm_happy=yes],[])])
34+
35+
AS_IF([test "$sharedfp_sm_happy" = "yes"],
36+
[$1],
37+
[$2])
38+
])dnl

ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,13 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
164164
/* Initialize semaphore so that is shared between processes. */
165165
/* the semaphore is shared by keeping it in the shared memory segment */
166166

167-
#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES
168-
if(sem_init(&sm_offset_ptr->mutex, 1, 1) != -1){
169-
#else
167+
#if defined(HAVE_SEM_OPEN)
170168
sm_data->sem_name = (char*) malloc( sizeof(char) * (strlen(filename_basename)+32) );
171169
sprintf(sm_data->sem_name,"OMPIO_sharedfp_sem_%s",filename_basename);
172170

173171
if( (sm_data->mutex = sem_open(sm_data->sem_name, O_CREAT, 0644, 1)) != SEM_FAILED ) {
172+
#elif defined(HAVE_SEM_INIT)
173+
if(sem_init(&sm_offset_ptr->mutex, 1, 1) != -1){
174174
#endif
175175
/*If opening was successful*/
176176
/*Store the new file handle*/
@@ -184,14 +184,14 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
184184
if(rank==0){
185185
MPI_Offset position=0;
186186

187-
#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES
188-
sem_wait(&sm_offset_ptr->mutex);
189-
sm_offset_ptr->offset=position;
190-
sem_post(&sm_offset_ptr->mutex);
191-
#else
187+
#if defined(HAVE_SEM_OPEN)
192188
sem_wait(sm_data->mutex);
193189
sm_offset_ptr->offset=position;
194190
sem_post(sm_data->mutex);
191+
#elif defined(HAVE_SEM_INIT)
192+
sem_wait(&sm_offset_ptr->mutex);
193+
sm_offset_ptr->offset=position;
194+
sem_post(&sm_offset_ptr->mutex);
195195
#endif
196196
}
197197
}else{
@@ -235,11 +235,11 @@ int mca_sharedfp_sm_file_close (mca_io_ompio_file_t *fh)
235235
/*Close sm handle*/
236236
if (file_data->sm_offset_ptr) {
237237
/* destroy semaphore */
238-
#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES
239-
sem_destroy(&file_data->sm_offset_ptr->mutex);
240-
#else
238+
#if defined(HAVE_SEM_OPEN)
241239
sem_unlink (file_data->sem_name);
242240
free (file_data->sem_name);
241+
#elif defined(HAVE_SEM_INIT)
242+
sem_destroy(&file_data->sm_offset_ptr->mutex);
243243
#endif
244244
/*Release the shared memory segment.*/
245245
munmap(file_data->sm_offset_ptr,sizeof(struct mca_sharedfp_sm_offset));

ompi/mca/sharedfp/sm/sharedfp_sm_request_position.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ int mca_sharedfp_sm_request_position(struct mca_sharedfp_base_data_t * sh,
4848

4949
/* Aquire an exclusive lock */
5050

51-
#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES
52-
sem_wait(&sm_offset_ptr->mutex);
53-
#else
51+
#if defined(HAVE_SEM_OPEN)
5452
sem_wait(sm_data->mutex);
53+
#elif defined(HAVE_SEM_INIT)
54+
sem_wait(&sm_offset_ptr->mutex);
5555
#endif
5656

5757
if ( mca_sharedfp_sm_verbose ) {
@@ -74,10 +74,10 @@ int mca_sharedfp_sm_request_position(struct mca_sharedfp_base_data_t * sh,
7474
printf("Releasing sm lock...rank=%d",rank);
7575
}
7676

77-
#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES
78-
sem_post(&sm_offset_ptr->mutex);
79-
#else
77+
#if defined(HAVE_SEM_OPEN)
8078
sem_post(sm_data->mutex);
79+
#elif defined(HAVE_SEM_INIT)
80+
sem_post(&sm_offset_ptr->mutex);
8181
#endif
8282
if ( mca_sharedfp_sm_verbose ) {
8383
printf("Released lock! released lock.for rank=%d\n",rank);

ompi/mca/sharedfp/sm/sharedfp_sm_seek.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ mca_sharedfp_sm_seek (mca_io_ompio_file_t *fh,
121121
/* Aquire an exclusive lock */
122122
sm_offset_ptr = sm_data->sm_offset_ptr;
123123

124-
#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES
125-
sem_wait(&sm_offset_ptr->mutex);
126-
#else
124+
#if defined(HAVE_SEM_OPEN)
127125
sem_wait(sm_data->mutex);
126+
#elif defined(HAVE_SEM_INIT)
127+
sem_wait(&sm_offset_ptr->mutex);
128128
#endif
129129

130130
if ( mca_sharedfp_sm_verbose ) {
@@ -134,10 +134,10 @@ mca_sharedfp_sm_seek (mca_io_ompio_file_t *fh,
134134
if ( mca_sharedfp_sm_verbose ) {
135135
printf("sharedfp_sm_seek: Releasing sm lock...rank=%d",rank); fflush(stdout);
136136
}
137-
#ifdef OMPIO_SHAREDFP_USE_UNNAMED_SEMAPHORES
138-
sem_post(&sm_offset_ptr->mutex);
139-
#else
137+
#if defined(HAVE_SEM_OPEN)
140138
sem_post(sm_data->mutex);
139+
#elif defined(HAVE_SEM_INIT)
140+
sem_post(&sm_offset_ptr->mutex);
141141
#endif
142142
}
143143

0 commit comments

Comments
 (0)