From db30e72069f9bdddda33b824c0e4a0fa3f6e51ce Mon Sep 17 00:00:00 2001 From: Dominik Gleich <dominik.gleich@memgraph.io> Date: Fri, 14 Apr 2017 16:56:27 +0200 Subject: [PATCH] Change back to seq_cst memory ordering. Summary: This probably made the sl_simulation test hang. We'll update it to this for now and see how it will behave in the future. Reviewers: buda Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D284 --- src/threading/sync/futex.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/threading/sync/futex.hpp b/src/threading/sync/futex.hpp index 648baa14f..4a73694a9 100644 --- a/src/threading/sync/futex.hpp +++ b/src/threading/sync/futex.hpp @@ -67,7 +67,7 @@ class Futex { bool try_lock() { // we took the lock if we stored the LOCKED state and previous // state was UNLOCKED - return mutex.state.locked.exchange(LOCKED, std::memory_order_acquire) == + return mutex.state.locked.exchange(LOCKED, std::memory_order_seq_cst) == UNLOCKED; } @@ -83,7 +83,7 @@ class Futex { // the lock is contended, go to sleep. when someone // wakes you up, try taking the lock again - while (mutex.all.exchange(LOCKED_CONTENDED, std::memory_order_acquire) & + while (mutex.all.exchange(LOCKED_CONTENDED, std::memory_order_seq_cst) & LOCKED) { // wait in the kernel for someone to wake us up when unlocking auto status = futex_wait(LOCKED_CONTENDED, timeout); @@ -99,26 +99,26 @@ class Futex { // if we're locked and uncontended, try to unlock the mutex before // it becomes contended - if (mutex.all.load(std::memory_order_acquire) == LOCKED && + if (mutex.all.load(std::memory_order_seq_cst) == LOCKED && mutex.all.compare_exchange_strong(state, UNLOCKED, - std::memory_order_release, - std::memory_order_relaxed)) + std::memory_order_seq_cst, + std::memory_order_seq_cst)) return; // we are contended, just release the lock - mutex.state.locked.store(UNLOCKED, std::memory_order_release); + mutex.state.locked.store(UNLOCKED, std::memory_order_seq_cst); // spin and hope someone takes a lock so we don't have to wake up // anyone because that's quite expensive for (size_t i = 0; i < UNLOCK_RETRIES; ++i) { // if someone took the lock, we're ok - if (is_locked(std::memory_order_acquire)) return; + if (is_locked(std::memory_order_seq_cst)) return; relax(); } // store that we are becoming uncontended - mutex.state.contended.store(UNCONTENDED, std::memory_order_release); + mutex.state.contended.store(UNCONTENDED, std::memory_order_seq_cst); // we need to wake someone up futex_wake(LOCKED);