size_t abstract_actor::detach_impl(const attachable::token& what, attachable_ptr& ptr, bool stop_on_hit, bool dry_run) { CAF_LOGF_TRACE(""); if (! ptr) { CAF_LOGF_DEBUG("invalid ptr"); return 0; } if (ptr->matches(what)) { if (! dry_run) { CAF_LOGF_DEBUG("removed element"); attachable_ptr next; next.swap(ptr->next); ptr.swap(next); } return stop_on_hit ? 1 : 1 + detach_impl(what, ptr, stop_on_hit, dry_run); } return detach_impl(what, ptr->next, stop_on_hit, dry_run); }
void monitorable_actor::attach(attachable_ptr ptr) { CAF_LOG_TRACE(""); CAF_ASSERT(ptr != nullptr); error fail_state; auto attached = exclusive_critical_section([&] { if (getf(is_terminated_flag)) { fail_state = fail_state_; return false; } attach_impl(ptr); return true; }); CAF_LOG_DEBUG("cannot attach functor to terminated actor: call immediately"); if (!attached) ptr->actor_exited(fail_state, nullptr); }
void abstract_actor::attach(attachable_ptr ptr) { CAF_LOG_TRACE(""); if (ptr == nullptr) { return; } uint32_t reason; { // lifetime scope of guard guard_type guard{mtx_}; reason = exit_reason_; if (reason == exit_reason::not_exited) { attach_impl(ptr); return; } } CAF_LOG_DEBUG("cannot attach functor to terminated actor: call immediately"); ptr->actor_exited(this, reason); }
bool actor::attach(attachable_ptr ptr) { if (ptr == nullptr) { guard_type guard{m_mtx}; return m_exit_reason == exit_reason::not_exited; } std::uint32_t reason; { // lifetime scope of guard guard_type guard{m_mtx}; reason = m_exit_reason; if (reason == exit_reason::not_exited) { m_attachables.push_back(std::move(ptr)); return true; } } ptr->actor_exited(reason); return false; }
inline bool operator()(const attachable_ptr& ptr) const { return ptr->matches(observe_token{observer_, type_}); }
inline bool operator()(const attachable_ptr& ptr) { return ptr->matches(subscription_token{m_group}); }