Commit b89c7db8 authored by Dominik Charousset's avatar Dominik Charousset

Clean up linking state properly

parent 582605a2
...@@ -71,11 +71,7 @@ public: ...@@ -71,11 +71,7 @@ public:
} }
/// Unlinks this actor from `x`. /// Unlinks this actor from `x`.
void unlink_from(const actor_addr& x) { void unlink_from(const actor_addr& x);
auto ptr = actor_cast<strong_actor_ptr>(x);
if (ptr && ptr->get() != this)
remove_link(ptr->get());
}
/// Links this actor to `x`. /// Links this actor to `x`.
template <class ActorHandle> template <class ActorHandle>
......
...@@ -44,6 +44,8 @@ void forwarding_actor_proxy::forward_msg(strong_actor_ptr sender, ...@@ -44,6 +44,8 @@ void forwarding_actor_proxy::forward_msg(strong_actor_ptr sender,
const forwarding_stack* fwd) { const forwarding_stack* fwd) {
CAF_LOG_TRACE(CAF_ARG(id()) << CAF_ARG(sender) CAF_LOG_TRACE(CAF_ARG(id()) << CAF_ARG(sender)
<< CAF_ARG(mid) << CAF_ARG(msg)); << CAF_ARG(mid) << CAF_ARG(msg));
if (msg.match_elements<exit_msg>())
unlink_from(msg.get_as<exit_msg>(0).source);
forwarding_stack tmp; forwarding_stack tmp;
shared_lock<detail::shared_spinlock> guard(mtx_); shared_lock<detail::shared_spinlock> guard(mtx_);
if (broker_) if (broker_)
......
...@@ -39,7 +39,7 @@ const char* monitorable_actor::name() const { ...@@ -39,7 +39,7 @@ const char* monitorable_actor::name() const {
void monitorable_actor::attach(attachable_ptr ptr) { void monitorable_actor::attach(attachable_ptr ptr) {
CAF_LOG_TRACE(""); CAF_LOG_TRACE("");
CAF_ASSERT(ptr); CAF_ASSERT(ptr != nullptr);
error fail_state; error fail_state;
auto attached = exclusive_critical_section([&] { auto attached = exclusive_critical_section([&] {
if (getf(is_terminated_flag)) { if (getf(is_terminated_flag)) {
...@@ -60,6 +60,19 @@ size_t monitorable_actor::detach(const attachable::token& what) { ...@@ -60,6 +60,19 @@ size_t monitorable_actor::detach(const attachable::token& what) {
return detach_impl(what); return detach_impl(what);
} }
void monitorable_actor::unlink_from(const actor_addr& x) {
auto ptr = actor_cast<strong_actor_ptr>(x);
if (ptr != nullptr) {
if (ptr->get() != this)
remove_link(ptr->get());
} else {
default_attachable::observe_token tk{x, default_attachable::link};
exclusive_critical_section([&] {
detach_impl(tk, true);
});
}
}
bool monitorable_actor::cleanup(error&& reason, execution_unit* host) { bool monitorable_actor::cleanup(error&& reason, execution_unit* host) {
CAF_LOG_TRACE(CAF_ARG(reason)); CAF_LOG_TRACE(CAF_ARG(reason));
attachable_ptr head; attachable_ptr head;
...@@ -140,8 +153,8 @@ void monitorable_actor::remove_link(abstract_actor* x) { ...@@ -140,8 +153,8 @@ void monitorable_actor::remove_link(abstract_actor* x) {
CAF_LOG_TRACE(CAF_ARG(x)); CAF_LOG_TRACE(CAF_ARG(x));
default_attachable::observe_token tk{x->address(), default_attachable::link}; default_attachable::observe_token tk{x->address(), default_attachable::link};
joined_exclusive_critical_section(this, x, [&] { joined_exclusive_critical_section(this, x, [&] {
if (x->remove_backlink(this)) x->remove_backlink(this);
detach_impl(tk, true); detach_impl(tk, true);
}); });
} }
......
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