diff options
Diffstat (limited to 'dinput/dinput.cpp')
-rw-r--r-- | dinput/dinput.cpp | 17 |
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(); } } |