diff options
author | Arne Juul <arnej@verizonmedia.com> | 2021-01-04 10:43:38 +0000 |
---|---|---|
committer | Arne Juul <arnej@verizonmedia.com> | 2021-01-04 10:43:38 +0000 |
commit | 8c9ed3d5c8ae492581927cd8a9461983be09dff5 (patch) | |
tree | cb26c6b7ca37bd0397a5f9ee9be2cbeecaca106e | |
parent | 1c4d7f8105ec86df94bb435b9a31801b0ed921fa (diff) |
avoid infinite loop
* try all possible buffer ids, if none are free abort().
This instead of spinning in an infinite loop.
-rw-r--r-- | vespalib/src/vespa/vespalib/datastore/datastorebase.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp b/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp index 15135af67b5..ac6252bf514 100644 --- a/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp +++ b/vespalib/src/vespa/vespalib/datastore/datastorebase.cpp @@ -101,10 +101,17 @@ void DataStoreBase::switchActiveBuffer(uint32_t typeId, size_t elemsNeeded) { size_t activeBufferId = _activeBufferIds[typeId]; - do { + for (size_t i = 0; i < getNumBuffers(); ++i) { // start using next buffer activeBufferId = nextBufferId(activeBufferId); - } while (!_states[activeBufferId].isFree()); + if (_states[activeBufferId].isFree()) { + break; + } + } + if (!_states[activeBufferId].isFree()) { + LOG(error, "did not find free buffer"); + abort(); + } onActive(activeBufferId, typeId, elemsNeeded); _activeBufferIds[typeId] = activeBufferId; } @@ -131,10 +138,14 @@ DataStoreBase::initActiveBuffers() uint32_t numTypes = _activeBufferIds.size(); for (uint32_t typeId = 0; typeId < numTypes; ++typeId) { size_t activeBufferId = 0; - while (!_states[activeBufferId].isFree()) { + for (size_t i = 0; i < getNumBuffers(); ++i) { + if (_states[activeBufferId].isFree()) { + break; + } // start using next buffer activeBufferId = nextBufferId(activeBufferId); } + assert(_states[activeBufferId].isFree()); onActive(activeBufferId, typeId, 0u); _activeBufferIds[typeId] = activeBufferId; } |