1
1

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.
Этот коммит содержится в:
Jeff Squyres 2015-07-25 05:42:57 -07:00
родитель 4f85e0d833
Коммит 868a84d4da
4 изменённых файлов: 7 добавлений и 25 удалений

Просмотреть файл

@ -101,7 +101,7 @@ int mca_sharedfp_sm_iwrite (mca_io_ompio_file_t *fh,
*Structures and definitions only for this component
*--------------------------------------------------------------*/
struct mca_sharedfp_sm_offset{
sem_t mutex; /* the mutex: a Posix memory-based unnamed semaphore */
sem_t mutex; /* the mutex: a POSIX memory-based unnamed semaphore */
long long offset; /* and the shared file pointer offset */
};
@ -113,7 +113,10 @@ struct mca_sharedfp_sm_data
struct mca_sharedfp_sm_offset * sm_offset_ptr;
/*save filename so that we can remove the file on close*/
char * sm_filename;
sem_t *mutex; /* the mutex: a Posix memory-based named semaphore */
/* The mutex: it will either point to a POSIX memory-based named
semaphore, or it will point to the a POSIX memory-based unnamed
semaphore located in sm_offset_ptr->mutex. */
sem_t *mutex;
char *sem_name; /* Name of the semaphore */
};

Просмотреть файл

@ -170,6 +170,7 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
if( (sm_data->mutex = sem_open(sm_data->sem_name, O_CREAT, 0644, 1)) != SEM_FAILED ) {
#elif defined(HAVE_SEM_INIT)
sm_data->mutex = &sm_offset_ptr->mutex;
if(sem_init(&sm_offset_ptr->mutex, 1, 1) != -1){
#endif
/*If opening was successful*/
@ -184,15 +185,9 @@ int mca_sharedfp_sm_file_open (struct ompi_communicator_t *comm,
if(rank==0){
MPI_Offset position=0;
#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{
free(sm_filename);

Просмотреть файл

@ -48,11 +48,7 @@ int mca_sharedfp_sm_request_position(struct mca_sharedfp_base_data_t * sh,
/* Aquire an exclusive lock */
#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 ) {
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,
printf("Releasing sm lock...rank=%d",rank);
}
#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);
}

Просмотреть файл

@ -121,11 +121,7 @@ mca_sharedfp_sm_seek (mca_io_ompio_file_t *fh,
/* Aquire an exclusive lock */
sm_offset_ptr = sm_data->sm_offset_ptr;
#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 ) {
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,
if ( mca_sharedfp_sm_verbose ) {
printf("sharedfp_sm_seek: Releasing sm lock...rank=%d",rank); fflush(stdout);
}
#if defined(HAVE_SEM_OPEN)
sem_post(sm_data->mutex);
#elif defined(HAVE_SEM_INIT)
sem_post(&sm_offset_ptr->mutex);
#endif
sem_post(sm_data->mutex);
}
/* since we are only letting process 0, update the current pointer