LibreOffice Module vcl (master)  1
zone.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #ifndef INCLUDED_VCL_INC_OPENGL_ZONE_H
11 #define INCLUDED_VCL_INC_OPENGL_ZONE_H
12 
13 #include <sal/config.h>
14 #include <sal/types.h>
15 #include <vcl/dllapi.h>
16 
17 #include <atomic>
18 #include <csignal>
19 #include <type_traits>
20 
22 
28  friend class OpenGLWatchdogThread;
29  friend class OpenGLSalGraphicsImpl;
30 
31  // gnEnterCount and gnLeaveCount are accessed both from multiple threads (cf.
32  // OpenGLWatchdogThread::execute; so need to be of atomic type) and from signal handlers (cf.
33  // VCLExceptionSignal_impl; so need to be of lock-free atomic type). sig_atomic_t is chosen as
34  // the underlying type under the assumption that it is most likely to lead to an atomic type
35  // that is actually lock-free. However, gnEnterCount and gnLeaveCount are both monotonically
36  // increasing, so will eventually overflow, so the underlying type better be unsigned, which
37  // sig_atomic_t is not guaranteed to be:
38 #if !defined ARM32 || (defined ARM32 && defined __ARM_PCS_VFP)
39  using AtomicCounter = std::atomic<std::make_unsigned_t<std::sig_atomic_t>>;
40  static_assert(AtomicCounter::is_always_lock_free);
41 #else
42  using AtomicCounter = volatile std::make_unsigned_t<std::sig_atomic_t>;
43 #endif
44 
49 
50  static void enter() { gnEnterCount++; }
51  static void leave() { gnLeaveCount++; }
52 public:
53  OpenGLZone() { enter(); }
54  ~OpenGLZone() { leave(); }
55  static bool isInZone() { return gnEnterCount != gnLeaveCount; }
56  static void hardDisable();
57  static void relaxWatchdogTimings();
58 };
59 
63 public:
65 };
66 
68 public:
71 };
72 
73 #endif // INCLUDED_VCL_INC_OPENGL_ZONE_H
74 
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
OpenGLZone const aZone
Definition: zone.hxx:62
static AtomicCounter gnEnterCount
how many times have we entered a GL zone
Definition: zone.hxx:40
Create this to not only enter the zone, but set VCL context.
Definition: zone.hxx:61
OpenGLZone()
Definition: zone.hxx:53
static bool isInZone()
Definition: zone.hxx:55
static void enter()
Definition: zone.hxx:50
We want to be able to detect if a given crash came from the OpenGL code, so use this helper to track ...
Definition: zone.hxx:27
static void leave()
Definition: zone.hxx:51
~OpenGLZone()
Definition: zone.hxx:54
std::atomic< std::make_unsigned_t< std::sig_atomic_t >> AtomicCounter
Definition: zone.hxx:39
static AtomicCounter gnLeaveCount
how many times have we left a new GL zone
Definition: zone.hxx:48