Commit 5f7f7633 authored by Dominik Charousset's avatar Dominik Charousset

Make `intrusive_ptr` compatible to boost version

parent 64cff1d0
...@@ -171,7 +171,7 @@ public: ...@@ -171,7 +171,7 @@ public:
// we got the last element out of the cache; pass the reference to the // we got the last element out of the cache; pass the reference to the
// client to avoid pointless increase/decrease ops on the reference count // client to avoid pointless increase/decrease ops on the reference count
embedded_storage result; embedded_storage result;
result.first.reset(cache_.release(), false); result.first.reset(cache_.detach(), false);
result.second = res; result.second = res;
return result; return result;
} }
......
...@@ -105,19 +105,19 @@ public: ...@@ -105,19 +105,19 @@ public:
} }
inline message_data* release() { inline message_data* release() {
return ptr_.release(); return ptr_.detach();
} }
inline void detach() { inline void unshare() {
static_cast<void>(get_detached()); static_cast<void>(get_unshared());
} }
inline message_data* operator->() { inline message_data* operator->() {
return get_detached(); return get_unshared();
} }
inline message_data& operator*() { inline message_data& operator*() {
return *get_detached(); return *get_unshared();
} }
/************************************************************************** /**************************************************************************
* observers * * observers *
...@@ -140,7 +140,7 @@ public: ...@@ -140,7 +140,7 @@ public:
} }
private: private:
message_data* get_detached(); message_data* get_unshared();
intrusive_ptr<message_data> ptr_; intrusive_ptr<message_data> ptr_;
}; };
......
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
set_ptr(raw_ptr, add_ref); set_ptr(raw_ptr, add_ref);
} }
intrusive_ptr(intrusive_ptr&& other) : ptr_(other.release()) { intrusive_ptr(intrusive_ptr&& other) : ptr_(other.detach()) {
// nop // nop
} }
...@@ -60,7 +60,7 @@ public: ...@@ -60,7 +60,7 @@ public:
} }
template <class Y> template <class Y>
intrusive_ptr(intrusive_ptr<Y> other) : ptr_(other.release()) { intrusive_ptr(intrusive_ptr<Y> other) : ptr_(other.detach()) {
static_assert(std::is_convertible<Y*, T*>::value, static_assert(std::is_convertible<Y*, T*>::value,
"Y* is not assignable to T*"); "Y* is not assignable to T*");
} }
...@@ -77,12 +77,18 @@ public: ...@@ -77,12 +77,18 @@ public:
/// Returns the raw pointer without modifying reference /// Returns the raw pointer without modifying reference
/// count and sets this to `nullptr`. /// count and sets this to `nullptr`.
pointer release() noexcept { pointer detach() noexcept {
auto result = ptr_; auto result = ptr_;
ptr_ = nullptr; ptr_ = nullptr;
return result; return result;
} }
/// Returns the raw pointer without modifying reference
/// count and sets this to `nullptr`.
pointer release() noexcept {
return detach();
}
void reset(pointer new_value = nullptr, bool add_ref = true) { void reset(pointer new_value = nullptr, bool add_ref = true) {
auto old = ptr_; auto old = ptr_;
set_ptr(new_value, add_ref); set_ptr(new_value, add_ref);
......
...@@ -201,7 +201,7 @@ public: ...@@ -201,7 +201,7 @@ public:
} }
// detach msg before invoking fun_ if needed // detach msg before invoking fun_ if needed
if (is_manipulator) { if (is_manipulator) {
msg.force_detach(); msg.force_unshare();
// update pointers in our intermediate tuple // update pointers in our intermediate tuple
for (size_t i = 0; i < msg.size(); ++i) { for (size_t i = 0; i < msg.size(); ++i) {
// msg is guaranteed to be detached, hence we don't need to // msg is guaranteed to be detached, hence we don't need to
...@@ -369,7 +369,7 @@ public: ...@@ -369,7 +369,7 @@ public:
bool prepare_invoke(message& msg, Tuple* out) { bool prepare_invoke(message& msg, Tuple* out) {
// detach msg before invoking fun_ if needed // detach msg before invoking fun_ if needed
if (detail::tl_exists<fargs, detail::is_mutable_ref>::value) { if (detail::tl_exists<fargs, detail::is_mutable_ref>::value) {
msg.force_detach(); msg.force_unshare();
} }
using filtered_pattern = using filtered_pattern =
typename detail::tl_filter_not_type< typename detail::tl_filter_not_type<
......
...@@ -281,8 +281,8 @@ public: ...@@ -281,8 +281,8 @@ public:
return vals_ ? vals_->type_token() : 0xFFFFFFFF; return vals_ ? vals_->type_token() : 0xFFFFFFFF;
} }
inline void force_detach() { inline void force_unshare() {
vals_.detach(); vals_.unshare();
} }
void reset(raw_ptr new_ptr = nullptr, bool add_ref = true); void reset(raw_ptr new_ptr = nullptr, bool add_ref = true);
......
...@@ -156,7 +156,7 @@ message message_builder::to_message() const { ...@@ -156,7 +156,7 @@ message message_builder::to_message() const {
message message_builder::move_to_message() { message message_builder::move_to_message() {
message result; message result;
result.vals().reset(static_cast<dynamic_msg_data*>(data_.release()), false); result.vals().reset(static_cast<dynamic_msg_data*>(data_.detach()), false);
return result; return result;
} }
...@@ -164,7 +164,7 @@ optional<message> message_builder::apply(message_handler handler) { ...@@ -164,7 +164,7 @@ optional<message> message_builder::apply(message_handler handler) {
// avoid detaching of data_ by moving the data to a message object, // avoid detaching of data_ by moving the data to a message object,
// calling message::apply and moving the data back // calling message::apply and moving the data back
message::data_ptr ptr; message::data_ptr ptr;
ptr.reset(static_cast<dynamic_msg_data*>(data_.release()), false); ptr.reset(static_cast<dynamic_msg_data*>(data_.detach()), false);
message msg{std::move(ptr)}; message msg{std::move(ptr)};
auto res = msg.apply(std::move(handler)); auto res = msg.apply(std::move(handler));
data_.reset(msg.vals().release(), false); data_.reset(msg.vals().release(), false);
......
...@@ -65,7 +65,7 @@ std::string message_data::tuple_type_names() const { ...@@ -65,7 +65,7 @@ std::string message_data::tuple_type_names() const {
return result; return result;
} }
message_data* message_data::cow_ptr::get_detached() { message_data* message_data::cow_ptr::get_unshared() {
auto p = ptr_.get(); auto p = ptr_.get();
if (! p->unique()) { if (! p->unique()) {
auto cptr = p->copy(); auto cptr = p->copy();
......
...@@ -727,7 +727,7 @@ default_multiplexer::~default_multiplexer() { ...@@ -727,7 +727,7 @@ default_multiplexer::~default_multiplexer() {
} }
void default_multiplexer::dispatch_runnable(runnable_ptr ptr) { void default_multiplexer::dispatch_runnable(runnable_ptr ptr) {
wr_dispatch_request(ptr.release()); wr_dispatch_request(ptr.detach());
} }
connection_handle default_multiplexer::add_tcp_scribe(abstract_broker* self, connection_handle default_multiplexer::add_tcp_scribe(abstract_broker* self,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment