summaryrefslogtreecommitdiffhomepage
path: root/dinput
diff options
context:
space:
mode:
Diffstat (limited to 'dinput')
-rw-r--r--dinput/dinput.cpp17
-rw-r--r--dinput/dinput.hpp4
2 files changed, 8 insertions, 13 deletions
diff --git a/dinput/dinput.cpp b/dinput/dinput.cpp
index 3931255b..75f398ad 100644
--- a/dinput/dinput.cpp
+++ b/dinput/dinput.cpp
@@ -1,8 +1,9 @@
#include "dinput.hpp"
+#include "compat/spinlock.hpp"
#include <QDebug>
-std::atomic<int> di_t::refcnt;
-std::atomic_flag di_t::init_lock = ATOMIC_FLAG_INIT;
+int di_t::refcnt{0};
+std::atomic_flag di_t::lock = ATOMIC_FLAG_INIT;
diptr di_t::handle;
diptr di_t::init_di_()
@@ -32,30 +33,24 @@ di_t::di_t()
void di_t::ref_di()
{
- while (init_lock.test_and_set())
- (void)0;
+ spinlock_guard l(lock);
if (!handle)
handle = init_di_();
++refcnt;
-
- init_lock.clear();
}
void di_t::unref_di()
{
+ spinlock_guard l(lock);
+
const int refcnt_ = --refcnt;
if (refcnt_ == 0)
{
- while (init_lock.test_and_set())
- (void)0;
-
qDebug() << "exit: di handle";
handle->Release();
-
- init_lock.clear();
}
}
diff --git a/dinput/dinput.hpp b/dinput/dinput.hpp
index a9241504..7128229b 100644
--- a/dinput/dinput.hpp
+++ b/dinput/dinput.hpp
@@ -25,8 +25,8 @@ class OTR_DINPUT_EXPORT di_t final
static void ref_di();
static diptr handle;
- static std::atomic<int> refcnt;
- static std::atomic_flag init_lock;
+ static int refcnt;
+ static std::atomic_flag lock;
static diptr init_di_();
public: