}
/* remove a t_fileio into the list. We assume the fio is locked, and we leave
- it locked. */
-static void gmx_fio_remove(t_fileio *fio, gmx_bool global_lock)
+ it locked.
+ NOTE: We also assume that the open_file_mutex has been locked */
+static void gmx_fio_remove(t_fileio *fio)
{
t_fileio *prev;
-#ifdef GMX_THREADS
- /* first lock the big open_files mutex. */
- /* We don't want two processes operating on this list at the same time */
- if (global_lock)
- tMPI_Thread_mutex_lock(&open_file_mutex);
-#endif
-
/* lock prev, because we're changing it */
gmx_fio_lock(fio->prev);
/* and make sure we point nowhere in particular */
fio->next=fio->prev=fio;
-
-#ifdef GMX_THREADS
- /* now unlock the big open_files mutex. */
- if (global_lock)
- tMPI_Thread_mutex_unlock(&open_file_mutex);
-#endif
-
}
{
int rc = 0;
+#ifdef GMX_THREADS
+ /* first lock the big open_files mutex. */
+ /* We don't want two processes operating on the list at the same time */
+ tMPI_Thread_mutex_lock(&open_file_mutex);
+#endif
+
gmx_fio_lock(fio);
/* first remove it from the list */
- gmx_fio_remove(fio, TRUE);
+ gmx_fio_remove(fio);
rc=gmx_fio_close_locked(fio);
gmx_fio_unlock(fio);
sfree(fio);
+#ifdef GMX_THREADS
+ tMPI_Thread_mutex_unlock(&open_file_mutex);
+#endif
+
return rc;
}
if (cur->fp == fp)
{
rc=gmx_fio_close_locked(cur);
- gmx_fio_remove(cur,FALSE);
+ gmx_fio_remove(cur);
gmx_fio_stop_getting_next(cur);
break;
}