Skip to content

Commit 868a84d

Browse files
committed
sharedfp: have sm_data->mutex always point to the right mutex
Even if the mutex is actually located in sm_data->sm_offset_ptr->mutex, have sm_data->mutex point to it. This avoids a few #if blocks that are otherwise identical.
1 parent 4f85e0d commit 868a84d

File tree

4 files changed

+7
-25
lines changed

4 files changed

+7
-25
lines changed

ompi/mca/sharedfp/sm/sharedfp_sm.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ int mca_sharedfp_sm_iwrite (mca_io_ompio_file_t *fh,
101101
*Structures and definitions only for this component
102102
*--------------------------------------------------------------*/
103103
struct mca_sharedfp_sm_offset{
104-
sem_t mutex; /* the mutex: a Posix memory-based unnamed semaphore */
104+
sem_t mutex; /* the mutex: a POSIX memory-based unnamed semaphore */
105105
long long offset; /* and the shared file pointer offset */
106106
};
107107

@@ -113,7 +113,10 @@ struct mca_sharedfp_sm_data
113113
struct mca_sharedfp_sm_offset * sm_offset_ptr;
114114
/*save filename so that we can remove the file on close*/
115115
char * sm_filename;
116-
sem_t *mutex; /* the mutex: a Posix memory-based named semaphore */
116+
/* The mutex: it will either point to a POSIX memory-based named
117+
semaphore, or it will point to the a POSIX memory-based unnamed
118+
semaphore located in sm_offset_ptr->mutex. */
119+
sem_t *mutex;
117120
char *sem_name; /* Name of the semaphore */
118121
};
119122

ompi/mca/sharedfp/sm/sharedfp_sm_file_open.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
170170

171171
if( (sm_data->mutex = sem_open(sm_data->sem_name, O_CREAT, 0644, 1)) != SEM_FAILED ) {
172172
#elif defined(HAVE_SEM_INIT)
173+
sm_data->mutex = &sm_offset_ptr->mutex;
173174
if(sem_init(&sm_offset_ptr->mutex, 1, 1) != -1){
174175
#endif
175176
/*If opening was successful*/
@@ -184,15 +185,9 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
184185
if(rank==0){
185186
MPI_Offset position=0;
186187

187-
#if defined(HAVE_SEM_OPEN)
188188
sem_wait(sm_data->mutex);
189189
sm_offset_ptr->offset=position;
190190
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);
195-
#endif
196191
}
197192
}else{
198193
free(sm_filename);

ompi/mca/sharedfp/sm/sharedfp_sm_request_position.c

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

4949
/* Aquire an exclusive lock */
5050

51-
#if defined(HAVE_SEM_OPEN)
5251
sem_wait(sm_data->mutex);
53-
#elif defined(HAVE_SEM_INIT)
54-
sem_wait(&sm_offset_ptr->mutex);
55-
#endif
5652

5753
if ( mca_sharedfp_sm_verbose ) {
5854
printf("Succeeded! Acquired sm lock.for rank=%d\n",rank);
@@ -74,11 +70,7 @@ int mca_sharedfp_sm_request_position(struct mca_sharedfp_base_data_t * sh,
7470
printf("Releasing sm lock...rank=%d",rank);
7571
}
7672

77-
#if defined(HAVE_SEM_OPEN)
7873
sem_post(sm_data->mutex);
79-
#elif defined(HAVE_SEM_INIT)
80-
sem_post(&sm_offset_ptr->mutex);
81-
#endif
8274
if ( mca_sharedfp_sm_verbose ) {
8375
printf("Released lock! released lock.for rank=%d\n",rank);
8476
}

ompi/mca/sharedfp/sm/sharedfp_sm_seek.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,7 @@ 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-
#if defined(HAVE_SEM_OPEN)
125124
sem_wait(sm_data->mutex);
126-
#elif defined(HAVE_SEM_INIT)
127-
sem_wait(&sm_offset_ptr->mutex);
128-
#endif
129125

130126
if ( mca_sharedfp_sm_verbose ) {
131127
printf("sharedfp_sm_seek: Success! Acquired sm lock.for rank=%d\n",rank);
@@ -134,11 +130,7 @@ mca_sharedfp_sm_seek (mca_io_ompio_file_t *fh,
134130
if ( mca_sharedfp_sm_verbose ) {
135131
printf("sharedfp_sm_seek: Releasing sm lock...rank=%d",rank); fflush(stdout);
136132
}
137-
#if defined(HAVE_SEM_OPEN)
138-
sem_post(sm_data->mutex);
139-
#elif defined(HAVE_SEM_INIT)
140-
sem_post(&sm_offset_ptr->mutex);
141-
#endif
133+
sem_post(sm_data->mutex);
142134
}
143135

144136
/* since we are only letting process 0, update the current pointer

0 commit comments

Comments
 (0)