#ifndef PROTON_UTILITY_ATOMIC_H_ #define PROTON_UTILITY_ATOMIC_H_ #include #include namespace proton { template T atomicMax(std::atomic &target, T value) { T current = target.load(); while (current < value && !target.compare_exchange_weak(current, value)) ; return current; } template T atomicMin(std::atomic &target, T value) { T current = target.load(); while (current > value && !target.compare_exchange_weak(current, value)) ; return current; } template void doubleCheckedLock(Condition enterCondition, std::mutex &lock, Function function) { if (!enterCondition()) return; std::unique_lock guard(lock); if (!enterCondition()) return; function(); } } // namespace proton #endif // PROTON_UTILITY_ATOMIC_H_