diff options
author | Juan Linietsky <reduzio@gmail.com> | 2019-07-29 12:59:18 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2020-02-11 11:53:29 +0100 |
commit | c613ead5fa2361296cf8d9a80d4648492ff4e16f (patch) | |
tree | 974356b6840ecf764415d43277ef78ad3c6b6373 /core/spin_lock.h | |
parent | 4fe3ee1730167b90ec8ae70c871c1dad032981d5 (diff) | |
download | redot-engine-c613ead5fa2361296cf8d9a80d4648492ff4e16f.tar.gz |
Added a spinlock template as well as a thread work pool class.
Also, optimized shader compilation to happen on threads.
Diffstat (limited to 'core/spin_lock.h')
-rw-r--r-- | core/spin_lock.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/core/spin_lock.h b/core/spin_lock.h new file mode 100644 index 0000000000..07f865d91a --- /dev/null +++ b/core/spin_lock.h @@ -0,0 +1,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 |