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);
49 mutable const void* raw_ =
nullptr;
53 template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
54 typename CheckingPolicy>
55 class BasicMember final :
private MemberBase,
private CheckingPolicy {
57 using PointeeType = T;
63 InitializingWriteBarrier();
64 this->CheckPointer(Get());
76 InitializingWriteBarrier();
77 this->CheckPointer(Get());
80 : BasicMember(&raw, atomic) {}
82 BasicMember(
const BasicMember& other) : BasicMember(other.Get()) {}
84 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
85 typename OtherCheckingPolicy,
86 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
88 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
89 OtherCheckingPolicy>& other)
90 : BasicMember(other.Get()) {}
92 BasicMember(BasicMember&& other)
noexcept : BasicMember(other.Get()) {
96 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
97 typename OtherCheckingPolicy,
98 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
99 BasicMember(BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
100 OtherCheckingPolicy>&& other)
noexcept
101 : BasicMember(other.Get()) {
105 template <
typename U,
typename PersistentWeaknessPolicy,
106 typename PersistentLocationPolicy,
107 typename PersistentCheckingPolicy,
108 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
110 PersistentLocationPolicy,
111 PersistentCheckingPolicy>& p)
112 : BasicMember(p.Get()) {}
116 return operator=(other.Get());
119 template <
typename U,
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
120 typename OtherCheckingPolicy,
121 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
123 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
124 OtherCheckingPolicy>& other) {
125 return operator=(other.Get());
128 BasicMember&
operator=(BasicMember&& other)
noexcept {
129 operator=(other.Get());
134 template <
typename U,
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
135 typename OtherCheckingPolicy,
136 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
137 BasicMember&
operator=(BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
138 OtherCheckingPolicy>&& other)
noexcept {
139 operator=(other.Get());
144 template <
typename U,
typename PersistentWeaknessPolicy,
145 typename PersistentLocationPolicy,
146 typename PersistentCheckingPolicy,
147 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
150 PersistentLocationPolicy, PersistentCheckingPolicy>&
152 return operator=(other.Get());
156 AssigningWriteBarrier();
157 this->CheckPointer(Get());
169 template <
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
170 typename OtherCheckingPolicy>
171 void Swap(BasicMember<T, OtherWeaknessTag, OtherBarrierPolicy,
172 OtherCheckingPolicy>& other) {
208 const T* GetRawAtomic()
const {
212 void InitializingWriteBarrier()
const {
215 void AssigningWriteBarrier()
const {
221 T* GetFromGC()
const {
return Get(); }
224 template <
typename U>
228 template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
229 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
230 typename WriteBarrierPolicy2,
typename CheckingPolicy2>
231 bool operator==(
const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1,
232 CheckingPolicy1>& member1,
233 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2,
234 CheckingPolicy2>& member2) {
235 return member1.Get() == member2.Get();
238 template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
239 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
240 typename WriteBarrierPolicy2,
typename CheckingPolicy2>
241 bool operator!=(
const BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1,
242 CheckingPolicy1>& member1,
243 const BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2,
244 CheckingPolicy2>& member2) {
245 return !(member1 == member2);
248 template <
typename T,
typename WriteBarrierPolicy,
typename CheckingPolicy>
250 internal::BasicMember<T, WeakMemberTag, WriteBarrierPolicy, CheckingPolicy>>
260 template <
typename T>
272 template <
typename T>
282 template <
typename T>