5 #ifndef INCLUDE_CPPGC_MEMBER_H_
6 #define INCLUDE_CPPGC_MEMBER_H_
10 #include <type_traits>
12 #include "cppgc/internal/pointer-policies.h"
13 #include "cppgc/sentinel-pointer.h"
14 #include "cppgc/type-traits.h"
34 const void*
GetRaw()
const {
return raw_; }
35 void SetRaw(
void* value) { raw_ = value; }
38 return reinterpret_cast<
const std::atomic<
const void*>*>(&raw_)->load(
39 std::memory_order_relaxed);
42 reinterpret_cast<std::atomic<
const void*>*>(&raw_)->store(
43 value, std::memory_order_relaxed);
52 mutable const void* raw_;
56 template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
57 typename CheckingPolicy>
58 class BasicMember final :
private MemberBase,
private CheckingPolicy {
60 using PointeeType = T;
66 InitializingWriteBarrier();
67 this->CheckPointer(Get());
79 InitializingWriteBarrier();
80 this->CheckPointer(Get());
83 : BasicMember(&raw, atomic) {}
85 BasicMember(
const BasicMember& other) : BasicMember(other.Get()) {}
87 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
88 typename OtherCheckingPolicy,
89 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
91 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
92 OtherCheckingPolicy>& other)
93 : BasicMember(other.Get()) {}
95 BasicMember(BasicMember&& other)
noexcept : BasicMember(other.Get()) {
99 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
100 typename OtherCheckingPolicy,
101 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
103 OtherCheckingPolicy>&& other)
noexcept
104 : BasicMember(other.Get()) {
108 template <
typename U,
typename PersistentWeaknessPolicy,
109 typename PersistentLocationPolicy,
110 typename PersistentCheckingPolicy,
111 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
113 PersistentLocationPolicy,
114 PersistentCheckingPolicy>& p)
115 : BasicMember(p.Get()) {}
119 return operator=(other.Get());
122 template <
typename U,
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
123 typename OtherCheckingPolicy,
124 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
126 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
127 OtherCheckingPolicy>& other) {
128 return operator=(other.Get());
131 BasicMember&
operator=(BasicMember&& other)
noexcept {
132 operator=(other.Get());
137 template <
typename U,
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
138 typename OtherCheckingPolicy,
139 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
140 BasicMember&
operator=(BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
141 OtherCheckingPolicy>&& other)
noexcept {
142 operator=(other.Get());
147 template <
typename U,
typename PersistentWeaknessPolicy,
148 typename PersistentLocationPolicy,
149 typename PersistentCheckingPolicy,
150 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
153 PersistentLocationPolicy, PersistentCheckingPolicy>&
155 return operator=(other.Get());
159 AssigningWriteBarrier();
160 this->CheckPointer(Get());
172 template <
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
173 typename OtherCheckingPolicy>
174 void Swap(BasicMember<T, OtherWeaknessTag, OtherBarrierPolicy,
175 OtherCheckingPolicy>& other) {
211 const T* GetRawAtomic()
const {
215 void InitializingWriteBarrier()
const {
218 void AssigningWriteBarrier()
const {
224 T* GetFromGC()
const {
return Get(); }
227 template <
typename U>
231 template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
232 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
233 typename WriteBarrierPolicy2,
typename CheckingPolicy2>
234 bool operator==(
const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1,
235 CheckingPolicy1>& member1,
236 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2,
237 CheckingPolicy2>& member2) {
238 return member1.Get() == member2.Get();
241 template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
242 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
243 typename WriteBarrierPolicy2,
typename CheckingPolicy2>
244 bool operator!=(
const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1,
245 CheckingPolicy1>& member1,
246 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2,
247 CheckingPolicy2>& member2) {
248 return !(member1 == member2);
251 template <
typename T,
typename WriteBarrierPolicy,
typename CheckingPolicy>
253 internal::BasicMember<T, WeakMemberTag, WriteBarrierPolicy, CheckingPolicy>>
263 template <
typename T>
275 template <
typename T>
285 template <
typename T>