summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2020-01-29 11:16:42 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2020-01-29 11:16:42 +0000
commit4d85e074df06fbce7439da2d7b876cc37846fe44 (patch)
tree8e4d5e9024db648e33900a4ea02b21f17242b3df /searchlib
parent6d8cf1e164fcbde23abf73334ec04b1ab057d48c (diff)
Ensure that we never end up with a seemingly valid bit count of 0.
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp10
-rw-r--r--searchlib/src/vespa/searchlib/common/bitvector.h7
2 files changed, 8 insertions, 9 deletions
diff --git a/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp b/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp
index 3de0c1f1320..08a3847f00d 100644
--- a/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp
+++ b/searchlib/src/vespa/searchlib/common/allocatedbitvector.cpp
@@ -52,6 +52,7 @@ AllocatedBitVector::AllocatedBitVector(Index numberOfElements, Index capacityBit
}
setBit(size()); // Guard bit
}
+ updateCount();
}
AllocatedBitVector::AllocatedBitVector(const AllocatedBitVector & rhs) :
@@ -70,6 +71,8 @@ AllocatedBitVector::AllocatedBitVector(const BitVector & rhs, Index capacity_) :
_capacityBits = computeCapacity(_capacityBits, _alloc.size());
memcpy(_alloc.get(), rhs.getStart(), rhs.sizeBytes());
init(_alloc.get(), 0, rhs.size());
+ setBit(size());
+ updateCount();
}
//////////////////////////////////////////////////////////////////////
@@ -121,12 +124,9 @@ AllocatedBitVector::grow(Index newSize, Index newCapacity)
if (newCapacity != capacity()) {
AllocatedBitVector tbv(newSize, newCapacity, _alloc.get(), size());
if (newSize > size()) {
- tbv.clearBit(size()); // Clear old guard bit.
- }
- ret.reset(new GenerationHeldAlloc<Alloc>(_alloc));
- if (( newSize >= size()) && isValidCount()) {
- tbv.setTrueBits(countTrueBits());
+ tbv.clearBitAndMaintainCount(size()); // Clear old guard bit.
}
+ ret = std::make_unique<GenerationHeldAlloc<Alloc>>(_alloc);
swap(tbv);
} else {
if (newSize > size()) {
diff --git a/searchlib/src/vespa/searchlib/common/bitvector.h b/searchlib/src/vespa/searchlib/common/bitvector.h
index 98e8c9adad3..9671e41df24 100644
--- a/searchlib/src/vespa/searchlib/common/bitvector.h
+++ b/searchlib/src/vespa/searchlib/common/bitvector.h
@@ -45,7 +45,7 @@ public:
}
Index countTrueBits() const {
if ( ! isValidCount()) {
- _numTrueBits.store(count(), std::memory_order_relaxed);
+ updateCount();
}
return _numTrueBits.load(std::memory_order_relaxed);
}
@@ -255,6 +255,7 @@ protected:
BitVector(void * buf, Index sz) : BitVector(buf, 0, sz) { }
BitVector() : BitVector(nullptr, 0) { }
void init(void * buf, Index start, Index end);
+ void updateCount() const { _numTrueBits.store(count(), std::memory_order_relaxed); }
void setTrueBits(Index numTrueBits) { _numTrueBits.store(numTrueBits, std::memory_order_relaxed); }
VESPA_DLL_LOCAL void clearIntervalNoInvalidation(Index start, Index end);
bool isValidCount() const { return isValidCount(_numTrueBits.load(std::memory_order_relaxed)); }
@@ -340,7 +341,7 @@ private:
func(start+pos);
start += pos + 1;
word >>= pos;
- word >>= 1;
+ word >>= 1u;
}
}
@@ -357,8 +358,6 @@ protected:
operator>>(vespalib::nbostream &in, BitVector &bv);
};
-typedef BitVector ConstBitVectorReference;
-
vespalib::nbostream &
operator<<(vespalib::nbostream &out, const BitVector &bv);