summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2019-11-03 20:52:19 -0500
committerAshod Nakashian <ashnakash@gmail.com>2019-11-06 03:43:45 +0100
commit7a976488f08bbeeb5620639cd47ad63afb030aed (patch)
tree29b90fb8e4525ee4bac549b29df48133f296aa4a /common
parent887ecdb8d3e8301b67e249c88d8aab734c76fed1 (diff)
wsd: cleanup the global flag accessors
The following flags are affected: ShutdownRequestFlag TerminationFlag DumpGlobalState Since it's common to grep for all places that set or reset these global flags, it makes more sense to have explicit functions for each operation. Now we have set and reset accessors where appropriate and get is reserved for read-only access. This changes the getters to only return the boolean value of these flags rather than a reference to the atomic object, now that they are read-only. Also, a few Mobile-specific cases were folded either with other Mobile-specific sections, or they were now identical to the non-Mobile case and therefore deduplicated, making the code cleaner and more readable. Change-Id: Icc852aa43e86695d4e7d5962040a9b5086d9d08c Reviewed-on: https://gerrit.libreoffice.org/81978 Reviewed-by: Ashod Nakashian <ashnakash@gmail.com> Tested-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'common')
-rw-r--r--common/SigUtil.cpp42
-rw-r--r--common/SigUtil.hpp38
-rw-r--r--common/Unit.cpp2
3 files changed, 45 insertions, 37 deletions
diff --git a/common/SigUtil.cpp b/common/SigUtil.cpp
index 933ad7f3e..212d1382f 100644
--- a/common/SigUtil.cpp
+++ b/common/SigUtil.cpp
@@ -40,39 +40,49 @@
static std::atomic<bool> TerminationFlag(false);
static std::atomic<bool> DumpGlobalState(false);
+#if MOBILEAPP
+std::atomic<bool> MobileTerminationFlag(false);
+#else
+// Mobile defines its own, which is constexpr.
+static std::atomic<bool> ShutdownRequestFlag(false);
+#endif
+
namespace SigUtil
{
- std::atomic<bool>& getTerminationFlag()
+ bool getShutdownRequestFlag()
+ {
+ return ShutdownRequestFlag;
+ }
+
+ bool getTerminationFlag()
{
return TerminationFlag;
}
- std::atomic<bool>& getDumpGlobalState()
+
+ void setTerminationFlag()
{
- return DumpGlobalState;
+ TerminationFlag = true;
}
-}
#if MOBILEAPP
-std::atomic<bool> MobileTerminationFlag(false);
-namespace SigUtil
-{
- bool getShutdownRequestFlag()
+ void resetTerminationFlag()
{
- return ShutdownRequestFlag;
+ TerminationFlag = false;
}
-}
#endif
-#if !MOBILEAPP
-static std::atomic<bool> ShutdownRequestFlag(false);
-namespace SigUtil
-{
- std::atomic<bool>& getShutdownRequestFlag()
+ bool getDumpGlobalState()
{
- return ShutdownRequestFlag;
+ return DumpGlobalState;
+ }
+
+ void resetDumpGlobalState()
+ {
+ DumpGlobalState = false;
}
}
+#if !MOBILEAPP
std::mutex SigHandlerTrap;
namespace SigUtil
diff --git a/common/SigUtil.hpp b/common/SigUtil.hpp
index 723dd2e5e..caf8d531d 100644
--- a/common/SigUtil.hpp
+++ b/common/SigUtil.hpp
@@ -13,36 +13,34 @@
#include <atomic>
#include <mutex>
-#if !MOBILEAPP
-namespace SigUtil
-{
- /// Flag to commence clean shutdown
- std::atomic<bool>& getShutdownRequestFlag();
-}
-#else
+#if MOBILEAPP
static constexpr bool ShutdownRequestFlag(false);
-namespace SigUtil
-{
- /// Flag to commence clean shutdown
- bool getShutdownRequestFlag();
-}
+extern std::atomic<bool> MobileTerminationFlag;
#endif
namespace SigUtil
{
- /// Flag to stop pump loops.
- std::atomic<bool>& getTerminationFlag();
-
- /// Flag to dump internal state
- std::atomic<bool>& getDumpGlobalState();
-}
+ /// Get the flag used to commence clean shutdown.
+ /// requestShutdown() is used to set the flag.
+ bool getShutdownRequestFlag();
+ /// Get the flag to stop pump loops forcefully.
+ bool getTerminationFlag();
+ /// Set the flag to stop pump loops forcefully.
+ void setTerminationFlag();
#if MOBILEAPP
-extern std::atomic<bool> MobileTerminationFlag;
+ /// Reset the flag to stop pump loops forcefully.
+ /// Only necessary in Mobile.
+ void resetTerminationFlag();
#endif
-#if !MOBILEAPP
+ /// Get the flag to dump internal state.
+ bool getDumpGlobalState();
+ /// Reset the flag to dump internal state.
+ void resetDumpGlobalState();
+}
+#if !MOBILEAPP
namespace SigUtil
{
/// Mutex to trap signal handler, if any,
diff --git a/common/Unit.cpp b/common/Unit.cpp
index 1dbe09645..151a4505d 100644
--- a/common/Unit.cpp
+++ b/common/Unit.cpp
@@ -189,7 +189,7 @@ void UnitBase::exitTest(TestResult result)
_retValue = result == TestResult::Ok ?
Poco::Util::Application::EXIT_OK :
Poco::Util::Application::EXIT_SOFTWARE;
- SigUtil::getTerminationFlag() = true;
+ SigUtil::setTerminationFlag();
SocketPoll::wakeupWorld();
}