11 #ifndef __UT_DoubleLock__
12 #define __UT_DoubleLock__
49 template <
typename ValueT,
typename LockT = UT_Lock>
52 template <
typename Y>
class ValueTrait;
53 template <
typename Y,
typename DT>
class ValueTrait<UT_UniquePtr<Y, DT>>;
54 template <
typename Y,
typename DT>
class ValueTrait<UT_UniquePtr<Y[], DT>>;
56 using TraitT = ValueTrait<ValueT>;
59 using GetT =
typename TraitT::GetT;
60 using SetT =
typename TraitT::SetT;
61 static_assert(
sizeof(ValueT) ==
sizeof(
GetT),
"T is not trivial");
70 if (!relaxedLoad(
val))
74 if (!relaxedLoad(
val))
91 relaxedStore(myValue, TraitT::release(myPendingValue));
111 GetT v = relaxedLoad(myValue);
126 TraitT::move(myPendingValue, val);
137 template <
typename Y>
144 static Y release(Y &
v) {
return v; }
145 static GetT get(
const Y &
v) {
return v; }
146 static void move(Y &
dst,
const Y &
src) { dst =
src; }
148 template <
typename Y,
typename DT>
149 class ValueTrait<UT_UniquePtr<Y, DT>>
154 using SetT = PtrT &&;
156 static GetT release(PtrT &
v) {
return v.release(); }
157 static GetT get(
const PtrT &
v) {
return v.get(); }
158 static void move(PtrT &
dst, PtrT &
src) { dst.reset(src.release()); }
160 template <
typename Y,
typename DT>
161 class ValueTrait<UT_UniquePtr<Y[], DT>>
166 using SetT = PtrT &&;
168 static GetT release(PtrT &v) {
return v.release(); }
169 static GetT get(
const PtrT &
v) {
return v.get(); }
170 static void move(PtrT &
dst, PtrT &
src) { dst.reset(src.release()); }
173 static GetT relaxedLoad(
const volatile ValueT &
ptr)
175 const volatile GetT *addr
176 =
reinterpret_cast<const volatile GetT *
>(&
ptr);
177 return *
static_cast<const volatile GetT *
>(addr);
179 static void relaxedStore(
volatile ValueT &
ptr,
GetT src)
181 volatile GetT *addr =
reinterpret_cast<volatile GetT *
>(&
ptr);
182 *
static_cast<volatile GetT *
>(addr) = src;
187 volatile ValueT &myValue;
188 ValueT myPendingValue;
typename TraitT::SetT SetT
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
typename TraitT::GetT GetT
auto get(const UT_ARTIterator< T > &it) -> decltype(it.key())
UT_DoubleLock(LockT &lock, volatile ValueT &val)