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