diff options
author | Tor Egge <Tor.Egge@yahooinc.com> | 2022-05-03 13:47:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-03 13:47:04 +0200 |
commit | 5c0d5b342fe9cc62e407c2fd2767bac84ffc4ca6 (patch) | |
tree | 0e1d26104ec3286250691ed841f238cfb0279bc7 | |
parent | 6df8ce07fa74c7f05ebc8e505136df82476e141c (diff) | |
parent | 2d0a77e003cf0cdfaf619d62af90ba0fb0aac710 (diff) |
Merge pull request #22404 from vespa-engine/havardpe/atomic-size-and-test-bit
use atomic operations to propagate bits and bitvector size
4 files changed, 15 insertions, 9 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.h index e6327163aae..05795aee7d5 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lid_allocator.h @@ -68,7 +68,7 @@ public: return lid < _usedLids.size(); } bool validLid(DocId lid) const { - return (lid < _usedLids.size() && _usedLids.testBit(lid)); + return (lid < _usedLids.getSizeSafe() && _usedLids.testBit(lid)); } bool validLidSafe(DocId lid, uint32_t limit) const { return (lid < limit && _usedLids.testBitSafe(lid)); diff --git a/searchcore/src/vespa/searchcore/proton/documentmetastore/lidstatevector.h b/searchcore/src/vespa/searchcore/proton/documentmetastore/lidstatevector.h index 592ca23e63c..08bd93f063d 100644 --- a/searchcore/src/vespa/searchcore/proton/documentmetastore/lidstatevector.h +++ b/searchcore/src/vespa/searchcore/proton/documentmetastore/lidstatevector.h @@ -51,6 +51,7 @@ public: bool testBit(unsigned int idx) const { return _bv.testBit(idx); } bool testBitSafe(unsigned int idx) const { return _bv.testBitSafe(idx); } unsigned int size() const { return _bv.size(); } + unsigned int getSizeSafe() const { return _bv.getSizeSafe(); } unsigned int byteSize() const { return _bv.extraByteSize() + sizeof(LidStateVector); } diff --git a/searchlib/src/vespa/searchlib/common/bitvector.cpp b/searchlib/src/vespa/searchlib/common/bitvector.cpp index 7eef1e7f8f2..d5b21a38c3f 100644 --- a/searchlib/src/vespa/searchlib/common/bitvector.cpp +++ b/searchlib/src/vespa/searchlib/common/bitvector.cpp @@ -106,13 +106,13 @@ BitVector::clearIntervalNoInvalidation(Range range_in) Index endw = wordNum(last); if (endw > startw) { - vespalib::atomic::store_ref_relaxed(_words[startw], _words[startw] & startBits(range.start())); + store_word(startw, _words[startw] & startBits(range.start())); for (Index i = startw + 1; i < endw; ++i) { - vespalib::atomic::store_ref_relaxed(_words[i], 0); + store_word(i, 0); } - vespalib::atomic::store_ref_relaxed(_words[endw], _words[endw] & endBits(last)); + store_word(endw, _words[endw] & endBits(last)); } else { - vespalib::atomic::store_ref_relaxed(_words[startw], _words[startw] & (startBits(range.start()) | endBits(last))); + store_word(startw, _words[startw] & (startBits(range.start()) | endBits(last))); } } diff --git a/searchlib/src/vespa/searchlib/common/bitvector.h b/searchlib/src/vespa/searchlib/common/bitvector.h index 779e9887daf..02294cc1f1f 100644 --- a/searchlib/src/vespa/searchlib/common/bitvector.h +++ b/searchlib/src/vespa/searchlib/common/bitvector.h @@ -44,8 +44,13 @@ public: void * getStart() { return _words; } Index size() const { return _sz; } Index sizeBytes() const { return numBytes(getActiveSize()); } + Word load_word(Index widx) const { return vespalib::atomic::load_ref_relaxed(_words[widx]); } + void store_word(Index widx, Word word) { return vespalib::atomic::store_ref_relaxed(_words[widx], word); } bool testBit(Index idx) const { - return ((_words[wordNum(idx)] & mask(idx)) != 0); + return ((load_word(wordNum(idx)) & mask(idx)) != 0); + } + Index getSizeSafe() const { + return vespalib::atomic::load_ref_acquire(_sz); } bool testBitSafe(Index idx) const { auto my_words = vespalib::atomic::load_ref_acquire(_words); @@ -139,13 +144,13 @@ public: // Can only remove the old stopsign if it is ahead of the new. clearBit(_sz); } - _sz = sz; + vespalib::atomic::store_ref_release(_sz, sz); } void setBit(Index idx) { - vespalib::atomic::store_ref_relaxed(_words[wordNum(idx)], _words[wordNum(idx)] | mask(idx)); + store_word(wordNum(idx), _words[wordNum(idx)] | mask(idx)); } void clearBit(Index idx) { - vespalib::atomic::store_ref_relaxed(_words[wordNum(idx)], _words[wordNum(idx)] & ~ mask(idx)); + store_word(wordNum(idx), _words[wordNum(idx)] & ~ mask(idx)); } void flipBit(Index idx) { _words[wordNum(idx)] ^= mask(idx); |