Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with gdal_viewshed with gcc 9.4 in debug mode (master only) #10826

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious: what changes here? Isn't the default ctor called in both cases?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help please -Weffc++ given that the constructor no longer explicitly initialize those members.

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
17 changes: 2 additions & 15 deletions port/cpl_worker_thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,8 @@ bool CPLWorkerThreadPool::SubmitJob(std::function<void()> task)
if (static_cast<int>(aWT.size()) < m_nMaxThreads)
{
// CPLDebug("CPL", "Starting new thread...");
std::unique_ptr<CPLWorkerThread> wt(new CPLWorkerThread);
wt->pfnInitFunc = nullptr;
wt->pInitData = nullptr;
auto wt = std::make_unique<CPLWorkerThread>();
wt->poTP = this;
wt->bMarkedAsWaiting = false;
//ABELL - Why should this fail? And this is a *pool* thread, not necessarily
// tied to the submitted job. The submitted job still needs to run, even if
// this fails. If we can't create a thread, should the entire pool become invalid?
Expand Down Expand Up @@ -279,10 +276,7 @@ bool CPLWorkerThreadPool::SubmitJobs(CPLThreadFunc pfnFunc,
if (static_cast<int>(aWT.size()) < m_nMaxThreads)
{
std::unique_ptr<CPLWorkerThread> wt(new CPLWorkerThread);
wt->pfnInitFunc = nullptr;
wt->pInitData = nullptr;
wt->poTP = this;
wt->bMarkedAsWaiting = false;
wt->hThread =
CPLCreateJoinableThread(WorkerThreadFunction, wt.get());
if (wt->hThread == nullptr)
Expand Down Expand Up @@ -425,10 +419,6 @@ bool CPLWorkerThreadPool::Setup(int nThreads, CPLThreadFunc pfnInitFunc,
wt->pfnInitFunc = pfnInitFunc;
wt->pInitData = pasInitData ? pasInitData[i] : nullptr;
wt->poTP = this;
{
std::lock_guard<std::mutex> oGuard(wt->m_mutex);
wt->bMarkedAsWaiting = false;
}
wt->hThread = CPLCreateJoinableThread(WorkerThreadFunction, wt.get());
if (wt->hThread == nullptr)
{
Expand Down Expand Up @@ -529,10 +519,7 @@ CPLWorkerThreadPool::GetNextJob(CPLWorkerThread *psWorkerThread)
std::unique_lock<std::mutex> oGuardThisThread(psWorkerThread->m_mutex);
// coverity[uninit_use_in_call]
oGuard.unlock();
while (psWorkerThread->bMarkedAsWaiting && eState != CPLWTS_STOP)
{
psWorkerThread->m_cv.wait(oGuardThisThread);
}
psWorkerThread->m_cv.wait(oGuardThisThread);
}
}

Expand Down
Loading