diff options
author | Tor Egge <Tor.Egge@online.no> | 2021-12-07 13:02:54 +0100 |
---|---|---|
committer | Tor Egge <Tor.Egge@online.no> | 2021-12-07 13:02:54 +0100 |
commit | 3a8d4a8308020093b498fa76aab3646793d4b6d6 (patch) | |
tree | 26830c306e176cfd1d7106e875448d4084a0cb9a /vespalib | |
parent | c4e8803732694d6cd0b2521273d8c83c12938f46 (diff) |
Ensure that replacement vector is visible for readers
before swapping it with existing vector.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/rcuvector.hpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/util/rcuvector.hpp b/vespalib/src/vespa/vespalib/util/rcuvector.hpp index 65844ac9802..3c455149dfd 100644 --- a/vespalib/src/vespa/vespalib/util/rcuvector.hpp +++ b/vespalib/src/vespa/vespalib/util/rcuvector.hpp @@ -63,6 +63,7 @@ RcuVectorBase<T>::expand(size_t newCapacity) { template <typename T> void RcuVectorBase<T>::replaceVector(ArrayType replacement) { + std::atomic_thread_fence(std::memory_order_release); replacement.swap(_data); // atomic switch of underlying data size_t holdSize = replacement.capacity() * sizeof(T); auto hold = std::make_unique<RcuVectorHeld<ArrayType>>(holdSize, std::move(replacement)); @@ -96,6 +97,7 @@ RcuVectorBase<T>::shrink(size_t newSize) for (uint32_t i = 0; i < newSize; ++i) { tmpData[i] = _data[i]; } + std::atomic_thread_fence(std::memory_order_release); // Users of RCU vector must ensure that no readers use old size // after swap. Attribute vectors uses _committedDocIdLimit for this. tmpData.swap(_data); // atomic switch of underlying data |