aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-04-02 13:58:37 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-04-02 13:58:37 +0000
commit30b6bce74ee98480b72d4a23328c0b30c28b4566 (patch)
tree0fc88beb8a9bd669115d8024d256f1a784194292
parentcfac02f352328cdae0d78fa9d6320468ba9be658 (diff)
Improve thread visibility.
-rw-r--r--vespalib/src/vespa/vespalib/util/gencnt.cpp2
-rw-r--r--vespalib/src/vespa/vespalib/util/gencnt.h9
2 files changed, 6 insertions, 5 deletions
diff --git a/vespalib/src/vespa/vespalib/util/gencnt.cpp b/vespalib/src/vespa/vespalib/util/gencnt.cpp
index 5adbf14a757..ad82cf2e67c 100644
--- a/vespalib/src/vespa/vespalib/util/gencnt.cpp
+++ b/vespalib/src/vespa/vespalib/util/gencnt.cpp
@@ -58,7 +58,7 @@ GenCnt::distance(const GenCnt &other) const
GenCnt &
GenCnt::operator=(const GenCnt &src)
{
- _val = src._val;
+ _val = src.getAsInt();
return *this;
}
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