gmx_bool gmx_fio_ndoe_gmx_bool(t_fileio *fio, gmx_bool *item, int n, const char *desc, const char *srcfile, int line) { gmx_bool ret=TRUE; int i,itmp; gmx_fio_lock(fio); for(i=0;i<n;i++) { if (fio->bRead) { ret=ret && fio->iotp->nread(fio, &itmp, 1, eioINT, desc, srcfile, line); item[i] = itmp; } else { itmp = item[i]; ret=ret && fio->iotp->nwrite(fio, &itmp, 1, eioINT, desc, srcfile, line); } } gmx_fio_unlock(fio); return ret; }
/* Stop looping through the open_files. Unlocks the global lock. */ static void gmx_fio_stop_getting_next(t_fileio *fio) { gmx_fio_unlock(fio); #ifdef GMX_THREAD_MPI tMPI_Thread_mutex_unlock(&open_file_mutex); #endif }
/* get the first open file, or NULL if there is none. Returns a locked fio. */ static t_fileio *gmx_fio_get_first(void) { t_fileio *ret; /* first lock the big open_files mutex and the dummy's mutex */ #ifdef GMX_THREAD_MPI /* first lock the big open_files mutex. */ tMPI_Thread_mutex_lock(&open_file_mutex); #endif gmx_fio_make_dummy(); gmx_fio_lock(open_files); ret = open_files->next; /* check whether there were any to begin with */ if (ret == open_files) { /* after this, the open_file pointer should never change */ ret = NULL; } else { gmx_fio_lock(open_files->next); } gmx_fio_unlock(open_files); return ret; }
int gmx_fio_close(t_fileio *fio) { int rc = 0; /* 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); if (fio->iFTP == efTNG) { gmx_incons("gmx_fio_close should not be called on a TNG file"); } gmx_fio_lock(fio); /* first remove it from the list */ gmx_fio_remove(fio); rc = gmx_fio_close_locked(fio); gmx_fio_unlock(fio); sfree(fio->fn); sfree(fio); tMPI_Thread_mutex_unlock(&open_file_mutex); return rc; }
gmx_bool gmx_fio_reade_double(t_fileio *fio, double *item, const char *desc, const char *srcfile, int line) { gmx_bool ret; gmx_fio_lock(fio); ret=fio->iotp->nread(fio, item, 1, eioDOUBLE, desc, srcfile, line); gmx_fio_unlock(fio); return ret; }
gmx_bool gmx_fio_nwritee_rvec(t_fileio *fio, const rvec *item, int n, const char *desc, const char *srcfile, int line) { gmx_bool ret; gmx_fio_lock(fio); ret=fio->iotp->nwrite(fio, item, n, eioNRVEC, desc, srcfile, line); gmx_fio_unlock(fio); return ret; }
gmx_bool gmx_fio_nwritee_uchar(t_fileio *fio, const unsigned char *item, int n, const char *desc, const char *srcfile, int line) { gmx_bool ret; gmx_fio_lock(fio); ret=fio->iotp->nwrite(fio, item, n, eioNUCHAR, desc, srcfile, line); gmx_fio_unlock(fio); return ret; }
gmx_bool gmx_fio_writee_string(t_fileio *fio, const char *item, const char *desc, const char *srcfile, int line) { gmx_bool ret; gmx_fio_lock(fio); ret=fio->iotp->nwrite(fio, item, 1, eioSTRING, desc, srcfile, line); gmx_fio_unlock(fio); return ret; }
gmx_bool gmx_fio_writee_ivec(t_fileio *fio, ivec *item, const char *desc, const char *srcfile, int line) { gmx_bool ret; gmx_fio_lock(fio); ret=fio->iotp->nwrite(fio, item, 1, eioIVEC, desc, srcfile, line); gmx_fio_unlock(fio); return ret; }
gmx_bool gmx_fio_writee_ushort(t_fileio *fio, unsigned short item, const char *desc, const char *srcfile, int line) { gmx_bool ret; gmx_fio_lock(fio); ret=fio->iotp->nwrite(fio, &item, 1, eioUSHORT, desc, srcfile, line); gmx_fio_unlock(fio); return ret; }
gmx_bool gmx_fio_writee_gmx_large_int(t_fileio *fio, gmx_large_int_t item, const char *desc, const char *srcfile, int line) { gmx_bool ret; gmx_fio_lock(fio); ret=fio->iotp->nwrite(fio, &item, 1, eioGMX_LARGE_INT, desc, srcfile, line); gmx_fio_unlock(fio); return ret; }
gmx_bool gmx_fio_writee_float(t_fileio *fio, float item, const char *desc, const char *srcfile, int line) { gmx_bool ret; gmx_fio_lock(fio); ret=fio->iotp->nwrite(fio, &item, 1, eioFLOAT, desc, srcfile, line); gmx_fio_unlock(fio); return ret; }
gmx_bool gmx_fio_writee_real(t_fileio *fio, real item, const char *desc, const char *srcfile, int line) { gmx_bool ret; gmx_fio_lock(fio); ret=fio->iotp->nwrite(fio, &item, 1, eioREAL, desc, srcfile, line); gmx_fio_unlock(fio); return ret; }
gmx_bool gmx_fio_reade_uchar(t_fileio *fio, unsigned char *item, const char *desc, const char *srcfile, int line) { gmx_bool ret; gmx_fio_lock(fio); ret=fio->iotp->nread(fio, item, 1, eioUCHAR, desc, srcfile, line); gmx_fio_unlock(fio); return ret; }
gmx_bool gmx_fio_writee_int64(t_fileio *fio, gmx_int64_t item, const char *desc, const char *srcfile, int line) { gmx_bool ret; gmx_fio_lock(fio); ret = fio->iotp->nwrite(fio, &item, 1, eioINT64, desc, srcfile, line); gmx_fio_unlock(fio); return ret; }
gmx_bool gmx_fio_reade_int(t_fileio *fio, int *item, const char *desc, const char *srcfile, int line) { gmx_bool ret; gmx_fio_lock(fio); ret=fio->iotp->nread(fio, item, 1, eioINT, desc, srcfile, line); gmx_fio_unlock(fio); return ret; }
char *gmx_fio_getname(t_fileio *fio) { char *ret; gmx_fio_lock(fio); ret = fio->fn; gmx_fio_unlock(fio); return ret; }
int gmx_fio_flush(t_fileio* fio) { int ret; gmx_fio_lock(fio); ret = gmx_fio_int_flush(fio); gmx_fio_unlock(fio); return ret; }
int gmx_fio_getftp(t_fileio* fio) { int ret; gmx_fio_lock(fio); ret = fio->iFTP; gmx_fio_unlock(fio); return ret; }
/* remove a t_fileio into the list. We assume the fio is locked, and we leave 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; /* lock prev, because we're changing it */ gmx_fio_lock(fio->prev); /* now set the prev's pointer */ fio->prev->next = fio->next; gmx_fio_unlock(fio->prev); /* with the next ptr, we can simply lock while the original was locked */ gmx_fio_lock(fio->next); fio->next->prev = fio->prev; gmx_fio_unlock(fio->next); /* and make sure we point nowhere in particular */ fio->next = fio->prev = fio; }
gmx_bool gmx_fio_getdebug(t_fileio *fio) { gmx_bool ret; gmx_fio_lock(fio); ret = fio->bDebug; gmx_fio_unlock(fio); return ret; }
int xtc_seek_time(t_fileio *fio, real time, int natoms, gmx_bool bSeekForwardOnly) { int ret; gmx_fio_lock(fio); ret = xdr_xtc_seek_time(time, fio->fp, fio->xdr, natoms, bSeekForwardOnly); gmx_fio_unlock(fio); return ret; }
int xtc_seek_frame(t_fileio *fio, int frame, int natoms) { int ret; gmx_fio_lock(fio); ret = xdr_xtc_seek_frame(frame, fio->fp, fio->xdr, natoms); gmx_fio_unlock(fio); return ret; }
gmx_bool gmx_fio_getread(t_fileio* fio) { gmx_bool ret; gmx_fio_lock(fio); ret = fio->bRead; gmx_fio_unlock(fio); return ret; }
int gmx_fio_fsync(t_fileio *fio) { int rc; gmx_fio_lock(fio); rc = gmx_fio_int_fsync(fio); gmx_fio_unlock(fio); return rc; }
/* * fio: file to compute md5 for * offset: starting pointer of region to use for md5 * digest: return array of md5 sum */ int gmx_fio_get_file_md5(t_fileio *fio, gmx_off_t offset, unsigned char digest[]) { int ret; gmx_fio_lock(fio); ret = gmx_fio_int_get_file_md5(fio, offset, digest); gmx_fio_unlock(fio); return ret; }
gmx_bool gmx_fio_nreade_int(t_fileio *fio, int *item, int n, const char *desc, const char *srcfile, int line) { gmx_bool ret=TRUE; int i; gmx_fio_lock(fio); for(i=0;i<n;i++) ret=ret && fio->iotp->nread(fio, &(item[i]), 1, eioINT, desc, srcfile, line); gmx_fio_unlock(fio); return ret; }
gmx_bool gmx_fio_nreade_string(t_fileio *fio, char *item[], int n, const char *desc, const char *srcfile, int line) { gmx_bool ret=TRUE; int i; gmx_fio_lock(fio); for(i=0;i<n;i++) ret=ret && fio->iotp->nread(fio, item[i], 1, eioSTRING, desc, srcfile, line); gmx_fio_unlock(fio); return ret; }
FILE * gmx_fio_fopen(const char *fn, const char *mode) { FILE *fp, *ret; t_fileio *fio; fio = gmx_fio_open(fn, mode); gmx_fio_lock(fio); ret = fio->fp; gmx_fio_unlock(fio); return ret; }
FILE *gmx_fio_getfp(t_fileio *fio) { FILE *ret = NULL; gmx_fio_lock(fio); if (fio->fp) { ret = fio->fp; } gmx_fio_unlock(fio); return ret; }