Skip to content

Commit

Permalink
viewshed: add explicit ~Cumulative() destructor, to avoid redefinitio…
Browse files Browse the repository at this point in the history
…n of NotifyQueue symbols, leading to mutex corruption

Fixes OSGeo#10825
  • Loading branch information
rouault committed Sep 18, 2024
1 parent 0c4395b commit dcc2d81
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 17 deletions.
5 changes: 4 additions & 1 deletion alg/viewshed/combiner.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/

#pragma once
#ifndef VIEWSHED_COMBINER_H_INCLUDED
#define VIEWSHED_COMBINER_H_INCLUDED

#include "cumulative.h"
#include "viewshed_types.h"
Expand Down Expand Up @@ -67,3 +68,5 @@ class Combiner

} // namespace viewshed
} // namespace gdal

#endif
4 changes: 4 additions & 0 deletions alg/viewshed/cumulative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ Cumulative::Cumulative(const Options &opts) : m_opts(opts)
{
}

/// Destructor
///
Cumulative::~Cumulative() = default;

/// Compute the cumulative viewshed of a raster band.
///
/// @param srcFilename Source filename.
Expand Down
13 changes: 12 additions & 1 deletion alg/viewshed/cumulative.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/

#pragma once
#ifndef VIEWSHED_CUMULATIVE_H_INCLUDED
#define VIEWSHED_CUMULATIVE_H_INCLUDED

#include <atomic>
#include <vector>
Expand All @@ -41,6 +42,11 @@ class Cumulative
{
public:
CPL_DLL explicit Cumulative(const Options &opts);
// We define an explicit destructor, whose implementation is in libgdal,
// otherwise with gcc 9.4 of Ubuntu 20.04 in debug mode, this would need to
// redefinition of the NotifyQueue class in both libgdal and gdal_viewshed,
// leading to weird things related to mutex.
CPL_DLL ~Cumulative();
CPL_DLL bool run(const std::string &srcFilename,
GDALProgressFunc pfnProgress = GDALDummyProgress,
void *pProgressArg = nullptr);
Expand Down Expand Up @@ -70,7 +76,12 @@ class Cumulative
void rollupRasters();
void scaleOutput();
bool writeOutput(DatasetPtr pDstDS);

Cumulative(const Cumulative &) = delete;
Cumulative &operator=(const Cumulative &) = delete;
};

} // namespace viewshed
} // namespace gdal

#endif
8 changes: 7 additions & 1 deletion alg/viewshed/notifyqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
#pragma once

#ifndef VIEWSHED_NOTIFYQUEUE_H_INCLUDED
#define VIEWSHED_NOTIFYQUEUE_H_INCLUDED

#include "cpl_port.h"

#include <condition_variable>
#include <mutex>
Expand Down Expand Up @@ -134,3 +138,5 @@ template <class T> class NotifyQueue

} // namespace viewshed
} // namespace gdal

#endif
5 changes: 4 additions & 1 deletion alg/viewshed/progress.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/

#pragma once
#ifndef VIEWSHED_PROGRESS_H_INCLUDED
#define VIEWSHED_PROGRESS_H_INCLUDED

#include <functional>
#include <mutex>
Expand Down Expand Up @@ -54,3 +55,5 @@ class Progress

} // namespace viewshed
} // namespace gdal

#endif
5 changes: 4 additions & 1 deletion alg/viewshed/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/

#pragma once
#ifndef VIEWSHED_UTIL_H_INCLUDED
#define VIEWSHED_UTIL_H_INCLUDED

#include "viewshed_types.h"

Expand All @@ -36,3 +37,5 @@ DatasetPtr createOutputDataset(GDALRasterBand &srcBand, const Options &opts,

} // namespace viewshed
} // namespace gdal

#endif
6 changes: 6 additions & 0 deletions alg/viewshed/viewshed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ bool getTransforms(GDALRasterBand &band, double *pFwdTransform,

} // unnamed namespace

Viewshed::Viewshed(const Options &opts) : oOpts{opts}
{
}

Viewshed::~Viewshed() = default;

/// Calculate the extent of the output raster in terms of the input raster and
/// save the input raster extent.
///
Expand Down
25 changes: 14 additions & 11 deletions alg/viewshed/viewshed.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
* DEALINGS IN THE SOFTWARE.
****************************************************************************/

#pragma once
#ifndef VIEWSHED_H_INCLUDED
#define VIEWSHED_H_INCLUDED

#include <algorithm>
#include <array>
Expand Down Expand Up @@ -59,13 +60,10 @@ class Viewshed
*
* @param opts Options to use when calculating viewshed.
*/
CPL_DLL explicit Viewshed(const Options &opts)
: oOpts{opts}, oOutExtent{}, oCurExtent{}, poDstDS{}, pSrcBand{}
{
}
CPL_DLL explicit Viewshed(const Options &opts);

Viewshed(const Viewshed &) = delete;
Viewshed &operator=(const Viewshed &) = delete;
/** Destructor */
CPL_DLL ~Viewshed();

CPL_DLL bool run(GDALRasterBandH hBand,
GDALProgressFunc pfnProgress = GDALDummyProgress,
Expand All @@ -83,10 +81,10 @@ class Viewshed

private:
Options oOpts;
Window oOutExtent;
Window oCurExtent;
DatasetPtr poDstDS;
GDALRasterBand *pSrcBand;
Window oOutExtent{};
Window oCurExtent{};
DatasetPtr poDstDS{};
GDALRasterBand *pSrcBand = nullptr;

DatasetPtr execute(int nX, int nY, const std::string &outFilename);
void setOutput(double &dfResult, double &dfCellVal, double dfZ);
Expand All @@ -96,7 +94,12 @@ class Viewshed
std::vector<double> &thisLineVal);
bool calcExtents(int nX, int nY,
const std::array<double, 6> &adfInvTransform);

Viewshed(const Viewshed &) = delete;
Viewshed &operator=(const Viewshed &) = delete;
};

} // namespace viewshed
} // namespace gdal

#endif
5 changes: 4 additions & 1 deletion alg/viewshed/viewshed_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
****************************************************************************/
#pragma once
#ifndef VIEWSHED_TYPES_H_INCLUDED
#define VIEWSHED_TYPES_H_INCLUDED

#include <algorithm>
#include <string>
Expand Down Expand Up @@ -171,3 +172,5 @@ struct Window

} // namespace viewshed
} // namespace gdal

#endif

0 comments on commit dcc2d81

Please sign in to comment.