Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "atomic.hpp"
- #include <twist/ed/wait/spin.hpp>
- // Naive Test-and-Set (TAS) spinlock
- class TASSpinLock {
- public:
- void Lock() {
- while (locked_.Exchange(1) == 1) {
- twist::ed::CpuRelax();
- }
- }
- bool TryLock() {
- return (locked_.Exchange(1) == 0);
- }
- void Unlock() {
- locked_.Store(0);
- }
- private:
- stdlike::Atomic locked_{0};
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement