Commit f4912f83 authored by neverlord's avatar neverlord

some refactoring

parent 791bf4c3
...@@ -138,7 +138,7 @@ class abstract_actor : public Base ...@@ -138,7 +138,7 @@ class abstract_actor : public Base
} }
for (attachable_ptr& ptr : mattachables) for (attachable_ptr& ptr : mattachables)
{ {
ptr->detach(reason); ptr->actor_exited(reason);
} }
} }
...@@ -186,7 +186,7 @@ class abstract_actor : public Base ...@@ -186,7 +186,7 @@ class abstract_actor : public Base
return true; return true;
} }
} }
uptr->detach(reason); uptr->actor_exited(reason);
return false; return false;
} }
} }
......
...@@ -225,7 +225,7 @@ class functor_attachable : public attachable ...@@ -225,7 +225,7 @@ class functor_attachable : public attachable
{ {
} }
void detach(std::uint32_t reason) void actor_exited(std::uint32_t reason)
{ {
m_functor(reason); m_functor(reason);
} }
......
...@@ -39,7 +39,7 @@ class attachable ...@@ -39,7 +39,7 @@ class attachable
* *
* The default implementation does nothing. * The default implementation does nothing.
*/ */
virtual void detach(std::uint32_t reason) = 0; virtual void actor_exited(std::uint32_t reason) = 0;
virtual bool matches(const token&) = 0; virtual bool matches(const token&) = 0;
......
...@@ -53,7 +53,7 @@ class group : public channel ...@@ -53,7 +53,7 @@ class group : public channel
~unsubscriber(); ~unsubscriber();
void detach(std::uint32_t); void actor_exited(std::uint32_t);
// matches on m_group // matches on m_group
bool matches(const attachable::token& what); bool matches(const attachable::token& what);
......
...@@ -7,6 +7,17 @@ ...@@ -7,6 +7,17 @@
namespace cppa { namespace cppa {
#ifdef CPPA_DOCUMENTATION
/**
* @brief Always points to the current actor. Similar to @c this in
* an object-oriented context.
*/
extern local_actor* self;
#else
// convertible<...> enables "actor_ptr this_actor = self;"
class self_type : public convertible<self_type, actor*> class self_type : public convertible<self_type, actor*>
{ {
...@@ -16,21 +27,26 @@ class self_type : public convertible<self_type, actor*> ...@@ -16,21 +27,26 @@ class self_type : public convertible<self_type, actor*>
static local_actor* get_impl(); static local_actor* get_impl();
self_type(const self_type&) = delete;
self_type& operator=(const self_type&) = delete;
public: public:
constexpr self_type() { }
// "inherited" from convertible<...>
inline local_actor* do_convert() const inline local_actor* do_convert() const
{ {
return get_impl(); return get_impl();
} }
constexpr self_type() { } // allow "self" wherever an local_actor or actor pointer is expected
inline operator local_actor*() const inline operator local_actor*() const
{ {
return get_impl(); return get_impl();
} }
inline local_actor* operator->() inline local_actor* operator->() const
{ {
return get_impl(); return get_impl();
} }
...@@ -42,31 +58,25 @@ class self_type : public convertible<self_type, actor*> ...@@ -42,31 +58,25 @@ class self_type : public convertible<self_type, actor*>
} }
// @pre get_unchecked() == nullptr // @pre get_unchecked() == nullptr
inline void set(local_actor* ptr) inline void set(local_actor* ptr) const
{ {
set_impl(ptr); set_impl(ptr);
} }
// @returns The current value without converting the calling context // @returns The current value without converting the calling context
// to an actor on-the-fly. // to an actor on-the-fly.
inline local_actor* unchecked() inline local_actor* unchecked() const
{ {
return get_unchecked_impl(); return get_unchecked_impl();
} }
}; };
#ifdef CPPA_DOCUMENTATION /*
* "self" emulates a new keyword. The object itself is useless, all it does
/** * is to provide syntactic sugar like "self->trap_exit(true)".
* @brief Always points to the current actor. Similar to @c this in
* an object-oriented context.
*/ */
extern local_actor* self; constexpr self_type self;
#else
extern self_type self;
#endif #endif
......
...@@ -12,7 +12,7 @@ class observer : public cppa::attachable ...@@ -12,7 +12,7 @@ class observer : public cppa::attachable
observer(cppa::actor_ptr&& client) : m_client(std::move(client)) { } observer(cppa::actor_ptr&& client) : m_client(std::move(client)) { }
void detach(std::uint32_t reason) void actor_exited(std::uint32_t reason)
{ {
using namespace cppa; using namespace cppa;
send(m_client, atom(":Down"), actor_ptr(self), reason); send(m_client, atom(":Down"), actor_ptr(self), reason);
......
...@@ -30,7 +30,7 @@ group::unsubscriber::~unsubscriber() ...@@ -30,7 +30,7 @@ group::unsubscriber::~unsubscriber()
if (m_group && m_self) m_group->unsubscribe(m_self); if (m_group && m_self) m_group->unsubscribe(m_self);
} }
void group::unsubscriber::detach(std::uint32_t) void group::unsubscriber::actor_exited(std::uint32_t)
{ {
// unsubscription is done in destructor // unsubscription is done in destructor
} }
......
...@@ -25,7 +25,7 @@ struct exit_observer : cppa::attachable ...@@ -25,7 +25,7 @@ struct exit_observer : cppa::attachable
{ {
cppa::detail::dec_actor_count(); cppa::detail::dec_actor_count();
} }
void detach(std::uint32_t) void actor_exited(std::uint32_t)
{ {
} }
bool matches(const token&) bool matches(const token&)
......
...@@ -29,7 +29,7 @@ boost::thread_specific_ptr<cppa::local_actor> t_this_context(cleanup_fun); ...@@ -29,7 +29,7 @@ boost::thread_specific_ptr<cppa::local_actor> t_this_context(cleanup_fun);
namespace cppa { namespace cppa {
self_type self; //self_type self;
void self_type::set_impl(local_actor* ptr) void self_type::set_impl(local_actor* ptr)
{ {
......
...@@ -307,6 +307,15 @@ size_t test__spawn() ...@@ -307,6 +307,15 @@ size_t test__spawn()
CPPA_CHECK_EQUAL(behavior_test<testee_actor>(), "init_state"); CPPA_CHECK_EQUAL(behavior_test<testee_actor>(), "init_state");
CPPA_CHECK_EQUAL(behavior_test<event_testee>(), "init_state"); CPPA_CHECK_EQUAL(behavior_test<event_testee>(), "init_state");
// create one million actors linked to one single actor
// and kill them all through killing the link
auto my_link = spawn(new event_testee);
for (int i = 0; i < 20000; ++i)
{
link(my_link, spawn(new event_testee));
}
send(my_link, atom(":Exit"), exit_reason::user_defined);
return CPPA_TEST_RESULT; return CPPA_TEST_RESULT;
......
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