|
@ -13,7 +13,7 @@ namespace gp { |
|
|
gp::allocator& owner; |
|
|
gp::allocator& owner; |
|
|
|
|
|
|
|
|
unique_ptr(T* _data, gp::allocator& _owner) |
|
|
unique_ptr(T* _data, gp::allocator& _owner) |
|
|
: data(data) |
|
|
|
|
|
|
|
|
: data(_data) |
|
|
, owner(_owner) |
|
|
, owner(_owner) |
|
|
{} |
|
|
{} |
|
|
|
|
|
|
|
@ -25,19 +25,23 @@ namespace gp { |
|
|
} |
|
|
} |
|
|
public: |
|
|
public: |
|
|
template<typename ...U> |
|
|
template<typename ...U> |
|
|
unique_ptr make(gp::allocator& owner, U&&... args) { |
|
|
|
|
|
|
|
|
k">static unique_ptr make(gp::allocator& owner, U&&... args) { |
|
|
auto ptr = owner.allocate(sizeof(T)); |
|
|
auto ptr = owner.allocate(sizeof(T)); |
|
|
return unique_ptr(new(ptr) T(gp::forward<U>(args)...), owner); |
|
|
return unique_ptr(new(ptr) T(gp::forward<U>(args)...), owner); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
T& operator->() { |
|
|
|
|
|
return o">*data; |
|
|
|
|
|
|
|
|
T* operator->() { |
|
|
|
|
|
return data; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
T& operator*() { |
|
|
T& operator*() { |
|
|
return *data; |
|
|
return *data; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
operator bool() { |
|
|
|
|
|
return data != nullptr; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
unique_ptr(unique_ptr&) = delete; |
|
|
unique_ptr(unique_ptr&) = delete; |
|
|
|
|
|
|
|
|
unique_ptr(unique_ptr&& oth) |
|
|
unique_ptr(unique_ptr&& oth) |
|
@ -67,7 +71,7 @@ namespace gp { |
|
|
gp::allocator& owner; |
|
|
gp::allocator& owner; |
|
|
|
|
|
|
|
|
shared_ptr(T* _data, gp::allocator& _owner) |
|
|
shared_ptr(T* _data, gp::allocator& _owner) |
|
|
: data(data) |
|
|
|
|
|
|
|
|
: data(_data) |
|
|
, owner(_owner) |
|
|
, owner(_owner) |
|
|
{} |
|
|
{} |
|
|
|
|
|
|
|
@ -83,7 +87,7 @@ namespace gp { |
|
|
} |
|
|
} |
|
|
public: |
|
|
public: |
|
|
template<typename ...U> |
|
|
template<typename ...U> |
|
|
shared_ptr make(gp::allocator& owner, U&&... args) { |
|
|
|
|
|
|
|
|
k">static shared_ptr make(gp::allocator& owner, U&&... args) { |
|
|
auto ptr = owner.allocate(sizeof(T)); |
|
|
auto ptr = owner.allocate(sizeof(T)); |
|
|
auto shared_atomic = owner.allocate(sizeof(std::atomic_int)); |
|
|
auto shared_atomic = owner.allocate(sizeof(std::atomic_int)); |
|
|
refcounter = new(shared_atomic) std::atomic_int(); |
|
|
refcounter = new(shared_atomic) std::atomic_int(); |
|
@ -91,14 +95,18 @@ namespace gp { |
|
|
return shared_ptr(new(ptr) T(gp::forward<U>(args)...), owner); |
|
|
return shared_ptr(new(ptr) T(gp::forward<U>(args)...), owner); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
T& operator->() { |
|
|
|
|
|
return o">*data; |
|
|
|
|
|
|
|
|
T* operator->() { |
|
|
|
|
|
return data; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
T& operator*() { |
|
|
T& operator*() { |
|
|
return *data; |
|
|
return *data; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
operator bool() { |
|
|
|
|
|
return data != nullptr; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
shared_ptr(shared_ptr& oth) { |
|
|
shared_ptr(shared_ptr& oth) { |
|
|
oth.refcounter->fetch_add(1, std::memory_order::acquire); |
|
|
oth.refcounter->fetch_add(1, std::memory_order::acquire); |
|
|
|
|
|
|
|
|