Avi Kivity
8628d98542
shared_ptr: fix reference count loss when creating a derived type with e_s_f_t
...
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.
2015-03-10 10:56:10 +02:00
Tomasz Grabiec
d674cd7deb
core: add make_shared(T&&) overload
...
Allows for code like this:
auto p = make_shared(object());
2015-03-04 18:49:26 +02:00
Avi Kivity
1e5df06f9a
shared_ptr: provide default std::hash<> specializations
...
Folloing std::shared_ptr.
2015-03-01 13:36:17 +02:00
Avi Kivity
3d81e06353
shared_ptr: fix dynamic_pointer_cast() dropping a ref after failure
...
If the input to dynamic_pointer_cast() faild the conversion, we leaked
a reference to the input object.
2015-02-25 11:05:45 +02:00
Avi Kivity
7f8d88371a
Add LICENSE, NOTICE, and copyright headers to all source files.
...
The two files imported from the OSv project retain their original licenses.
2015-02-19 16:52:34 +02:00
Pekka Enberg
fc7cb5ab5e
shared_ptr: Fix assignment of polymorphic types
...
Fix the assignment operator to work with polymorphic types.
Suggested by Nadav.
Signed-off-by: Pekka Enberg <penberg@cloudius-systems.com >
2015-02-08 10:24:21 +02:00
Tomasz Grabiec
24227fd933
shared_ptr: Add helpers for hashing shared_ptr<> by value
2015-01-25 13:12:04 +02:00
Gleb Natapov
20d2725ed9
core: shared_ptr add noexcept
...
Add missing noexcepts. Those on constructors are needed to be able to
store shared pointers in growable containers efficiently.
2015-01-12 17:29:02 +02:00
Pekka Enberg
fa8d120d70
core: Fix shared_ptr pointer casts
...
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 >
2015-01-07 13:50:59 +02:00
Avi Kivity
66eea763bf
shared_ptr: add comparison operators
2015-01-05 13:24:07 +02:00
Avi Kivity
7a317f78a2
shared_ptr: be friend to self
...
Needed for converting constructor.
2015-01-05 13:24:06 +02:00
Avi Kivity
c7d7494a65
shared_ptr: add some documentation
2015-01-05 10:39:35 +02:00
Avi Kivity
b6d76ed650
shared_ptr: add polymorphic-capable shared pointer
...
At the cost of doubling the pointer size, this shared_ptr is polymorphic
and can be upcast to a base class.
2015-01-04 23:15:58 +02:00
Avi Kivity
87f63f7b90
shared_ptr: rename to lw_shared_ptr (for light-weight)
...
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.
2015-01-04 22:38:49 +02:00
Avi Kivity
33518ea9d0
shared_ptr: fix uninitialized enable_shared_from_this ref count
...
Caused immediate leak.
2015-01-01 14:29:27 +02:00
Avi Kivity
3cecef365f
shared_ptr: implement enable_shared_from_this<>
...
Mirrors std::enable_shared_from_this<>.
2014-12-29 11:02:31 +02:00
Tomasz Grabiec
0b4ee2ff60
core: advertise element type in shared_ptr<>
...
Other smart pointers also do that. Will help foreign_ptr<>.
2014-11-11 13:52:23 +02:00
Asias He
8b737c95e5
core: Add use_count for shared_ptr
...
This is useful when debugging shared_ptr.
2014-10-22 11:40:18 +03:00
Tomasz Grabiec
319ae0b530
core: add shared_ptr::operator=(T&&)
...
Allows to move an item directly into existing shread_ptr.
2014-10-15 15:59:42 +02:00
Avi Kivity
e659c7fafc
Add specializations to make_shared
2014-09-03 16:22:27 +03:00
Avi Kivity
48f570f57c
core: add shared_ptr<> smart pointer
...
Just like std::shared_ptr<>, except no atomics.
2014-09-02 19:08:52 +03:00