#pragma once
#include <atomic>
#include <thread>
struct Atomic_Wait_Mutex {
    void lock() noexcept {
        while (locked.test_and_set(std::memory_order_acquire)) {
            locked.wait(true, std::memory_order_relaxed);
        }
    }
    void unlock() noexcept {
        locked.clear(std::memory_order_release);
        locked.notify_one();
    }
private:
    std::atomic_flag locked = ATOMIC_FLAG_INIT;
};
struct Atomic_Spin_Mutex {
    void lock() noexcept {
        while (locked.test_and_set(std::memory_order_acquire)) {
            while (locked.test(std::memory_order_relaxed)) {
                std::this_thread::yield();
            }
        }
    }
    void unlock() noexcept {
        locked.clear(std::memory_order_release);
    }
private:
    std::atomic_flag locked = ATOMIC_FLAG_INIT;
};
