aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2022-02-18 11:07:36 +0800
committerKunoiSayami <[email protected]>2022-02-18 11:07:36 +0800
commita66cea8f77aeafa8523d28ea63a159826cef38a3 (patch)
tree93424ea153d30901b1bee7d3194227782e97baa9
parentf83373a5486bf7cad48fbd662c7f7f9484e79a65 (diff)
feat(skiplist): Temporary use spin lock
Signed-off-by: KunoiSayami <[email protected]>
-rw-r--r--db/skiplist.cuh14
-rw-r--r--db/skiplist_test.cu7
2 files changed, 8 insertions, 13 deletions
diff --git a/db/skiplist.cuh b/db/skiplist.cuh
index 6f0cc6c..1fd7091 100644
--- a/db/skiplist.cuh
+++ b/db/skiplist.cuh
@@ -228,11 +228,10 @@ struct SkipList<Key, Comparator>::Node {
__device__ bool SetNextSafe(int n, Node *x) {
assert(n >= 0);
Node * origin = next_[n].load(cuda::memory_order_acquire);
- //assert(origin != x);
- if (origin == nullptr) {
- next_[n].store(x);
- x->NoBarrier_SetNext(n, origin);
- return true;
+ assert(origin != x);
+ if (origin == nullptr && next_[n].compare_exchange_weak(origin, x)) {
+ x->NoBarrier_SetNext(n, origin);
+ return true;
}
if (origin->key < x->key) {
return false;
@@ -414,7 +413,7 @@ __device__ SkipList<Key, Comparator>::SkipList(Comparator cmp, Arena* arena)
head_(NewNode(0 /* any key will do */, kMaxHeight)),
max_height_(1),
rnd_(0xdeadbeef),
- arena_lock_(),
+ arena_lock_(true),
find_lock_() {
for (int i = 0; i < kMaxHeight; i++) {
head_->SetNext(i, nullptr);
@@ -431,6 +430,8 @@ __device__ void SkipList<Key, Comparator>::Insert(const Key& key) {
// Our data structure does not allow duplicate insertion
assert(x == nullptr || !Equal(key, x->key));
+ // TODO: Remove spin lock in feature
+ this->find_lock_.lock();
int height = RandomHeight();
if (height > GetMaxHeight()) {
@@ -462,6 +463,7 @@ __device__ void SkipList<Key, Comparator>::Insert(const Key& key) {
/*x->NoBarrier_SetNext(i, prev[i]->NoBarrier_Next(i));
prev[i]->SetNext(i, x);*/
}
+ this->find_lock_.unlock();
}
template <typename Key, class Comparator>
diff --git a/db/skiplist_test.cu b/db/skiplist_test.cu
index d73e433..e5a1256 100644
--- a/db/skiplist_test.cu
+++ b/db/skiplist_test.cu
@@ -431,17 +431,10 @@ __global__ void testKeysIsEqualLists(SkipList<Key, Comparator> * skiplist, const
SkipList<Key, Comparator>::Iterator iter(skiplist);
iter.SeekToFirst();
- bool need_break = false;
- int break_after = 20;
for (unsigned i = 0; i < SKIPLIST_TEST_SIZE ; i++ ) {
assert(iter.Valid());
//printf("%d %lu %lu\n", i, iter.key(), sorted_keys[i]);
- if (iter.key() != sorted_keys[i]) {
- need_break = true;
- }
- if (need_break && !--break_after)
- break;
assert(iter.key() == sorted_keys[i]);
iter.Next();
}