Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <atomic.hpp>
- #include "futex_like.hpp"
- namespace tpcc {
- namespace solutions {
- class AdaptiveLock {
- public:
- AdaptiveLock() {
- state_.store(false);
- tpcc::atomic <bool> tmp;
- tmp.store(false);
- futex_ = new FutexLike<bool> (tmp);
- }
- ~AdaptiveLock() {
- delete futex_;
- }
- void Lock() {
- while (state_.exchange(true)) {
- futex_->Wait(false);
- }
- }
- void Unlock() {
- state_.store(false);
- futex_->WakeOne();
- }
- private:
- tpcc::atomic<bool> state_;
- FutexLike<bool> *futex_;
- };
- } // namespace solutions
- } // namespace tpcc
Advertisement
Add Comment
Please, Sign In to add comment