summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-12-20 18:23:14 +0100
committerStanislaw Halik <sthalik@misaki.pl>2018-12-24 19:31:24 +0100
commite81df263f4123a39fe6d4d50fb21f47dd242e796 (patch)
tree4b8cd13da31ac3fb3a2d2695b65595d7c5570439 /compat
parent2613beb8028ecac53548d311b27ff38559763f6c (diff)
remove const correctness violations
This is possibly related to a livelock where several threads do const removal in their respective code paths. Use the `mutable' specifier for the mutexes and spline's cached data. Now using the `mutable' specifier, get rid of <optional> in compat/mutex.
Diffstat (limited to 'compat')
-rw-r--r--compat/copyable-mutex.cpp22
-rw-r--r--compat/copyable-mutex.hpp14
2 files changed, 16 insertions, 20 deletions
diff --git a/compat/copyable-mutex.cpp b/compat/copyable-mutex.cpp
index dde84c83..17b5aa34 100644
--- a/compat/copyable-mutex.cpp
+++ b/compat/copyable-mutex.cpp
@@ -1,18 +1,19 @@
#include "copyable-mutex.hpp"
+#include <cstdlib>
-mutex& mutex::operator=(const mutex& datum)
+mutex& mutex::operator=(const mutex& rhs)
{
- inner.emplace(datum->isRecursive() ? QMutex::Recursive : QMutex::NonRecursive);
+ if (rhs->isRecursive() != inner.isRecursive())
+ std::abort();
+
return *this;
}
-mutex::mutex(const mutex& datum)
+mutex::mutex(const mutex& datum) : mutex{datum.inner.isRecursive() ? Recursive : NonRecursive}
{
- *this = datum;
}
-mutex::mutex(mutex::mode m) :
- inner { std::in_place, static_cast<QMutex::RecursionMode>(int(m)) }
+mutex::mutex(RecursionMode m) : inner{m}
{
}
@@ -21,13 +22,12 @@ QMutex* mutex::operator&() const
return *this;
}
-QMutex* mutex::operator->() const
+mutex::operator QMutex*() const
{
- return *this;
+ return &inner;
}
-mutex::operator QMutex*() const
+QMutex* mutex::operator->() const
{
- return const_cast<QMutex*>(&inner.value());
+ return *this;
}
-
diff --git a/compat/copyable-mutex.hpp b/compat/copyable-mutex.hpp
index 46c6c88c..37e6802b 100644
--- a/compat/copyable-mutex.hpp
+++ b/compat/copyable-mutex.hpp
@@ -1,25 +1,21 @@
#pragma once
-#include <optional>
-
#include <QMutex>
#include "export.hpp"
class OTR_COMPAT_EXPORT mutex
{
- std::optional<QMutex> inner;
+ mutable QMutex inner;
public:
- enum mode
- {
- recursive = QMutex::Recursive,
- normal = QMutex::NonRecursive,
- };
+ using RecursionMode = QMutex::RecursionMode;
+ static constexpr inline RecursionMode Recursive = RecursionMode::Recursive;
+ static constexpr inline RecursionMode NonRecursive = RecursionMode::NonRecursive;
mutex& operator=(const mutex& datum);
mutex(const mutex& datum);
- explicit mutex(mode m = normal);
+ explicit mutex(RecursionMode m);
QMutex* operator&() const;
operator QMutex*() const;