5 #ifndef INCLUDE_CPPGC_CROSS_THREAD_PERSISTENT_H_
6 #define INCLUDE_CPPGC_CROSS_THREAD_PERSISTENT_H_
10 #include "cppgc/internal/persistent-node.h"
11 #include "cppgc/internal/pointer-policies.h"
12 #include "cppgc/persistent.h"
13 #include "cppgc/visitor.h"
19 template <
typename T,
typename WeaknessPolicy,
typename LocationPolicy,
20 typename CheckingPolicy>
22 public LocationPolicy,
23 private WeaknessPolicy,
24 private CheckingPolicy {
26 using typename WeaknessPolicy::IsStrongPersistent;
27 using PointeeType = T;
33 : LocationPolicy(loc) {}
37 : LocationPolicy(loc) {}
46 if (!IsValid(raw))
return;
47 PersistentRegion& region =
this->GetPersistentRegion(raw);
49 this->CheckPointer(raw);
56 template <
typename U,
typename MemberBarrierPolicy,
57 typename MemberWeaknessTag,
typename MemberCheckingPolicy,
58 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
60 internal::BasicMember<U, MemberBarrierPolicy, MemberWeaknessTag,
75 template <
typename U,
typename OtherWeaknessPolicy,
76 typename OtherLocationPolicy,
typename OtherCheckingPolicy,
77 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
81 OtherCheckingPolicy>& other,
91 *
this = std::move(other);
96 PersistentRegionLock guard;
97 AssignUnsafe(other.Get());
101 template <
typename U,
typename OtherWeaknessPolicy,
102 typename OtherLocationPolicy,
typename OtherCheckingPolicy,
103 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
107 OtherCheckingPolicy>& other) {
108 PersistentRegionLock guard;
109 AssignUnsafe(other.Get());
114 if (
this == &other)
return *
this;
116 PersistentRegionLock guard;
118 LocationPolicy::operator=(std::move(other));
121 other.SetValue(
nullptr);
122 other.SetNode(
nullptr);
133 template <
typename U,
typename MemberBarrierPolicy,
134 typename MemberWeaknessTag,
typename MemberCheckingPolicy,
135 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
137 internal::BasicMember<U, MemberBarrierPolicy, MemberWeaknessTag,
138 MemberCheckingPolicy>
140 return operator=(member.Get());
164 return static_cast<T*>(
const_cast<
void*>(
GetValue()));
174 if (IsValid(old_value)) {
175 PersistentRegionLock guard;
176 PersistentRegion& region =
this->GetPersistentRegion(old_value);
222 template <
typename U,
typename OtherWeaknessPolicy = WeaknessPolicy,
223 typename OtherLocationPolicy = LocationPolicy,
224 typename OtherCheckingPolicy = CheckingPolicy>
228 PersistentRegionLock guard;
230 OtherLocationPolicy, OtherCheckingPolicy>(
231 static_cast<U*>(Get()));
234 template <
typename U = T,
236 U, WeaknessPolicy>::IsStrongPersistent::value>::type>
244 static bool IsValid(
const void* ptr) {
248 static void Trace(
Visitor* v,
const void* ptr) {
250 v->TraceRoot(*handle, handle->Location());
253 void Assign(T* ptr) {
255 if (IsValid(old_value)) {
256 PersistentRegionLock guard;
257 PersistentRegion& region =
this->GetPersistentRegion(old_value);
258 if (IsValid(ptr) && (®ion == &
this->GetPersistentRegion(ptr))) {
260 this->CheckPointer(ptr);
267 if (!IsValid(ptr))
return;
268 PersistentRegionLock guard;
269 SetNode(this->GetPersistentRegion(ptr).AllocateNode(
this, &Trace)
);
270 this->CheckPointer(ptr);
273 void AssignUnsafe(T* ptr) {
276 if (IsValid(old_value)) {
277 PersistentRegion& region =
this->GetPersistentRegion(old_value);
278 if (IsValid(ptr) && (®ion == &
this->GetPersistentRegion(ptr))) {
280 this->CheckPointer(ptr);
287 if (!IsValid(ptr))
return;
288 SetNode(this->GetPersistentRegion(ptr).AllocateNode(
this, &Trace)
);
289 this->CheckPointer(ptr);
292 void ClearFromGC()
const {
302 template <
typename T,
typename LocationPolicy,
typename CheckingPolicy>
305 LocationPolicy, CheckingPolicy>>
323 template <
typename T>
338 template <
typename T>