1
0
mirror of https://github.com/google/leveldb.git synced 2025-04-15 13:20:37 +08:00

add barrier-free variant of find_greater_or_equal

This commit is contained in:
classhe 2020-07-12 14:50:35 +08:00
parent 5bd5f0f67a
commit 100b8f0405

View File

@ -117,7 +117,8 @@ class SkipList {
//
// If prev is non-null, fills prev[level] with pointer to previous
// node at "level" for every level in [0..max_height_-1].
Node* FindGreaterOrEqual(const Key& key, Node** prev) const;
Node* FindGreaterOrEqual(const Key& key, Node** prev,
bool barrier_free = false) const;
// Return the latest node with a key < key.
// Return head_ if there is no such node.
@ -259,12 +260,12 @@ bool SkipList<Key, Comparator>::KeyIsAfterNode(const Key& key, Node* n) const {
template <typename Key, class Comparator>
typename SkipList<Key, Comparator>::Node*
SkipList<Key, Comparator>::FindGreaterOrEqual(const Key& key,
Node** prev) const {
SkipList<Key, Comparator>::FindGreaterOrEqual(const Key& key, Node** prev,
bool barrier_free) const {
Node* x = head_;
int level = GetMaxHeight() - 1;
while (true) {
Node* next = x->Next(level);
Node* next = barrier_free ? x->NoBarrier_Next(level) : x->Next(level);
if (KeyIsAfterNode(key, next)) {
// Keep searching in this list
x = next;
@ -338,7 +339,7 @@ void SkipList<Key, Comparator>::Insert(const Key& key) {
// TODO(opt): We can use a barrier-free variant of FindGreaterOrEqual()
// here since Insert() is externally synchronized.
Node* prev[kMaxHeight];
Node* x = FindGreaterOrEqual(key, prev);
Node* x = FindGreaterOrEqual(key, prev, true);
// Our data structure does not allow duplicate insertion
assert(x == nullptr || !Equal(key, x->key));