diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2019-01-16 05:58:48 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2019-01-16 07:49:13 +0100 |
commit | 03d28dde1635e36508cff1f9eabc265cdb5febb9 (patch) | |
tree | ee62d5851315c7b4c2c3c05f8a72e29a6dd4a1e8 /compat | |
parent | f8faca0abecafd6e65d07bd0fdd618070114cdfa (diff) |
compat/mutex: remove
Always use the adaptive QMutex.
Diffstat (limited to 'compat')
-rw-r--r-- | compat/check-visible.cpp | 11 | ||||
-rw-r--r-- | compat/spinlock.hpp | 31 |
2 files changed, 5 insertions, 37 deletions
diff --git a/compat/check-visible.cpp b/compat/check-visible.cpp index 2772c9ae..1212ab90 100644 --- a/compat/check-visible.cpp +++ b/compat/check-visible.cpp @@ -1,11 +1,10 @@ #include "check-visible.hpp" +#include <QMutex> #include <QWidget> #include <QDebug> -#include "spinlock.hpp" - -static std::atomic_flag lock = ATOMIC_FLAG_INIT; +static QMutex lock; static bool visible = true; #if defined _WIN32 @@ -22,7 +21,7 @@ constexpr int invisible_timeout = 250; void set_is_visible(const QWidget& w, bool force) { - spinlock_guard l(lock); + QMutexLocker l(&lock); if (w.isHidden() || w.windowState() & Qt::WindowMinimized) { @@ -78,12 +77,12 @@ void set_is_visible(const QWidget& w, bool) bool check_is_visible() { - spinlock_guard l(lock); + QMutexLocker l(&lock); return visible; } void force_is_visible(bool value) { - spinlock_guard l(lock); + QMutexLocker l(&lock); visible = value; } diff --git a/compat/spinlock.hpp b/compat/spinlock.hpp deleted file mode 100644 index b94df7c8..00000000 --- a/compat/spinlock.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include "export.hpp" -#include "macros1.h" -#include <atomic> - -struct OTR_COMPAT_EXPORT spinlock_guard final -{ - spinlock_guard(const spinlock_guard&) = delete; - spinlock_guard& operator=(const spinlock_guard&) = delete; - constexpr spinlock_guard(spinlock_guard&&) noexcept = default; - - cc_forceinline - spinlock_guard(std::atomic_flag* lock) noexcept : spinlock_guard(*lock) {} - - cc_forceinline - spinlock_guard(std::atomic_flag& lock) noexcept : lock(lock) - { - while (lock.test_and_set(std::memory_order_acquire)) - (void)0; - } - - cc_forceinline - ~spinlock_guard() noexcept - { - lock.clear(std::memory_order_release); - } - -private: - std::atomic_flag& lock; -}; |