proxygen
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
HazptrWideCAS.h
Go to the documentation of this file.
1
/*
2
* Copyright 2016-present Facebook, Inc.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
#pragma once
17
18
#include <
folly/synchronization/Hazptr.h
>
19
20
#include <string>
21
22
namespace
folly
{
23
26
template
<
typename
T,
template
<
typename
>
class
Atom
= std::atomic>
27
class
HazptrWideCAS
{
28
struct
Node
:
public
hazptr_obj_base
<Node, Atom> {
29
T
val_
;
30
explicit
Node
(
T
v
= {}) :
val_
(
v
) {}
31
};
32
33
Atom<Node*>
node_
;
34
35
public
:
36
HazptrWideCAS
() : node_(new
Node
()) {}
37
38
~HazptrWideCAS
() {
39
delete
node_.load(std::memory_order_relaxed);
40
}
41
42
bool
cas
(
T
& u,
T
&
v
) {
43
Node
* n =
new
Node
(v);
44
hazptr_holder<Atom>
hptr;
45
Node
* p;
46
while
(
true
) {
47
p = hptr.
get_protected
(node_);
48
if
(p->
val_
!= u) {
49
delete
n;
50
return
false
;
51
}
52
if
(node_.compare_exchange_weak(
53
p, n, std::memory_order_relaxed, std::memory_order_release)) {
54
break
;
55
}
56
}
57
hptr.
reset
();
58
p->
retire
();
59
return
true
;
60
}
61
};
62
63
}
// namespace folly
folly::pushmi
Definition:
boosters.h:30
folly::HazptrWideCAS::Node
Definition:
HazptrWideCAS.h:28
folly::hazptr_holder::get_protected
FOLLY_ALWAYS_INLINE T * get_protected(const Atom< T * > &src) noexcept
Definition:
HazptrHolder.h:138
Hazptr.h
folly::hazptr_obj_base::retire
void retire(D deleter={}, hazptr_domain< Atom > &domain=default_hazptr_domain< Atom >())
Definition:
HazptrObj.h:229
folly::HazptrWideCAS::HazptrWideCAS
HazptrWideCAS()
Definition:
HazptrWideCAS.h:36
folly::T
folly::std T
folly::HazptrWideCAS
Definition:
HazptrWideCAS.h:27
folly
—— Concurrent Priority Queue Implementation ——
Definition:
AtomicBitSet.h:29
folly::HazptrWideCAS::cas
bool cas(T &u, T &v)
Definition:
HazptrWideCAS.h:42
Atom
#define Atom
Definition:
ConcurrentHashMapTest.cpp:301
folly::HazptrWideCAS::Node::val_
T val_
Definition:
HazptrWideCAS.h:29
folly::HazptrWideCAS::node_
Atom< Node * > node_
Definition:
HazptrWideCAS.h:33
folly::hazptr_holder::reset
FOLLY_ALWAYS_INLINE void reset(const T *ptr) noexcept
Definition:
HazptrHolder.h:153
folly::HazptrWideCAS::~HazptrWideCAS
~HazptrWideCAS()
Definition:
HazptrWideCAS.h:38
folly::HazptrWideCAS::Node::Node
Node(T v={})
Definition:
HazptrWideCAS.h:30
folly::hazptr_obj_base
Definition:
Hazptr-fwd.h:66
folly::hazptr_holder
Definition:
Hazptr-fwd.h:155
proxygen
folly
folly
synchronization
example
HazptrWideCAS.h
Generated by
1.8.11