aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@online.no>2022-04-27 11:43:21 +0200
committerTor Egge <Tor.Egge@online.no>2022-04-27 11:43:21 +0200
commit25bc334bc148e2926565316468e4335a056aa75d (patch)
tree7fcb588d3912dad4b9502d01a0d204162746d160
parent240f59cb04b7b8a1cf20bae584efb7f3be329acf (diff)
Use relaxed atomic in SequencedTaskExecutor when mapping to ExecutorId.
-rw-r--r--staging_vespalib/src/vespa/vespalib/util/sequencedtaskexecutor.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/util/sequencedtaskexecutor.cpp b/staging_vespalib/src/vespa/vespalib/util/sequencedtaskexecutor.cpp
index 59ffad88d09..e12d2065d9f 100644
--- a/staging_vespalib/src/vespa/vespalib/util/sequencedtaskexecutor.cpp
+++ b/staging_vespalib/src/vespa/vespalib/util/sequencedtaskexecutor.cpp
@@ -3,6 +3,7 @@
#include "sequencedtaskexecutor.h"
#include "adaptive_sequenced_executor.h"
#include "singleexecutor.h"
+#include <vespa/vespalib/util/atomic.h>
#include <vespa/vespalib/util/threadstackexecutor.h>
#include <vespa/vespalib/util/blockingthreadstackexecutor.h>
#include <vespa/vespalib/util/size_literals.h>
@@ -31,8 +32,13 @@ isLazy(const std::vector<std::unique_ptr<vespalib::SyncableThreadExecutor>> & ex
ssize_t
find(uint16_t key, const uint16_t values[], size_t numValues) {
for (size_t i(0); i < numValues; i++) {
- if (key == values[i]) return i;
- if (INVALID_KEY == values[i]) return -1;
+ auto value = vespalib::atomic::load_ref_relaxed(values[i]);
+ if (key == value) {
+ return i;
+ }
+ if (INVALID_KEY == value) {
+ return -1;
+ }
}
return -1;
}
@@ -162,7 +168,7 @@ SequencedTaskExecutor::getExecutorIdPerfect(uint64_t componentId) const {
if (pos < 0) {
pos = find(INVALID_KEY, _component2IdPerfect.get(), getNumExecutors() * NUM_PERFECT_PER_EXECUTOR);
if (pos >= 0) {
- _component2IdPerfect[pos] = key;
+ vespalib::atomic::store_ref_relaxed(_component2IdPerfect[pos], key);
} else {
// There was a race for the last spots
return std::optional<ISequencedTaskExecutor::ExecutorId>();
@@ -175,11 +181,11 @@ SequencedTaskExecutor::getExecutorIdPerfect(uint64_t componentId) const {
ISequencedTaskExecutor::ExecutorId
SequencedTaskExecutor::getExecutorIdImPerfect(uint64_t componentId) const {
uint32_t shrunkId = componentId % _component2IdImperfect.size();
- uint8_t executorId = _component2IdImperfect[shrunkId];
+ uint8_t executorId = vespalib::atomic::load_ref_relaxed(_component2IdImperfect[shrunkId]);
if (executorId == MAGIC) {
std::lock_guard guard(_mutex);
- if (_component2IdImperfect[shrunkId] == MAGIC) {
- _component2IdImperfect[shrunkId] = _nextId % getNumExecutors();
+ if (vespalib::atomic::load_ref_relaxed(_component2IdImperfect[shrunkId]) == MAGIC) {
+ vespalib::atomic::store_ref_relaxed(_component2IdImperfect[shrunkId], _nextId % getNumExecutors());
_nextId++;
}
executorId = _component2IdImperfect[shrunkId];