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

Make `intrusive_ptr` compatible to boost version

parent 64cff1d0
......@@ -171,7 +171,7 @@ public:
// 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
embedded_storage result;
result.first.reset(cache_.release(), false);
result.first.reset(cache_.detach(), false);
result.second = res;
return result;
}
......
......@@ -105,19 +105,19 @@ public:
}
inline message_data* release() {
return ptr_.release();
return ptr_.detach();
}
inline void detach() {
static_cast<void>(get_detached());
inline void unshare() {
static_cast<void>(get_unshared());
}
inline message_data* operator->() {
return get_detached();
return get_unshared();
}
inline message_data& operator*() {
return *get_detached();
return *get_unshared();
}
/**************************************************************************
* observers *
......@@ -140,7 +140,7 @@ public:
}
private:
message_data* get_detached();
message_data* get_unshared();
intrusive_ptr<message_data> ptr_;
};
......
......@@ -51,7 +51,7 @@ public:
set_ptr(raw_ptr, add_ref);
}
intrusive_ptr(intrusive_ptr&& other) : ptr_(other.release()) {
intrusive_ptr(intrusive_ptr&& other) : ptr_(other.detach()) {
// nop
}
......@@ -60,7 +60,7 @@ public:
}
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,
"Y* is not assignable to T*");
}
......@@ -77,12 +77,18 @@ public:
/// Returns the raw pointer without modifying reference
/// count and sets this to `nullptr`.
pointer release() noexcept {
pointer detach() noexcept {
auto result = ptr_;
ptr_ = nullptr;
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) {
auto old = ptr_;
set_ptr(new_value, add_ref);
......
......@@ -201,7 +201,7 @@ public:
}
// detach msg before invoking fun_ if needed
if (is_manipulator) {
msg.force_detach();
msg.force_unshare();
// update pointers in our intermediate tuple
for (size_t i = 0; i < msg.size(); ++i) {
// msg is guaranteed to be detached, hence we don't need to
......@@ -369,7 +369,7 @@ public:
bool prepare_invoke(message& msg, Tuple* out) {
// detach msg before invoking fun_ if needed
if (detail::tl_exists<fargs, detail::is_mutable_ref>::value) {
msg.force_detach();
msg.force_unshare();
}
using filtered_pattern =
typename detail::tl_filter_not_type<
......
......@@ -281,8 +281,8 @@ public:
return vals_ ? vals_->type_token() : 0xFFFFFFFF;
}
inline void force_detach() {
vals_.detach();
inline void force_unshare() {
vals_.unshare();
}
void reset(raw_ptr new_ptr = nullptr, bool add_ref = true);
......
......@@ -156,7 +156,7 @@ message message_builder::to_message() const {
message message_builder::move_to_message() {
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;
}
......@@ -164,7 +164,7 @@ optional<message> message_builder::apply(message_handler handler) {
// avoid detaching of data_ by moving the data to a message object,
// calling message::apply and moving the data back
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)};
auto res = msg.apply(std::move(handler));
data_.reset(msg.vals().release(), false);
......
......@@ -65,7 +65,7 @@ std::string message_data::tuple_type_names() const {
return result;
}
message_data* message_data::cow_ptr::get_detached() {
message_data* message_data::cow_ptr::get_unshared() {
auto p = ptr_.get();
if (! p->unique()) {
auto cptr = p->copy();
......
......@@ -727,7 +727,7 @@ default_multiplexer::~default_multiplexer() {
}
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,
......
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