Skip to content

Commit

Permalink
relaxed signatures of link and monitor related member functions of cl…
Browse files Browse the repository at this point in the history
…ass actor
  • Loading branch information
Neverlord committed Aug 22, 2012
1 parent e94ebf0 commit 43f7550
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 68 deletions.
29 changes: 4 additions & 25 deletions cppa/actor.hpp
Expand Up @@ -127,51 +127,30 @@ class actor : public channel {
* @param other Actor instance that whose execution is coupled to the
* execution of this Actor.
*/
virtual void link_to(intrusive_ptr<actor>& other) = 0;
virtual void link_to(const intrusive_ptr<actor>& other) = 0;

/**
* @brief Unlinks this actor from @p other.
* @param other Linked Actor.
* @note Links are automatically removed if the Actor finishes execution.
*/
virtual void unlink_from(intrusive_ptr<actor>& other) = 0;
virtual void unlink_from(const intrusive_ptr<actor>& other) = 0;

/**
* @brief Establishes a link relation between this actor and @p other.
* @param other Actor instance that wants to link against this Actor.
* @returns @c true if this actor is running and added @p other to its
* list of linked actors; otherwise @c false.
*/
virtual bool establish_backlink(intrusive_ptr<actor>& other) = 0;
virtual bool establish_backlink(const intrusive_ptr<actor>& other) = 0;

/**
* @brief Removes a link relation between this actor and @p other.
* @param other Actor instance that wants to unlink from this Actor.
* @returns @c true if this actor is running and removed @p other
* from its list of linked actors; otherwise @c false.
*/
virtual bool remove_backlink(intrusive_ptr<actor>& other) = 0;

// rvalue support
/**
* @copydoc link_to(intrusive_ptr<actor>&)
*/
void link_to(intrusive_ptr<actor>&& other);

/**
* @copydoc :unlink_from(intrusive_ptr<actor>&)
*/
void unlink_from(intrusive_ptr<actor>&& other);

/**
* @copydoc remove_backlink(intrusive_ptr<actor>&)
*/
bool remove_backlink(intrusive_ptr<actor>&& other);

/**
* @copydoc establish_backlink(intrusive_ptr<actor>&)
*/
bool establish_backlink(intrusive_ptr<actor>&& other);
virtual bool remove_backlink(const intrusive_ptr<actor>& other) = 0;

/**
* @brief Gets the {@link process_information} of the parent process.
Expand Down
12 changes: 6 additions & 6 deletions cppa/actor_proxy.hpp
Expand Up @@ -57,21 +57,21 @@ class actor_proxy : public detail::abstract_actor<actor> {

void sync_enqueue(actor* sender, message_id_t id, any_tuple msg);

void link_to(intrusive_ptr<actor>& other);
void link_to(const intrusive_ptr<actor>& other);

// do not cause to send this actor an "UNLINK" message
// to the "original" remote actor
void local_link_to(intrusive_ptr<actor>& other);
void local_link_to(const intrusive_ptr<actor>& other);

void unlink_from(intrusive_ptr<actor>& other);
void unlink_from(const intrusive_ptr<actor>& other);

// do not cause to send this actor an "UNLINK" message
// to the "original" remote actor
void local_unlink_from(intrusive_ptr<actor>& other);
void local_unlink_from(const actor_ptr& other);

bool remove_backlink(intrusive_ptr<actor>& to);
bool remove_backlink(const intrusive_ptr<actor>& to);

bool establish_backlink(intrusive_ptr<actor>& to);
bool establish_backlink(const intrusive_ptr<actor>& to);

};

Expand Down
12 changes: 6 additions & 6 deletions cppa/detail/abstract_actor.hpp
Expand Up @@ -139,15 +139,15 @@ class abstract_actor : public abstract_actor_base<Base, std::is_base_of<local_ac
// uptr will be destroyed here, without locked mutex
}

void link_to(intrusive_ptr<actor>& other) { // override
void link_to(const intrusive_ptr<actor>& other) {
(void) link_to_impl(other);
}

void unlink_from(intrusive_ptr<actor>& other) { // override
void unlink_from(const intrusive_ptr<actor>& other) {
(void) unlink_from_impl(other);
}

bool remove_backlink(intrusive_ptr<actor>& other) { // override
bool remove_backlink(const intrusive_ptr<actor>& other) {
if (other && other != this) {
guard_type guard(m_mtx);
auto i = std::find(m_links.begin(), m_links.end(), other);
Expand All @@ -159,7 +159,7 @@ class abstract_actor : public abstract_actor_base<Base, std::is_base_of<local_ac
return false;
}

bool establish_backlink(intrusive_ptr<actor>& other) { // override
bool establish_backlink(const intrusive_ptr<actor>& other) {
std::uint32_t reason = exit_reason::not_exited;
if (other && other != this) {
guard_type guard(m_mtx);
Expand Down Expand Up @@ -252,7 +252,7 @@ class abstract_actor : public abstract_actor_base<Base, std::is_base_of<local_ac
}
}

bool link_to_impl(intrusive_ptr<actor>& other) {
bool link_to_impl(const intrusive_ptr<actor>& other) {
if (other && other != this) {
guard_type guard(m_mtx);
// send exit message if already exited
Expand All @@ -270,7 +270,7 @@ class abstract_actor : public abstract_actor_base<Base, std::is_base_of<local_ac
return false;
}

bool unlink_from_impl(intrusive_ptr<actor>& other) {
bool unlink_from_impl(const intrusive_ptr<actor>& other) {
guard_type guard(m_mtx);
// remove_backlink returns true if this actor is linked to other
if (other && !exited() && other->remove_backlink(this)) {
Expand Down
20 changes: 0 additions & 20 deletions src/actor.cpp
Expand Up @@ -78,24 +78,4 @@ actor::actor(const process_information_ptr& pptr)
}
}

void actor::link_to(intrusive_ptr<actor>&& other) {
intrusive_ptr<actor> tmp(std::move(other));
link_to(tmp);
}

void actor::unlink_from(intrusive_ptr<actor>&& other) {
intrusive_ptr<actor> tmp(std::move(other));
unlink_from(tmp);
}

bool actor::remove_backlink(intrusive_ptr<actor>&& to) {
intrusive_ptr<actor> tmp(std::move(to));
return remove_backlink(tmp);
}

bool actor::establish_backlink(intrusive_ptr<actor>&& to) {
intrusive_ptr<actor> tmp(std::move(to));
return establish_backlink(tmp);
}

} // namespace cppa
22 changes: 11 additions & 11 deletions src/actor_proxy.cpp
Expand Up @@ -35,6 +35,7 @@
#include "cppa/actor_proxy.hpp"
#include "cppa/exit_reason.hpp"
#include "cppa/detail/middleman.hpp"
#include "cppa/detail/types_array.hpp"
#include "cppa/detail/network_manager.hpp"
#include "cppa/detail/singleton_manager.hpp"

Expand All @@ -45,15 +46,14 @@ namespace cppa {
using detail::middleman_enqueue;

actor_proxy::actor_proxy(std::uint32_t mid, const process_information_ptr& pptr)
: super(mid, pptr) {
//attach(get_scheduler()->register_hidden_context());
}
: super(mid, pptr) { }

void actor_proxy::enqueue(actor* sender, any_tuple msg) {
auto& arr = detail::static_types_array<atom_value, std::uint32_t>::arr;
if ( msg.size() == 2
&& *(msg.type_at(0)) == typeid(atom_value)
&& msg.type_at(0) == arr[0]
&& msg.get_as<atom_value>(0) == atom("KILL_PROXY")
&& *(msg.type_at(1)) == typeid(std::uint32_t)) {
&& msg.type_at(1) == arr[1]) {
cleanup(msg.get_as<std::uint32_t>(1));
return;
}
Expand All @@ -64,7 +64,7 @@ void actor_proxy::sync_enqueue(actor* sender, message_id_t id, any_tuple msg) {
middleman_enqueue(parent_process_ptr(), sender, this, std::move(msg), id);
}

void actor_proxy::link_to(intrusive_ptr<actor>& other) {
void actor_proxy::link_to(const intrusive_ptr<actor>& other) {
if (link_to_impl(other)) {
// causes remote actor to link to (proxy of) other
middleman_enqueue(parent_process_ptr(),
Expand All @@ -74,11 +74,11 @@ void actor_proxy::link_to(intrusive_ptr<actor>& other) {
}
}

void actor_proxy::local_link_to(intrusive_ptr<actor>& other) {
void actor_proxy::local_link_to(const intrusive_ptr<actor>& other) {
link_to_impl(other);
}

void actor_proxy::unlink_from(intrusive_ptr<actor>& other) {
void actor_proxy::unlink_from(const intrusive_ptr<actor>& other) {
if (unlink_from_impl(other)) {
// causes remote actor to unlink from (proxy of) other
middleman_enqueue(parent_process_ptr(),
Expand All @@ -88,11 +88,11 @@ void actor_proxy::unlink_from(intrusive_ptr<actor>& other) {
}
}

void actor_proxy::local_unlink_from(intrusive_ptr<actor>& other) {
void actor_proxy::local_unlink_from(const intrusive_ptr<actor>& other) {
unlink_from_impl(other);
}

bool actor_proxy::establish_backlink(intrusive_ptr<actor>& other) {
bool actor_proxy::establish_backlink(const intrusive_ptr<actor>& other) {
bool result = super::establish_backlink(other);
if (result) {
// causes remote actor to unlink from (proxy of) other
Expand All @@ -104,7 +104,7 @@ bool actor_proxy::establish_backlink(intrusive_ptr<actor>& other) {
return result;
}

bool actor_proxy::remove_backlink(intrusive_ptr<actor>& other) {
bool actor_proxy::remove_backlink(const intrusive_ptr<actor>& other) {
bool result = super::remove_backlink(other);
if (result) {
middleman_enqueue(parent_process_ptr(),
Expand Down

0 comments on commit 43f7550

Please sign in to comment.