Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <atomic.hpp>
- #include <backoff.hpp>
- namespace tpcc {
- namespace solutions {
- class TicketLock {
- public:
- // don't change this method
- void Lock() {
- Backoff backoff{};
- while (locked.exchange(true)) {
- backoff();
- }
- }
- bool TryLock() {
- return !locked.exchange(true);
- }
- // don't change this method
- void Unlock() {
- locked.store(false);
- }
- private:
- atomic<bool> locked;
- };
- } // namespace solutions
- } // namespace tpcc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement