diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2020-04-04 12:24:12 +0200 |
|---|---|---|
| committer | Kristian Evers <kristianevers@gmail.com> | 2020-04-04 19:23:53 +0200 |
| commit | 1f792e6b9c9b41c4da8f8996e3eb325e444b0099 (patch) | |
| tree | 6bd265cde3ea00eb45b688ae021aee4f5eb6d818 /src/transformations/vgridshift.cpp | |
| parent | 8aab6fd948a5e9c16a352fa34a4e8cde54d5d924 (diff) | |
| download | PROJ-1f792e6b9c9b41c4da8f8996e3eb325e444b0099.tar.gz PROJ-1f792e6b9c9b41c4da8f8996e3eb325e444b0099.zip | |
hgridshift/vgridshift: defer grid opening when grid has already been opened
Relates to #2115
With the fix of https://github.com/OSGeo/PROJ/pull/2128, transforming between
EPSG:4326+3855 and EPSG:4269+5703 leads to many operations with many grids,
and opening a file handle for each operation saturates the limit of 1024
file handles opened simunalteously. This fix defers grid opening when a
transformation has already been instanciated with the same grid.
Diffstat (limited to 'src/transformations/vgridshift.cpp')
| -rw-r--r-- | src/transformations/vgridshift.cpp | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/src/transformations/vgridshift.cpp b/src/transformations/vgridshift.cpp index 121b795a..6ee8a6b0 100644 --- a/src/transformations/vgridshift.cpp +++ b/src/transformations/vgridshift.cpp @@ -12,6 +12,27 @@ PROJ_HEAD(vgridshift, "Vertical grid shift"); using namespace NS_PROJ; + +#ifdef __MINGW32__ +// mingw32-win32 doesn't implement std::mutex +namespace { +class MyMutex { + public: + // cppcheck-suppress functionStatic + void lock() { pj_acquire_lock(); } + // cppcheck-suppress functionStatic + void unlock() { pj_release_lock(); } +}; +} +#else +#include <mutex> +#define MyMutex std::mutex +#endif + +static MyMutex gMutex{}; +static std::set<std::string> gKnownGrids{}; + + namespace { // anonymous namespace struct vgridshiftData { double t_final = 0; @@ -192,13 +213,27 @@ PJ *TRANSFORMATION(vgridshift,0) { Q->defer_grid_opening = true; } else { - /* Build gridlist. P->vgridlist_geoid can be empty if +grids only ask for optional grids. */ - Q->grids = pj_vgrid_init(P, "grids"); + const char *gridnames = pj_param(P->ctx, P->params, "sgrids").s; + gMutex.lock(); + const bool isKnownGrid = gKnownGrids.find(gridnames) != gKnownGrids.end(); + gMutex.unlock(); - /* Was gridlist compiled properly? */ - if ( proj_errno(P) ) { - proj_log_error(P, "vgridshift: could not find required grid(s)."); - return destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID); + if( isKnownGrid ) { + Q->defer_grid_opening = true; + } + else { + /* Build gridlist. P->vgridlist_geoid can be empty if +grids only ask for optional grids. */ + Q->grids = pj_vgrid_init(P, "grids"); + + /* Was gridlist compiled properly? */ + if ( proj_errno(P) ) { + proj_log_error(P, "vgridshift: could not find required grid(s)."); + return destructor(P, PJD_ERR_FAILED_TO_LOAD_GRID); + } + + gMutex.lock(); + gKnownGrids.insert(gridnames); + gMutex.unlock(); } } @@ -214,3 +249,9 @@ PJ *TRANSFORMATION(vgridshift,0) { return P; } + +void pj_clear_vgridshift_knowngrids_cache() { + gMutex.lock(); + gKnownGrids.clear(); + gMutex.unlock(); +} |
