summaryrefslogtreecommitdiff
path: root/include/opencl
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-09-18 19:13:34 +0200
committerStephan Bergmann <sbergman@redhat.com>2019-09-18 20:28:29 +0200
commit33d922ea07b6b20276471b19fd9c148ed90d7442 (patch)
tree84a4ea43f15af47852308d31c8b32d1b75fdcc2f /include/opencl
parentc3940a9fb2de7ba09f7d82497491918fd9bb3d0e (diff)
-Werror=volatile in OpenCLZone
Recent GCC 10 trunk in C++20 mode reports issues like > include/opencl/OpenCLZone.hxx:27:9: error: ‘++’ expression of ‘volatile’-qualified type is deprecated [-Werror=volatile] > 27 | gnEnterCount++; > | ^~~~~~~~~~~~ But unlike in the case of ec17c8ec5256386b0197a8ffe5d7cad3e7d70f8f "-Werror=volatile in OpenGLZone", * it looks like there are no multi-threading issues here, and the counters are just accessed (via OpenCLZone::isInZone) from the VCLExceptionSignal_impl signal handler in addition to being modified (via OpenCLZone RAII objects) from mainline code; and * from the usage pattern of gnEnterCount and gnLeaveCount it appears that they can be combined into a single counter. (f41eb66302208f384a475fb20c98b6d1b0676cb6 "opencl: OpenCLZone, detect CL device change and disable CL on crash" presumably modelled OpenCLZone naively after OpenGLZone, without simplifying it where possible.) One minor advantage of having two monotonically increasing counters is that when they overflow, the implementation of isInZone (comparing them for equality) still gives ~useful results (assuming that a false "match" of non-overflown gnEnterCount against overflown gnLeaveCount is highly unlikely). But instances of OpenCLZone RAII objects are presumably never nested very deeply (if at all), so that the newly added "TODO: overflow" comment (which would even cause UB if std::sig_atomic_t is signed) is probably of no practical concern. Change-Id: I92e1f2c46ca996a0a86bacabcda2accba5eb6298 Reviewed-on: https://gerrit.libreoffice.org/79106 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/opencl')
-rw-r--r--include/opencl/OpenCLZone.hxx18
1 files changed, 11 insertions, 7 deletions
diff --git a/include/opencl/OpenCLZone.hxx b/include/opencl/OpenCLZone.hxx
index 0d2059dddc87..d1c59dcd25d4 100644
--- a/include/opencl/OpenCLZone.hxx
+++ b/include/opencl/OpenCLZone.hxx
@@ -10,33 +10,37 @@
#ifndef INCLUDED_OPENCL_INC_OPENCL_ZONE_HXX
#define INCLUDED_OPENCL_INC_OPENCL_ZONE_HXX
+#include <sal/config.h>
+
+#include <cassert>
+#include <csignal>
+
#include <opencl/opencldllapi.h>
// FIXME: post back-port, templatize me and share with OpenGLZone.
class OPENCL_DLLPUBLIC OpenCLZone
{
- /// how many times have we entered a CL zone
- static volatile sal_uInt64 gnEnterCount;
- /// how many times have we left a new CL zone
- static volatile sal_uInt64 gnLeaveCount;
+ /// how many times have we entered a CL zone and not yet left it
+ static volatile std::sig_atomic_t gnEnterCount;
static volatile bool gbInInitialTest;
public:
OpenCLZone()
{
- gnEnterCount++;
+ gnEnterCount = gnEnterCount + 1; //TODO: overflow
}
~OpenCLZone()
{
- gnLeaveCount++;
+ assert(gnEnterCount > 0);
+ gnEnterCount = gnEnterCount - 1;
if (!isInZone())
gbInInitialTest = false;
}
static bool isInZone()
{
- return gnEnterCount != gnLeaveCount;
+ return gnEnterCount > 0;
}
static bool isInInitialTest()