aboutsummaryrefslogtreecommitdiffstats
path: root/staging_vespalib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-11-14 18:39:51 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-11-14 18:39:51 +0000
commit58b3df5810c5f8f8d883ff08071c37b153da82c0 (patch)
treee14bbc9a2f6e753d7e39974e11652ff4d611992f /staging_vespalib
parentd6c99a96fc8d3d2ced331998a81a26beb6acc825 (diff)
If we lost the race for the last spots we need to use the second option.
Diffstat (limited to 'staging_vespalib')
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/sequencedtaskexecutor.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/util/sequencedtaskexecutor.cpp b/staging_vespalib/src/vespa/vespalib/util/sequencedtaskexecutor.cpp
index 685f670b164..f6bee62de33 100644
--- a/staging_vespalib/src/vespa/vespalib/util/sequencedtaskexecutor.cpp
+++ b/staging_vespalib/src/vespa/vespalib/util/sequencedtaskexecutor.cpp
@@ -127,11 +127,17 @@ SequencedTaskExecutor::getExecutorId(uint64_t componentId) const {
ISequencedTaskExecutor::ExecutorId
SequencedTaskExecutor::getExecutorIdPerfect(uint64_t componentId) const {
PerfectKeyT key = componentId;
- std::lock_guard guard(_mutex);
+ std::unique_lock guard(_mutex);
auto found = std::find(_component2IdPerfect.begin(), _component2IdPerfect.end(), key);
if (found == _component2IdPerfect.end()) {
- _component2IdPerfect.push_back(key);
- found = _component2IdPerfect.end() - 1;
+ if ((_component2IdPerfect.size() < _component2IdPerfect.capacity())) {
+ _component2IdPerfect.push_back(key);
+ found = _component2IdPerfect.end() - 1;
+ } else {
+ // There was a race for the last spots
+ guard.unlock();
+ return getExecutorIdImPerfect(componentId);
+ }
}
return ExecutorId((found - _component2IdPerfect.begin()) % getNumExecutors());
}