diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-09-17 20:39:43 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-09-18 09:38:38 +0200 |
commit | ec17c8ec5256386b0197a8ffe5d7cad3e7d70f8f (patch) | |
tree | 3dfca98374e151a17f709e1310109f0869025011 /vcl | |
parent | e9024b469530a483a1019ccef2b8b664c1696456 (diff) |
-Werror=volatile in OpenGLZone
Recent GCC 10 trunk in C++20 mode reports issues like
> vcl/inc/opengl/zone.hxx:37:21: error: ‘++’ expression of ‘volatile’-qualified type is deprecated [-Werror=volatile]
> 37 | OpenGLZone() { gnEnterCount++; }
> | ^~~~~~~~~~~~
so look for a type that is more appropriate here (see the comment added to
vcl/inc/opengl/zone.hxx for details). (Though calls like
OpenGLZone::isInZone(), comparing gnEnterCount and gnLeaveCount, in
OpenGLWatchdogThread::execute are still not done atomically, of course.)
Change-Id: Ie5563addc65f629336f89cbccb73f7b9ac5e9870
Reviewed-on: https://gerrit.libreoffice.org/79072
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/opengl/zone.hxx | 18 | ||||
-rw-r--r-- | vcl/source/opengl/OpenGLHelper.cxx | 4 |
2 files changed, 18 insertions, 4 deletions
diff --git a/vcl/inc/opengl/zone.hxx b/vcl/inc/opengl/zone.hxx index d4d478bff411..3210186c3096 100644 --- a/vcl/inc/opengl/zone.hxx +++ b/vcl/inc/opengl/zone.hxx @@ -14,6 +14,10 @@ #include <sal/types.h> #include <vcl/dllapi.h> +#include <atomic> +#include <csignal> +#include <type_traits> + class OpenGLWatchdogThread; /** @@ -24,10 +28,20 @@ class VCL_DLLPUBLIC OpenGLZone { friend class OpenGLWatchdogThread; friend class OpenGLSalGraphicsImpl; + // gnEnterCount and gnLeaveCount are accessed both from multiple threads (cf. + // OpenGLWatchdogThread::execute; so need to be of atomic type) and from signal handlers (cf. + // VCLExceptionSignal_impl; so need to be of lock-free atomic type). sig_atomic_t is chosen as + // the underlying type under the assumption that it is most likely to lead to an atomic type + // that is actually lock-free. However, gnEnterCount and gnLeaveCount are both monotonically + // increasing, so will eventually overflow, so the underlying type better be unsigned, which + // sig_atomic_t is not guaranteed to be: + using AtomicCounter = std::atomic<std::make_unsigned_t<std::sig_atomic_t>>; + static_assert(AtomicCounter::is_always_lock_free); + /// how many times have we entered a GL zone - static volatile sal_uInt64 gnEnterCount; + static AtomicCounter gnEnterCount; /// how many times have we left a new GL zone - static volatile sal_uInt64 gnLeaveCount; + static AtomicCounter gnLeaveCount; static void enter() { gnEnterCount++; } static void leave() { gnLeaveCount++; } diff --git a/vcl/source/opengl/OpenGLHelper.cxx b/vcl/source/opengl/OpenGLHelper.cxx index a179f3710d2c..6b9b97a31f1a 100644 --- a/vcl/source/opengl/OpenGLHelper.cxx +++ b/vcl/source/opengl/OpenGLHelper.cxx @@ -44,8 +44,8 @@ #endif static bool volatile gbInShaderCompile = false; -sal_uInt64 volatile OpenGLZone::gnEnterCount = 0; -sal_uInt64 volatile OpenGLZone::gnLeaveCount = 0; +OpenGLZone::AtomicCounter OpenGLZone::gnEnterCount = 0; +OpenGLZone::AtomicCounter OpenGLZone::gnLeaveCount = 0; namespace { |