16 template <
typename T,
typename TMutex = std::mutex>
55 : resource(ptr, ptr ?
alignedNew<
Detail::LockingControlBlock<T>>(ptr) : nullptr) {
65 : resource(other.resource)
66 , block(other.block) {}
68 template <
typename T2>
70 : resource(other.resource) {
75 : resource(
std::move(other.resource))
76 , block(other.block) {
77 other.block =
nullptr;
80 template <
typename T2>
82 : resource(
std::move(other.resource))
83 , block((
Detail::LockingControlBlock<T>*)other.block) {
86 other.block =
nullptr;
92 std::unique_lock<Detail::LockingControlBlock<T>>
lock(*block);
98 std::unique_lock<Detail::LockingControlBlock<T>>
lock(*block);
99 resource = other.resource;
102 resource = other.resource;
110 std::unique_lock<Detail::LockingControlBlock<T>>
lock(*block);
111 resource = std::move(other.resource);
114 resource = std::move(other.resource);
126 std::unique_lock<Detail::LockingControlBlock<T>>
lock;
157 return lock.owns_lock();
161 if (
lock.owns_lock()) {
178 return Proxy(resource, block);
186 return Proxy(resource, block);
194 explicit operator bool()
const {
195 return bool(resource);
204 std::unique_lock<Detail::LockingControlBlock<T>>
lock(*block);
213 template <
typename T,
typename... TArgs>
215 return LockingPtr<T>(alignedNew<T>(std::forward<TArgs>(args)...));
Base class for utility wrappers (Optional, Variant, ...)
NAMESPACE_SPH_BEGIN INLINE T * alignedNew(TArgs &&... args)
Creates a new object of type T on heap, using aligned allocation.
#define SPH_ASSERT(x,...)
LockingPtr< T > makeLocking(TArgs &&... args)
#define NAMESPACE_SPH_END
Wrapper of pointer that deletes the resource from destructor.
LockingControlBlock(T *ptr)
ProxyRef operator*() const
LockingPtr(LockingPtr &&other)
LockingPtr & operator=(const LockingPtr &other)
LockingPtr(const LockingPtr< T2 > &other)
LockingPtr(AutoPtr< T > &&other)
LockingPtr(const LockingPtr &other)
LockingPtr(LockingPtr< T2 > &&other)
LockingPtr & operator=(LockingPtr &&other)
Non-owning wrapper of pointer.
Detail::ControlBlockHolder * block
Overload of std::swap for Sph::Array.
void swap(Sph::Array< T, TCounter > &ar1, Sph::Array< T, TCounter > &ar2)