Add a use_count() method for shared_ptr, like std::shared_ptr has.
We already had such a method for lw_shared_ptr, but not for shared_ptr.
Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>
Allow enable_shared_from_this<T>::shared_from_this() to return
a shared_ptr<const T> when called on a const object.
Reviewed-by: Pekka Enberg <penberg@cloudius-systems.com>
The foreign_ptr wrapper needs 'element_type' to be present in
shared_ptr to be able to access the data.
Fixes the following compilation failure when trying to use shared_ptr
with foreign_ptr:
In file included from tests/foreign_ptr_test.cc:24:0:
./core/distributed.hh: In instantiation of ‘class foreign_ptr<shared_ptr<basic_sstring<char, unsigned int, 15u> > >’:
tests/foreign_ptr_test.cc:28:54: required from here
./core/distributed.hh:272:56: error: no type named ‘element_type’ in ‘class shared_ptr<basic_sstring<char, unsigned int, 15u> >’
using element_type = typename PtrType::element_type;
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
make_shared() has a special case for detecting a created class deriving
from enable_shared_from_this<>, so it can point the refcount pointer into
the object's data area instead of creating a shared_ptr_count_base for it.
The code, however, fails to detect a creating class deriving indirectly
from enable_shared_from_this:
struct base : enable_shared_from_this<base> {};
struct derived : base {};
make_shared<derived>(); // <- allocates independent refcount
The result is that the object reference counter lives in two locations.
Fix by detecting the derived class case as well.
Fix compilation errors in the shared_ptr pointer cast functions and
update shared_ptr constructor to take shared_ptr_count_base.
Suggested by Avi.
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com>
The current shared_ptr implementation is efficient, but does not support
polymorphic types.
Rename it in order to make room for a polymorphic shared_ptr.