diff options
Diffstat (limited to 'vespalib/src/vespa/vespalib/util/gencnt.h')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/gencnt.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/vespalib/src/vespa/vespalib/util/gencnt.h b/vespalib/src/vespa/vespalib/util/gencnt.h index 7bfc5a7e49b..cac868a8adb 100644 --- a/vespalib/src/vespa/vespalib/util/gencnt.h +++ b/vespalib/src/vespa/vespalib/util/gencnt.h @@ -2,6 +2,7 @@ #pragma once #include <cstdint> +#include <atomic> namespace vespalib { @@ -16,7 +17,7 @@ namespace vespalib { class GenCnt { private: - uint32_t _val; + std::atomic<uint32_t> _val; public: /** @@ -31,12 +32,12 @@ public: **/ GenCnt(uint32_t val) : _val(val) {} - GenCnt(const GenCnt &rhs) = default; + GenCnt(const GenCnt &rhs) : _val(rhs.getAsInt()) {} /** * @brief empty destructor **/ - ~GenCnt() {} + ~GenCnt() = default; /** * @brief Increase the generation count held by this object @@ -95,7 +96,7 @@ public: * * @return generation counter **/ - uint32_t getAsInt() const { return _val; } + uint32_t getAsInt() const { return _val.load(std::memory_order_relaxed); } /** * @brief Set the generation counter from an integer |