Initialize version sooner in VersionedMap::begin
This commit is contained in:
@@ -262,62 +262,49 @@ struct MemManager {
|
||||
}
|
||||
|
||||
void gc(const uint32_t *roots, int numRoots, int64_t oldestVersion) {
|
||||
#if DEBUG_VERBOSE
|
||||
if (debugVerboseEnabled) {
|
||||
printf("GC roots:\n");
|
||||
for (int i = 0; i < numRoots; ++i) {
|
||||
printf(" %u\n", roots[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// Calculate reachable set
|
||||
BitSet reachable{next};
|
||||
// Each node has at most 3 children and nodes along the search path aren't
|
||||
// in the stack, so we need 2 * kPathLengthUpperBound
|
||||
uint32_t stack[2 * kPathLengthUpperBound];
|
||||
int stackIndex = 0;
|
||||
auto tryPush = [&](uint32_t p) {
|
||||
#if DEBUG_VERBOSE
|
||||
if (debugVerboseEnabled) {
|
||||
printf(" GC: visit: %u\n", p);
|
||||
}
|
||||
#endif
|
||||
if (!reachable.set(p)) {
|
||||
auto tryPush = [&](uint32_t parent, uint32_t child) {
|
||||
if (!reachable.set(child)) {
|
||||
#if DEBUG_VERBOSE
|
||||
if (debugVerboseEnabled) {
|
||||
printf(" GC: push on to stack: %u\n", p);
|
||||
printf(" GC: reach: %u (parent %u)\n", child, parent);
|
||||
}
|
||||
#endif
|
||||
assert(stackIndex < sizeof(stack) / sizeof(stack[0]));
|
||||
stack[stackIndex++] = p;
|
||||
stack[stackIndex++] = child;
|
||||
}
|
||||
};
|
||||
for (int i = 0; i < numRoots; ++i) {
|
||||
if (roots[i] == 0) {
|
||||
continue;
|
||||
}
|
||||
tryPush(roots[i]);
|
||||
tryPush(0, roots[i]);
|
||||
while (stackIndex > 0) {
|
||||
uint32_t p = stack[--stackIndex];
|
||||
auto &node = base[p];
|
||||
if (node.updated.load(std::memory_order_relaxed)) {
|
||||
if (node.pointer[!node.replacedPointer] != 0) {
|
||||
tryPush(node.pointer[!node.replacedPointer]);
|
||||
tryPush(p, node.pointer[!node.replacedPointer]);
|
||||
}
|
||||
if (oldestVersion < node.updateVersion) {
|
||||
if (node.pointer[node.replacedPointer] != 0) {
|
||||
tryPush(node.pointer[node.replacedPointer]);
|
||||
tryPush(p, node.pointer[node.replacedPointer]);
|
||||
}
|
||||
}
|
||||
if (node.pointer[2] != 0) {
|
||||
tryPush(node.pointer[2]);
|
||||
tryPush(p, node.pointer[2]);
|
||||
}
|
||||
} else {
|
||||
if (node.pointer[0] != 0) {
|
||||
tryPush(node.pointer[0]);
|
||||
tryPush(p, node.pointer[0]);
|
||||
}
|
||||
if (node.pointer[1] != 0) {
|
||||
tryPush(node.pointer[1]);
|
||||
tryPush(p, node.pointer[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -495,6 +482,11 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
|
||||
result = n.pointer[which];
|
||||
}
|
||||
assert(result == 0 || result >= kMinAddressable);
|
||||
#ifndef NDEBUG
|
||||
if (result != 0) {
|
||||
assert(mm.base[result].entry != nullptr);
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1174,6 +1166,7 @@ void VersionedMap::firstGeq(const Key *key, const int64_t *version,
|
||||
VersionedMap::Iterator VersionedMap::begin(int64_t version) const {
|
||||
VersionedMap::Iterator result;
|
||||
result.impl = new (safe_malloc(sizeof(Iterator::Impl))) Iterator::Impl();
|
||||
result.impl->version = version;
|
||||
|
||||
bool ignored;
|
||||
result.impl->finger.push(
|
||||
@@ -1205,7 +1198,6 @@ VersionedMap::Iterator VersionedMap::begin(int64_t version) const {
|
||||
}
|
||||
result.impl->mutationIndex = 0;
|
||||
|
||||
result.impl->version = version;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user