Templatize direction for move

This commit is contained in:
2024-05-23 18:26:26 -07:00
parent b5dbf4a049
commit 021569f033

View File

@@ -459,18 +459,18 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
// The last node is allowed to be 0, in which case this is the search path of
// where an entry would exist
template <std::memory_order kOrder>
void move(Finger &finger, int64_t at, bool direction) const {
template <std::memory_order kOrder, bool kDirection>
void move(Finger &finger, int64_t at) const {
uint32_t c;
if (finger.backNode() != 0 &&
(c = child<kOrder>(finger.backNode(), direction, at)) != 0) {
finger.push(c, direction);
while ((c = child<kOrder>(finger.backNode(), !direction, at)) != 0) {
finger.push(c, !direction);
(c = child<kOrder>(finger.backNode(), kDirection, at)) != 0) {
finger.push(c, kDirection);
while ((c = child<kOrder>(finger.backNode(), !kDirection, at)) != 0) {
finger.push(c, !kDirection);
}
} else {
while (finger.searchPathSize() > 1 &&
finger.backDirection() == direction) {
finger.backDirection() == kDirection) {
finger.pop();
}
finger.pop();
@@ -639,7 +639,7 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
if (inserted) {
Finger copy;
finger.copyTo(copy);
move<std::memory_order_relaxed>(copy, latestVersion, true);
move<std::memory_order_relaxed, true>(copy, latestVersion);
if (copy.searchPathSize() == 0) {
rangeVersion = -1; // Sentinel for "no mutation ending here"
} else {
@@ -655,7 +655,7 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
val = {nullptr, -1}; // Sentinel for "no point mutation here"
Finger copy;
finger.copyTo(copy);
move<std::memory_order_relaxed>(copy, latestVersion, true);
move<std::memory_order_relaxed, true>(copy, latestVersion);
if (copy.searchPathSize() == 0) {
pointVersion = -1; // Sentinel for "no mutation ending here"
} else {
@@ -801,7 +801,7 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
} else {
search<std::memory_order_relaxed>(continueKey, latestRoot, latestVersion,
finger);
move<std::memory_order_relaxed>(finger, latestVersion, true);
move<std::memory_order_relaxed, true>(finger, latestVersion);
if (finger.searchPathSize() == 0) {
continueKey = {nullptr, 0};
return;
@@ -810,7 +810,7 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
assert(finger.backNode() != 0);
int64_t rangeVersion = mm.base[finger.backNode()].entry->rangeVersion;
move<std::memory_order_relaxed>(finger, latestVersion, false);
move<std::memory_order_relaxed, false>(finger, latestVersion);
if (finger.searchPathSize() == 0) {
continueKey = {nullptr, 0};
return;
@@ -829,7 +829,7 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
} else {
rangeVersion = n.entry->rangeVersion;
}
move<std::memory_order_relaxed>(finger, latestVersion, false);
move<std::memory_order_relaxed, false>(finger, latestVersion);
if (finger.searchPathSize() == 0) {
continueKey = {nullptr, 0};
return;
@@ -866,11 +866,11 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
Finger iter;
search<std::memory_order_relaxed>({m.param1, m.param1Len}, latestRoot,
latestVersion, iter);
move<std::memory_order_relaxed>(iter, latestVersion, true);
move<std::memory_order_relaxed, true>(iter, latestVersion);
while (iter.searchPathSize() > 0 &&
mm.base[iter.backNode()] < Key{m.param2, m.param2Len}) {
remove(iter);
move<std::memory_order_relaxed>(iter, latestVersion, true);
move<std::memory_order_relaxed, true>(iter, latestVersion);
}
insert({m.param2, m.param2Len}, {});
}
@@ -1023,7 +1023,7 @@ void materializeMutations(VersionedMap::Iterator::Impl *impl, const Entry *prev,
if (prev == nullptr) {
Finger copy;
impl->finger.copyTo(copy);
impl->map->move<std::memory_order_acquire>(copy, impl->version, false);
impl->map->move<std::memory_order_acquire, false>(copy, impl->version);
if (copy.searchPathSize() > 0) {
prev = impl->map->mm.base[copy.backNode()].entry;
} else {
@@ -1033,7 +1033,7 @@ void materializeMutations(VersionedMap::Iterator::Impl *impl, const Entry *prev,
if (next == nullptr) {
Finger copy;
impl->finger.copyTo(copy);
impl->map->move<std::memory_order_acquire>(copy, impl->version, true);
impl->map->move<std::memory_order_acquire, true>(copy, impl->version);
if (copy.searchPathSize() > 0) {
next = impl->map->mm.base[copy.backNode()].entry;
}
@@ -1078,8 +1078,8 @@ VersionedMap::Iterator &VersionedMap::Iterator::operator++() {
do {
const auto &entry = *impl->map->mm.base[impl->finger.backNode()].entry;
impl->map->move<std::memory_order_acquire>(impl->finger, impl->version,
true);
impl->map->move<std::memory_order_acquire, true>(impl->finger,
impl->version);
if (impl->finger.searchPathSize() > 0) {
materializeMutations(impl, &entry, nullptr);
}
@@ -1123,8 +1123,8 @@ VersionedMap::Iterator &VersionedMap::Iterator::operator--() {
break;
}
next = impl->map->mm.base[impl->finger.backNode()].entry;
impl->map->move<std::memory_order_acquire>(impl->finger, impl->version,
false);
impl->map->move<std::memory_order_acquire, false>(impl->finger,
impl->version);
}
impl->mutationIndex = impl->mutationCount - 1;
return *this;
@@ -1132,8 +1132,8 @@ VersionedMap::Iterator &VersionedMap::Iterator::operator--() {
do {
const Entry *entry = impl->map->mm.base[impl->finger.backNode()].entry;
impl->map->move<std::memory_order_acquire>(impl->finger, impl->version,
false);
impl->map->move<std::memory_order_acquire, false>(impl->finger,
impl->version);
if (impl->finger.searchPathSize() > 0) {
materializeMutations(impl, nullptr, entry);
}
@@ -1182,7 +1182,7 @@ void VersionedMap::Impl::firstGeq(const Key *key, const int64_t *version,
exact = false;
} else if (finger.backNode() == 0) {
exact = false;
move<std::memory_order_acquire>(finger, version[i], true);
move<std::memory_order_acquire, true>(finger, version[i]);
if (finger.searchPathSize() > 0) {
assert(finger.backNode() != 0);
}
@@ -1204,8 +1204,8 @@ void VersionedMap::Impl::firstGeq(const Key *key, const int64_t *version,
break;
}
prev = iterator[i].impl->map->mm.base[finger.backNode()].entry;
iterator[i].impl->map->move<std::memory_order_acquire>(
finger, iterator[i].impl->version, true);
iterator[i].impl->map->move<std::memory_order_acquire, true>(
finger, iterator[i].impl->version);
}
if (exact) {
iterator[i].impl->mutationIndex = iterator[i].impl->mutationCount - 1;
@@ -1257,8 +1257,8 @@ VersionedMap::Iterator VersionedMap::begin(int64_t version) const {
break;
}
prev = result.impl->map->mm.base[result.impl->finger.backNode()].entry;
result.impl->map->move<std::memory_order_acquire>(
result.impl->finger, result.impl->version, true);
result.impl->map->move<std::memory_order_acquire, true>(
result.impl->finger, result.impl->version);
}
result.impl->mutationIndex = 0;