summaryrefslogtreecommitdiff
path: root/core/spin_lock.h
blob: 07f865d91a6e8ed863dca98156be67ed9a2ae556 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef SPIN_LOCK_H
#define SPIN_LOCK_H

#include "core/typedefs.h"
#include <atomic>

class SpinLock {
	std::atomic_flag locked = ATOMIC_FLAG_INIT;

public:
	_ALWAYS_INLINE_ void lock() {
		while (locked.test_and_set(std::memory_order_acquire)) {
			;
		}
	}
	_ALWAYS_INLINE_ void unlock() {
		locked.clear(std::memory_order_release);
	}
};
#endif // SPIN_LOCK_H