[Libreoffice-commits] core.git: vcl/inc vcl/source
Stephan Bergmann (via logerrit)
logerrit at kemper.freedesktop.org
Wed Sep 18 07:39:41 UTC 2019
vcl/inc/opengl/zone.hxx | 18 ++++++++++++++++--
vcl/source/opengl/OpenGLHelper.cxx | 4 ++--
2 files changed, 18 insertions(+), 4 deletions(-)
New commits:
commit ec17c8ec5256386b0197a8ffe5d7cad3e7d70f8f
Author: Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue Sep 17 20:39:43 2019 +0200
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Wed Sep 18 09:38:38 2019 +0200
-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 at redhat.com>
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 {
More information about the Libreoffice-commits
mailing list