summaryrefslogtreecommitdiffhomepage
path: root/dinput/dinput.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-12-29 13:27:21 +0100
committerStanislaw Halik <sthalik@misaki.pl>2019-01-16 07:48:18 +0100
commite9bbb68829e972df2e458aa5beec0568d4737f02 (patch)
treeb305103d53214dcddb76c1f26738d334972b17d3 /dinput/dinput.cpp
parenta1a9a091093c9fb711a1665de9f4d46ae5c5ab67 (diff)
compat/spinlock: implement and use it
Diffstat (limited to 'dinput/dinput.cpp')
-rw-r--r--dinput/dinput.cpp17
1 files changed, 6 insertions, 11 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();
}
}