libjmmcg
release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
|
A shared pointer-type that has threading specified as a trait, and uses an intrusive count to save on calls to the memory allocator, which could cause excessive contention on the memory manager in a multi-threaded environment. More...
#include <shared_ptr.hpp>
Public Types | |
using | value_type = V |
A convenience typedef to the type to be controlled. More... | |
using | element_type = value_type |
A convenience typedef to the type to be controlled. More... | |
using | lock_traits = LkT |
using | atomic_ptr_t = typename lock_traits::template atomic< value_type * > |
The (potentially) lock-free pointer type. More... | |
using | base_ctr_type = sp_counter_itf_type< long > |
The counter interface to be used on the controlled type, which allows the counter-type to be specified at compile or run-time. More... | |
using | ctr_type = typename V::atomic_ctr_t |
using | exception_type = typename lock_traits::exception_type |
using | deleter_t = typename value_type::deleter_t |
Make sure the correct object-deletion mechanism is used. More... | |
using | no_ref_counting = typename lock_traits::template noop_atomic_ctr< typename ctr_type::value_type > |
The no-op atomic counter does nothing, therefore the shared_ptr must not manage the memory of such objects... More... | |
using | no_deletion = noop_dtor< typename value_type::deleter_t::element_type > |
Public Member Functions | |
BOOST_MPL_ASSERT ((std::is_base_of< base_ctr_type, value_type >)) | |
atomic_ptr_t __fastcall | release () noexcept(true) |
constexpr __stdcall | shared_ptr () noexcept(true) |
__stdcall | shared_ptr (value_type *ptr) noexcept(true) |
template<class V1 > | |
__stdcall | shared_ptr (V1 *ptr) noexcept(true) |
__stdcall | shared_ptr (atomic_ptr_t const &ptr) noexcept(true) |
template<class V1 > | |
__stdcall | shared_ptr (sp_counter_itf_type< V1 > const &ptr) noexcept(true) |
template<class V1 , template< class > class At> | |
__stdcall | shared_ptr (At< V1 * > const &ptr) noexcept(true) |
__stdcall | shared_ptr (std::unique_ptr< value_type, deleter_t > &ptr) noexcept(true) |
template<class V1 > | |
__stdcall | shared_ptr (std::unique_ptr< V1, typename V1::deleter_t > &ptr) noexcept(true) |
__stdcall | shared_ptr (std::unique_ptr< value_type, deleter_t > &&ptr) noexcept(true) |
template<class V1 > | |
__stdcall | shared_ptr (std::unique_ptr< V1, typename V1::deleter_t > &&ptr) noexcept(true) |
template<class V2 , class LkT2 > | |
JMMCG_MSVC_STDCALL_HACK | shared_ptr (const shared_ptr< V2, LkT2 > &s) noexcept(true) |
template<class V2 , class LkT2 > | |
JMMCG_MSVC_STDCALL_HACK | shared_ptr (shared_ptr< V2, LkT2 > &&s) noexcept(true) |
shared_ptr (const shared_ptr &s) noexcept(true) | |
shared_ptr (shared_ptr &&s) noexcept(true) | |
__stdcall | ~shared_ptr () noexcept(true) |
template<class V2 , class LkT2 > | |
void | operator= (const shared_ptr< V2, LkT2 > &s) noexcept(true) |
template<class V2 , class LkT2 > | |
void | operator= (shared_ptr< V2, LkT2 > &&s) noexcept(true) |
void | operator= (const shared_ptr &s) noexcept(true) |
void | operator= (shared_ptr &&s) noexcept(true) |
void __fastcall | reset () noexcept(true) |
constexpr bool __fastcall | operator== (const shared_ptr &s) const noexcept(true) |
constexpr bool __fastcall | operator!= (const shared_ptr &s) const noexcept(true) |
constexpr bool __fastcall | operator< (const shared_ptr &s) const noexcept(true) |
constexpr bool __fastcall | operator> (const shared_ptr &s) const noexcept(true) |
constexpr | operator bool () const noexcept(true) |
constexpr const atomic_ptr_t &__fastcall | get () const noexcept(true) |
atomic_ptr_t &__fastcall | get () noexcept(true) |
constexpr const value_type &__fastcall | operator* () const noexcept(true) |
value_type &__fastcall | operator* () noexcept(true) |
constexpr value_type const *__fastcall | operator-> () const noexcept(true) |
value_type *__fastcall | operator-> () noexcept(true) |
void | swap (shared_ptr &s) noexcept(true) |
tstring | to_string () const noexcept(false) |
template<class V1 > | |
shared_ptr (V1 *ptr) noexcept(true) | |
template<class V1 > | |
shared_ptr (sp_counter_itf_type< V1 > const &ptr) noexcept(true) | |
template<class V1 , template< class > class At> | |
shared_ptr (At< V1 * > const &ptr) noexcept(true) | |
template<class V1 > | |
shared_ptr (std::unique_ptr< V1, typename V1::deleter_t > &d) noexcept(true) | |
template<class V1 > | |
shared_ptr (std::unique_ptr< V1, typename V1::deleter_t > &&d) noexcept(true) | |
template<typename V2 , class LkT2 > | |
shared_ptr (const shared_ptr< V2, LkT2 > &s) noexcept(true) | |
template<typename V2 , class LkT2 > | |
shared_ptr (shared_ptr< V2, LkT2 > &&s) noexcept(true) | |
Static Public Attributes | |
static constexpr ppd::generic_traits::memory_access_modes | memory_access_mode |
Friends | |
template<class , class > | |
class | shared_ptr |
tostream &__fastcall | operator<< (tostream &os, shared_ptr const &ptr) noexcept(false) |
A shared pointer-type that has threading specified as a trait, and uses an intrusive count to save on calls to the memory allocator, which could cause excessive contention on the memory manager in a multi-threaded environment.
I don't use boost::shared_ptr nor std::shared_ptr as they are insufficiently flexible for my purposes: the multi-threading model they use is not a trait, moreover their counters & deleters can only be specified at compile-time, not also at run-time. This class uses a lock-free implementation based upon the careful use of the sp_counter_type that uses a specialised atomic_counter_type. For performance tests see 'examples/shared_ptr_parallel.cpp'.
Definition at line 129 of file shared_ptr.hpp.
using jmmcg::LIBJMMCG_VER_NAMESPACE::shared_ptr< V, LkT >::atomic_ptr_t = typename lock_traits::template atomic<value_type *> |
The (potentially) lock-free pointer type.
We need the operations on the contained pointer (to the managed object) to be atomic because the move operations might occur on more than one thread, and therefore there is a race condition on non-SMP architectures, which is avoided if (in the implementation) the operations on the contained pointer are atomic.
Definition at line 138 of file shared_ptr.hpp.
using jmmcg::LIBJMMCG_VER_NAMESPACE::shared_ptr< V, LkT >::base_ctr_type = sp_counter_itf_type<long> |
The counter interface to be used on the controlled type, which allows the counter-type to be specified at compile or run-time.
Definition at line 140 of file shared_ptr.hpp.
using jmmcg::LIBJMMCG_VER_NAMESPACE::shared_ptr< V, LkT >::ctr_type = typename V::atomic_ctr_t |
Definition at line 141 of file shared_ptr.hpp.
using jmmcg::LIBJMMCG_VER_NAMESPACE::shared_ptr< V, LkT >::deleter_t = typename value_type::deleter_t |
Make sure the correct object-deletion mechanism is used.
Definition at line 147 of file shared_ptr.hpp.
using jmmcg::LIBJMMCG_VER_NAMESPACE::shared_ptr< V, LkT >::element_type = value_type |
A convenience typedef to the type to be controlled.
Definition at line 132 of file shared_ptr.hpp.
using jmmcg::LIBJMMCG_VER_NAMESPACE::shared_ptr< V, LkT >::exception_type = typename lock_traits::exception_type |
Definition at line 142 of file shared_ptr.hpp.
using jmmcg::LIBJMMCG_VER_NAMESPACE::shared_ptr< V, LkT >::lock_traits = LkT |
This does not have to be the same as the element_type, as it may not contain any lock_traits, or we may want the flexibility to deal with the type differently in this case.
Definition at line 133 of file shared_ptr.hpp.
using jmmcg::LIBJMMCG_VER_NAMESPACE::shared_ptr< V, LkT >::no_deletion = noop_dtor<typename value_type::deleter_t::element_type> |
If you get a compilation issue here, check you aren't using std::default_delete, but libjmmcg::default_delete instead.
Definition at line 158 of file shared_ptr.hpp.
using jmmcg::LIBJMMCG_VER_NAMESPACE::shared_ptr< V, LkT >::no_ref_counting = typename lock_traits::template noop_atomic_ctr<typename ctr_type::value_type> |
The no-op atomic counter does nothing, therefore the shared_ptr must not manage the memory of such objects...
Definition at line 152 of file shared_ptr.hpp.
using jmmcg::LIBJMMCG_VER_NAMESPACE::shared_ptr< V, LkT >::value_type = V |
A convenience typedef to the type to be controlled.
Definition at line 131 of file shared_ptr.hpp.
|
inlineconstexprnoexcept |
Definition at line 178 of file shared_ptr.hpp.
|
inlineexplicitnoexcept |
ptr | Note that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero. |
Definition at line 55 of file shared_ptr_impl.hpp.
|
explicitnoexcept |
ptr | Note that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero. The type of the parameter must be the same type or a class non-privately derived from value_type. |
|
inlineexplicitnoexcept |
ptr | Note that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero. |
Definition at line 87 of file shared_ptr_impl.hpp.
|
explicitnoexcept |
ptr | Note that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero. |
|
explicitnoexcept |
ptr | Note that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero. |
|
inlineexplicitnoexcept |
ptr | Note that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero. |
Definition at line 130 of file shared_ptr_impl.hpp.
|
explicitnoexcept |
ptr | Note that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero. The type of the parameter must be the same type or a class non-privately derived from value_type. |
|
inlineexplicitnoexcept |
ptr | Note that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero. |
Definition at line 159 of file shared_ptr_impl.hpp.
|
explicitnoexcept |
ptr | Note that this ptr could have a non-zero reference count, and this ctor will take ownership of the ptr, respecting that reference count, only deleting the ptr if it reaches zero. The type of the parameter must be the same type or a class non-privately derived from value_type. |
|
explicitnoexcept |
Note that the same deleter and threading model must be specified.
s | The type of the parameter must be the same type or a class non-privately derived from value_type. |
|
explicitnoexcept |
Note that the same deleter and threading model must be specified.
s | The type of the parameter must be the same type or a class non-privately derived from value_type. |
|
inlinenoexcept |
Definition at line 188 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 202 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 240 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 69 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 101 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 115 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 144 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 172 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 210 of file shared_ptr_impl.hpp.
References jmmcg::LIBJMMCG_VER_NAMESPACE::sp_counter_type< Val, LkT, Del, AtCtr >::shared_ptr.
|
inlinenoexcept |
Definition at line 230 of file shared_ptr_impl.hpp.
jmmcg::LIBJMMCG_VER_NAMESPACE::shared_ptr< V, LkT >::BOOST_MPL_ASSERT | ( | (std::is_base_of< base_ctr_type, value_type >) | ) |
|
inlineconstexprnoexcept |
Definition at line 303 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 307 of file shared_ptr_impl.hpp.
|
inlineexplicitconstexprnoexcept |
Definition at line 294 of file shared_ptr_impl.hpp.
|
inlineconstexprnoexcept |
Definition at line 290 of file shared_ptr_impl.hpp.
|
inlineconstexprnoexcept |
Definition at line 311 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 316 of file shared_ptr_impl.hpp.
|
inlineconstexprnoexcept |
Definition at line 321 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 325 of file shared_ptr_impl.hpp.
|
inlineconstexprnoexcept |
Definition at line 281 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 269 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Note that the same deleter and threading model must be specified.
s | The type of the parameter must be the same type or a class non-privately derived from value_type. |
Definition at line 252 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 276 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Note that the same deleter and threading model must be specified.
s | The type of the parameter must be the same type or a class non-privately derived from value_type. |
Definition at line 263 of file shared_ptr_impl.hpp.
|
inlineconstexprnoexcept |
Definition at line 286 of file shared_ptr_impl.hpp.
|
inlineconstexprnoexcept |
Definition at line 298 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Decrement the reference count & possibly delete the object, via calling value_type::delete() which uses the value_type::deleter_t method to delete the object & release the memory.
Definition at line 26 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 50 of file shared_ptr_impl.hpp.
References jmmcg::LIBJMMCG_VER_NAMESPACE::sp_counter_type< Val, LkT, Del, AtCtr >::shared_ptr.
|
inlinenoexcept |
Definition at line 245 of file shared_ptr_impl.hpp.
|
inlinenoexcept |
Definition at line 330 of file shared_ptr_impl.hpp.
References jmmcg::LIBJMMCG_VER_NAMESPACE::sp_counter_type< Val, LkT, Del, AtCtr >::shared_ptr.
|
friend |
Definition at line 303 of file shared_ptr.hpp.
Definition at line 309 of file shared_ptr.hpp.
|
staticconstexpr |
To assist in allowing compile-time computation of the algorithmic order of the threading model.
Definition at line 162 of file shared_ptr.hpp.