32 spinlock() {
new(buffer) std::atomic<bool>(
false); }
35 ~spinlock() { assert(!get().load()); get().~atomic<
bool>(); }
38 inline void lock() {
while (get().exchange(
true)) { } };
41 inline void unlock() { get().store(
false); }
43 inline bool try_lock() {
return !get().exchange(
true); }
47 void operator=(
const spinlock &) =
delete;
49 std::atomic<bool> &get() {
return *
reinterpret_cast<std::atomic<bool> *
>(buffer); }
51 char buffer[
sizeof(std::atomic<bool>)];
69 conditional_lock(T &t,
bool use) : lock_(&t), use_(use) {
if (use_) t.lock(); }
70 conditional_lock(T *t,
bool use) : lock_(t), use_(use) {
if (use_&&t) t->lock(); }
spinlock()
By default the QAtomicInt is 0 on creation.
Definition: spinlock.h:32
~spinlock()
A spinlock object can only be destroyed when it has been released.
Definition: spinlock.h:35
void unlock()
Release the lock.
Definition: spinlock.h:41
Definition: spinlock.h:79
Definition: spinlock.h:67
Definition: spinlock.h:29
#define BASE_EXPORT
Definition: basedef.h:21
Definition: spinlock.h:57
Base type definitions - if QT is not in use.
void lock()
Acquire a lock using the test-and-set paradigm.
Definition: spinlock.h:38