Prepare for firstGeq to be safe on foreign threads

This commit is contained in:
2024-05-03 16:17:06 -07:00
parent 99760176a6
commit 971aabea6e
5 changed files with 281 additions and 98 deletions

46
RootSet.h Normal file
View File

@@ -0,0 +1,46 @@
#pragma once
#include <atomic>
#include <memory>
#include <stdint.h>
struct RootSet {
/// Register the root node for version after adding mutations
void add(uint32_t node, int64_t version);
/// Inform that there will be no calls to rootForVersion with a version less
/// than `oldestVersion`
void setOldestVersion(int64_t oldestVersion);
/// Foreign threads may freely interact with a `ThreadSafeHandle`, as long as
/// the latest version as of obtaining the handle is greater than
/// `oldestVersion`.
struct ThreadSafeHandle {
/// Get a root node that can correctly be used for `version`
uint32_t rootForVersion(int64_t version) const;
/// @private
struct Impl;
private:
Impl *impl; // not owned
};
/// Safe to call from foreign threads
ThreadSafeHandle getThreadSafeHandle() const;
const uint32_t *roots() const;
int rootCount() const;
RootSet();
~RootSet();
/// @private
struct Impl;
private:
Impl *impl;
};