memgraph/src/utils/atomic.hpp
florijan c826fa6640 Fix recovery bug (transaction ID bumping)
Summary:
When performing recovery, ensure that the transaction ID in engine is
bumped to one after the max tx id seen in recovery.

Reviewers: dgleich

Reviewed By: dgleich

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1312
2018-03-23 10:09:04 +01:00

24 lines
625 B
C++

#pragma once
#include <atomic>
namespace utils {
/**
* Ensures that the given atomic is greater or equal to the given value. If it
* already satisfies that predicate, it's not modified.
*
* @param atomic - The atomic variable to ensure on.
* @param value - The minimal value the atomic must have after this call.
* @tparam TValue - Type of value.
*/
template <typename TValue>
void EnsureAtomicGe(std::atomic<TValue> &atomic, TValue value) {
while (true) {
auto current = atomic.load();
if (current >= value) break;
if (atomic.compare_exchange_weak(current, value)) break;
}
}
} // namespace utils