Loading...
Searching...
No Matches
hash_set.h
Go to the documentation of this file.
1
/*
2
* Licensed to the Apache Software Foundation (ASF) under one
3
* or more contributor license agreements. See the NOTICE file
4
* distributed with this work for additional information
5
* regarding copyright ownership. The ASF licenses this file
6
* to you under the Apache License, Version 2.0 (the
7
* "License"); you may not use this file except in compliance
8
* with the License. You may obtain a copy of the License at
9
*
10
* http://www.apache.org/licenses/LICENSE-2.0
11
*
12
* Unless required by applicable law or agreed to in writing,
13
* software distributed under the License is distributed on an
14
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
* KIND, either express or implied. See the License for the
16
* specific language governing permissions and limitations
17
* under the License.
18
*/
19
20
#pragma once
21
22
#include <iostream>
23
#include <mutex>
24
#include <set>
25
26
namespace
resdb
{
27
28
template
<
class
_type>
29
class
SpinLockSet
{
30
public
:
31
SpinLockSet
(){};
32
~SpinLockSet
() { set_.clear(); }
33
34
int
exists
(_type key) {
35
bool
result =
false
;
36
lock_.lock();
37
result = set_.count(key);
38
lock_.unlock();
39
return
result;
40
}
41
void
add
(_type key) {
42
lock_.lock();
43
set_.insert(key);
44
lock_.unlock();
45
};
46
int
check_and_add
(_type key) {
47
bool
result =
false
;
48
lock_.lock();
49
result = set_.count(key);
50
set_.insert(key);
51
lock_.unlock();
52
return
result;
53
}
54
int
remove
(_type key) {
55
lock_.lock();
56
57
int
result = set_.erase(key);
58
59
lock_.unlock();
60
return
result;
61
}
62
63
int
size
() {
return
set_.size(); }
64
65
private
:
66
std::set<_type> set_;
67
std::mutex lock_;
68
};
69
70
}
// namespace resdb
resdb::SpinLockSet
Definition
hash_set.h:29
resdb::SpinLockSet::exists
int exists(_type key)
Definition
hash_set.h:34
resdb::SpinLockSet::size
int size()
Definition
hash_set.h:63
resdb::SpinLockSet::SpinLockSet
SpinLockSet()
Definition
hash_set.h:31
resdb::SpinLockSet::check_and_add
int check_and_add(_type key)
Definition
hash_set.h:46
resdb::SpinLockSet::remove
int remove(_type key)
Definition
hash_set.h:54
resdb::SpinLockSet::~SpinLockSet
~SpinLockSet()
Definition
hash_set.h:32
resdb::SpinLockSet::add
void add(_type key)
Definition
hash_set.h:41
resdb
Definition
chain_state.cpp:24
platform
consensus
ordering
geo_pbft
hash_set.h
Generated by
1.9.8