proxygen
HazptrRec.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-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 
19 
21 
22 #include <atomic>
23 
24 namespace folly {
25 
31 template <template <typename> class Atom>
32 class alignas(hardware_destructive_interference_size) hazptr_rec {
33  Atom<const void*> hazptr_{nullptr}; // the hazard pointer
36  Atom<bool> active_{false};
37 
38  friend class hazptr_domain<Atom>;
39  friend class hazptr_holder<Atom>;
40  friend class hazptr_tc_entry<Atom>;
41 
42  const void* hazptr() const noexcept {
43  return hazptr_.load(std::memory_order_acquire);
44  }
45 
46  FOLLY_ALWAYS_INLINE void reset_hazptr(const void* p = nullptr) noexcept {
47  hazptr_.store(p, std::memory_order_release);
48  }
49 
51  return active_.load(std::memory_order_acquire);
52  }
53 
55  active_.store(true, std::memory_order_relaxed);
56  }
57 
59  bool a = active();
60  return !a &&
61  active_.compare_exchange_strong(
62  a, true, std::memory_order_release, std::memory_order_relaxed);
63  }
64 
65  void release() noexcept {
66  active_.store(false, std::memory_order_release);
67  }
68 
70  return next_;
71  }
72 
74  next_ = rec;
75  }
76 
78  return domain_;
79  }
80 
82  domain_ = dom;
83  }
84 }; // hazptr_rec
85 
86 } // namespace folly
#define FOLLY_ALWAYS_INLINE
Definition: CPortability.h:151
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
requires E e noexcept(noexcept(s.error(std::move(e))))
void set_domain(hazptr_domain< Atom > *dom)
Definition: HazptrRec.h:81
const void * hazptr() const noexcept
Definition: HazptrRec.h:42
void set_next(hazptr_rec< Atom > *rec)
Definition: HazptrRec.h:73
hazptr_domain< Atom > * domain_
Definition: HazptrRec.h:34
#define Atom
void release() noexcept
Definition: HazptrRec.h:65
char a
FOLLY_ALWAYS_INLINE hazptr_domain< Atom > * domain()
Definition: HazptrRec.h:77
hazptr_rec * next_
Definition: HazptrRec.h:35
Definition: Hazptr-fwd.h:95
const
Definition: upload.py:398
FOLLY_ALWAYS_INLINE void reset_hazptr(const void *p=nullptr) noexcept
Definition: HazptrRec.h:46
bool try_acquire() noexcept
Definition: HazptrRec.h:58
bool active() const noexcept
Definition: HazptrRec.h:50
hazptr_rec< Atom > * next()
Definition: HazptrRec.h:69
void set_active() noexcept
Definition: HazptrRec.h:54