Skip to content
Snippets Groups Projects
Commit 200556f2 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

cdo_cdf_openread(): added parameter lockIO

parent 070490ed
No related branches found
No related tags found
1 merge request!245M214003/develop
Subproject commit 3c7a570ecb5b19bba4861bf60851cb10e35c7128
Subproject commit 266b3c9b446d228e64cd1daa7bc3a00560310242
......@@ -139,15 +139,15 @@ vlist_copy_flag_locked(int p_vlistID2, int p_vlistID1)
}
void
open_lock(void)
open_lock(bool lockIO)
{
cthread_mutex_lock(Threading::cdoLockIO ? streamMutex : streamOpenMutex);
cthread_mutex_lock((Threading::cdoLockIO || lockIO) ? streamMutex : streamOpenMutex);
}
void
open_unlock(void)
open_unlock(bool lockIO)
{
cthread_mutex_unlock(Threading::cdoLockIO ? streamMutex : streamOpenMutex);
cthread_mutex_unlock((Threading::cdoLockIO || lockIO) ? streamMutex : streamOpenMutex);
}
void
......
......@@ -2,6 +2,7 @@
#define CDI_LOCKEDIO_H
#include <cstddef>
#include <cstdbool>
int stream_open_read_locked(const char *filename);
void stream_close_locked(int p_fileID);
......@@ -17,8 +18,8 @@ int stream_inq_time_step_locked(int p_fileID, int p_tsID);
int stream_def_time_step_locked(int p_fileID, int p_tsID);
int stream_copy_record_locked(int p_fileID, int p_targetFileID);
void vlist_copy_flag_locked(int p_vlistID2, int p_vlistID1);
void open_lock(void);
void open_unlock(void);
void open_lock(bool lockIO = false);
void open_unlock(bool lockIO = false);
void cdo_vlist_copy_flag(int vlistID2, int vlistID1);
#endif
......@@ -498,7 +498,11 @@ cdo_define_grid(const char *pgridfile)
if (buffer[1] == 'H' && buffer[2] == 'D' && buffer[3] == 'F') // HDF
{
Debug(cdoDebug, "Grid from NetCDF4 file");
gridID = grid_from_nc_file(filename);
bool lockIO = false;
#ifndef HAVE_NC4HDF5_THREADSAFE
// if (Options::test) lockIO = true;
#endif
gridID = grid_from_nc_file(filename, lockIO);
}
}
......
......@@ -74,7 +74,7 @@ GridDesciption
int grid_define(GridDesciption &grid);
int grid_from_nc_file(const char *gridfile);
int grid_from_nc_file(const char *gridfile, bool lockIO = false);
int grid_from_h5_file(const char *gridfile);
int grid_from_name(const std::string &gridname);
......@@ -84,8 +84,8 @@ int cdo_define_grid(const std::string &gridfile);
int grid_read(FILE *gfp, const char *dname); // TODO: Find better place for this
int cdo_cdf_openread(const char *filename);
void cdo_cdf_close(int nc_file_id);
int cdo_cdf_openread(const char *filename, bool lockIO = false);
void cdo_cdf_close(int nc_file_id, bool lockIO = false);
void cdo_set_grids(const char *gridarg);
void gaussian_latitudes_in_degrees(std::vector<double> &lats, std::vector<double> &lat_bounds, size_t nlat);
......
......@@ -31,15 +31,15 @@ nce(int istat)
#endif
int
cdo_cdf_openread(const char *filename)
cdo_cdf_openread(const char *filename, bool lockIO)
{
int fileID = -1;
#ifdef HAVE_LIBNETCDF
int nc_file_id; // NetCDF grid file id
open_lock();
open_lock(lockIO);
auto istat = nc_open(filename, NC_NOWRITE, &nc_file_id);
open_unlock();
open_unlock(lockIO);
if (istat != NC_NOERR) cdo_abort("nc_open failed on %s! %s", filename, nc_strerror(istat));
fileID = nc_file_id;
......@@ -51,12 +51,12 @@ cdo_cdf_openread(const char *filename)
}
void
cdo_cdf_close(int nc_file_id)
cdo_cdf_close(int nc_file_id, bool lockIO)
{
#ifdef HAVE_LIBNETCDF
open_lock();
open_lock(lockIO);
auto istat = nc_close(nc_file_id);
open_unlock();
open_unlock(lockIO);
if (istat != NC_NOERR) cdo_abort("nc_close failed! %s", nc_strerror(istat));
#else
cdo_warning("NetCDF support not compiled in!");
......@@ -64,7 +64,7 @@ cdo_cdf_close(int nc_file_id)
}
int
grid_from_nc_file(const char *gridfile)
grid_from_nc_file(const char *gridfile, bool lockIO)
{
int gridID = -1;
#ifdef HAVE_LIBNETCDF
......@@ -86,7 +86,7 @@ grid_from_nc_file(const char *gridfile)
// open grid file and read grid size/name data
auto nc_file_id = cdo_cdf_openread(gridfile);
auto nc_file_id = cdo_cdf_openread(gridfile, lockIO);
if (nc_inq_dimid(nc_file_id, "grid_size", &nc_gridsize_id) == NC_NOERR
&& nc_inq_dimid(nc_file_id, "grid_rank", &nc_gridrank_id) == NC_NOERR
......@@ -166,7 +166,7 @@ grid_from_nc_file(const char *gridfile)
gridID = grid_define(grid);
}
cdo_cdf_close(nc_file_id);
cdo_cdf_close(nc_file_id, lockIO);
#else
cdo_warning("NetCDF support not compiled in!");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment