Commit 51494159 authored by Dominik Charousset's avatar Dominik Charousset

re-renamed untyped_actor -> event_based_actor

with this patch, untyped_actor is called event_based_actor once more
and blocking_untyped_actor has been renamed to blocking_actor;
reason to this is, that untyped_actor is too general, as there
are several other classes that are indeed untyped actors but do not
inherit from event_based_actor (e.g. io::broker, actor_proxy)
parent e94c2c79
...@@ -147,7 +147,7 @@ set(LIBCPPA_SRC ...@@ -147,7 +147,7 @@ set(LIBCPPA_SRC
src/binary_serializer.cpp src/binary_serializer.cpp
src/broker.cpp src/broker.cpp
src/buffer.cpp src/buffer.cpp
src/blocking_untyped_actor.cpp src/blocking_actor.cpp
src/channel.cpp src/channel.cpp
src/context_switching_resume.cpp src/context_switching_resume.cpp
src/continuable.cpp src/continuable.cpp
...@@ -159,6 +159,7 @@ set(LIBCPPA_SRC ...@@ -159,6 +159,7 @@ set(LIBCPPA_SRC
src/deserializer.cpp src/deserializer.cpp
src/duration.cpp src/duration.cpp
src/empty_tuple.cpp src/empty_tuple.cpp
src/event_based_actor.cpp
src/exception.cpp src/exception.cpp
src/exit_reason.cpp src/exit_reason.cpp
src/fd_util.cpp src/fd_util.cpp
...@@ -206,7 +207,6 @@ set(LIBCPPA_SRC ...@@ -206,7 +207,6 @@ set(LIBCPPA_SRC
src/uniform_type_info.cpp src/uniform_type_info.cpp
src/uniform_type_info_map.cpp src/uniform_type_info_map.cpp
src/untyped_actor_handle.cpp src/untyped_actor_handle.cpp
src/untyped_actor.cpp
src/weak_ptr_anchor.cpp src/weak_ptr_anchor.cpp
src/yield_interface.cpp) src/yield_interface.cpp)
......
...@@ -13,7 +13,7 @@ cppa/attachable.hpp ...@@ -13,7 +13,7 @@ cppa/attachable.hpp
cppa/behavior.hpp cppa/behavior.hpp
cppa/binary_deserializer.hpp cppa/binary_deserializer.hpp
cppa/binary_serializer.hpp cppa/binary_serializer.hpp
cppa/blocking_untyped_actor.hpp cppa/blocking_actor.hpp
cppa/channel.hpp cppa/channel.hpp
cppa/untyped_actor_handle.hpp cppa/untyped_actor_handle.hpp
cppa/config.hpp cppa/config.hpp
...@@ -155,7 +155,7 @@ cppa/typed_actor_ptr.hpp ...@@ -155,7 +155,7 @@ cppa/typed_actor_ptr.hpp
cppa/typed_behavior.hpp cppa/typed_behavior.hpp
cppa/uniform_type_info.hpp cppa/uniform_type_info.hpp
cppa/unit.hpp cppa/unit.hpp
cppa/untyped_actor.hpp cppa/event_based_actor.hpp
cppa/util/abstract_uniform_type_info.hpp cppa/util/abstract_uniform_type_info.hpp
cppa/util/algorithm.hpp cppa/util/algorithm.hpp
cppa/util/arg_match_t.hpp cppa/util/arg_match_t.hpp
...@@ -332,9 +332,9 @@ cppa/behavior_stack_based.hpp ...@@ -332,9 +332,9 @@ cppa/behavior_stack_based.hpp
cppa/resumable.hpp cppa/resumable.hpp
src/resumable.cpp src/resumable.cpp
cppa/policy/middleman_scheduling.hpp cppa/policy/middleman_scheduling.hpp
src/untyped_actor.cpp src/event_based_actor.cpp
src/functor_based_blocking_actor.cpp src/functor_based_blocking_actor.cpp
src/blocking_untyped_actor.cpp src/blocking_actor.cpp
cppa/policy/policies.hpp cppa/policy/policies.hpp
cppa/detail/response_future_util.hpp cppa/detail/response_future_util.hpp
cppa/system_messages.hpp cppa/system_messages.hpp
......
...@@ -60,6 +60,7 @@ class deserializer; ...@@ -60,6 +60,7 @@ class deserializer;
*/ */
typedef std::uint32_t actor_id; typedef std::uint32_t actor_id;
class actor;
class abstract_actor; class abstract_actor;
typedef intrusive_ptr<abstract_actor> abstract_actor_ptr; typedef intrusive_ptr<abstract_actor> abstract_actor_ptr;
...@@ -101,6 +102,9 @@ class abstract_actor : public abstract_channel { ...@@ -101,6 +102,9 @@ class abstract_actor : public abstract_channel {
*/ */
virtual void link_to(const actor_addr& other); virtual void link_to(const actor_addr& other);
void link_to(const actor& whom);
/** /**
* @brief Unlinks this actor from @p other. * @brief Unlinks this actor from @p other.
* @param other Linked Actor. * @param other Linked Actor.
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <utility>
#include <type_traits> #include <type_traits>
#include "cppa/intrusive_ptr.hpp" #include "cppa/intrusive_ptr.hpp"
...@@ -44,9 +45,12 @@ ...@@ -44,9 +45,12 @@
namespace cppa { namespace cppa {
class actor_addr;
class actor_proxy; class actor_proxy;
class untyped_actor; class blocking_actor;
class blocking_untyped_actor; class event_based_actor;
struct invalid_actor_addr_t;
namespace io { namespace io {
class broker; class broker;
...@@ -58,20 +62,36 @@ class raw_access; ...@@ -58,20 +62,36 @@ class raw_access;
struct invalid_actor_t { constexpr invalid_actor_t() { } }; struct invalid_actor_t { constexpr invalid_actor_t() { } };
/**
* @brief Identifies an invalid {@link actor}.
* @relates actor
*/
constexpr invalid_actor_t invalid_actor = invalid_actor_t{}; constexpr invalid_actor_t invalid_actor = invalid_actor_t{};
/** /**
* @brief Identifies an untyped actor. * @brief Identifies an untyped actor.
*
* Can be used with derived types of {@link event_based_actor},
* {@link blocking_actor}, {@link actor_proxy}, or
* {@link io::broker}.
*/ */
class actor : util::comparable<actor> { class actor : util::comparable<actor>
, util::comparable<actor, actor_addr>
, util::comparable<actor, invalid_actor_t>
, util::comparable<actor, invalid_actor_addr_t> {
friend class detail::raw_access; friend class detail::raw_access;
public: public:
/**
* @brief Extends {@link untyped_actor_handle} to grant
* access to the enqueue member function.
*/
class handle : public untyped_actor_handle {
// untyped_actor_handle does not provide a virtual destructor // untyped_actor_handle does not provide a virtual destructor
// -> no new members // -> no new members
class handle : public untyped_actor_handle {
friend class actor; friend class actor;
...@@ -81,6 +101,9 @@ class actor : util::comparable<actor> { ...@@ -81,6 +101,9 @@ class actor : util::comparable<actor> {
handle() = default; handle() = default;
/**
* @brief Enqueues @p msg to the receiver specified in @p hdr.
*/
void enqueue(const message_header& hdr, any_tuple msg) const; void enqueue(const message_header& hdr, any_tuple msg) const;
private: private:
...@@ -91,55 +114,114 @@ class actor : util::comparable<actor> { ...@@ -91,55 +114,114 @@ class actor : util::comparable<actor> {
actor() = default; actor() = default;
actor(actor&&) = default;
actor(const actor&) = default;
template<typename T> template<typename T>
actor(intrusive_ptr<T> ptr, actor(intrusive_ptr<T> ptr,
typename std::enable_if< typename std::enable_if<
std::is_base_of<io::broker, T>::value std::is_base_of<io::broker, T>::value
|| std::is_base_of<actor_proxy, T>::value || std::is_base_of<actor_proxy, T>::value
|| std::is_base_of<untyped_actor, T>::value || std::is_base_of<blocking_actor, T>::value
|| std::is_base_of<blocking_untyped_actor, T>::value || std::is_base_of<event_based_actor, T>::value
>::type* = 0)
: m_ops(std::move(ptr)) { }
template<typename T>
actor(T* ptr,
typename std::enable_if<
std::is_base_of<io::broker, T>::value
|| std::is_base_of<actor_proxy, T>::value
|| std::is_base_of<event_based_actor, T>::value
|| std::is_base_of<blocking_actor, T>::value
>::type* = 0) >::type* = 0)
: m_ops(ptr) { } : m_ops(ptr) { }
actor(const std::nullptr_t&); actor(const invalid_actor_t&);
actor(actor_proxy*); actor& operator=(actor&&) = default;
actor(untyped_actor*); actor& operator=(const actor&) = default;
actor(blocking_untyped_actor*); template<typename T>
typename std::enable_if<
std::is_base_of<io::broker, T>::value
|| std::is_base_of<actor_proxy, T>::value
|| std::is_base_of<event_based_actor, T>::value
|| std::is_base_of<blocking_actor, T>::value,
actor&
>::type
operator=(intrusive_ptr<T> ptr) {
actor tmp{std::move(ptr)};
swap(tmp);
return *this;
}
actor(const invalid_actor_t&); template<typename T>
typename std::enable_if<
std::is_base_of<io::broker, T>::value
|| std::is_base_of<actor_proxy, T>::value
|| std::is_base_of<event_based_actor, T>::value
|| std::is_base_of<blocking_actor, T>::value,
actor&
>::type
operator=(T* ptr) {
actor tmp{ptr};
swap(tmp);
return *this;
}
actor& operator=(const invalid_actor_t&);
inline operator bool() const {
return static_cast<bool>(m_ops.m_ptr);
}
explicit inline operator bool() const; inline bool operator!() const {
return !static_cast<bool>(m_ops.m_ptr);
}
inline bool operator!() const; /**
* @brief Queries whether this handle is valid, i.e., points
* to an instance of an untyped actor.
*/
inline bool valid() const {
return static_cast<bool>(m_ops.m_ptr);
}
/**
* @brief Returns a handle that grants access to
* actor operations such as enqueue.
*/
inline const handle* operator->() const { inline const handle* operator->() const {
// this const cast is safe, because untyped_actor_handle cannot be
// modified anyways and the offered operations are intended to
// be called on const elements
return &m_ops; return &m_ops;
} }
inline const handle& operator*() const {
return m_ops;
}
intptr_t compare(const actor& other) const; intptr_t compare(const actor& other) const;
intptr_t compare(const invalid_actor_t&) const;
intptr_t compare(const actor_addr&) const;
inline intptr_t compare(const invalid_actor_addr_t&) const {
return compare(invalid_actor);
}
private: private:
void swap(actor& other);
actor(abstract_actor*); actor(abstract_actor*);
handle m_ops; handle m_ops;
}; };
inline actor::operator bool() const {
return static_cast<bool>(m_ops.m_ptr);
}
inline bool actor::operator!() const {
return !static_cast<bool>(*this);
}
} // namespace cppa } // namespace cppa
#endif // CPPA_ACTOR_HPP #endif // CPPA_ACTOR_HPP
...@@ -43,18 +43,23 @@ ...@@ -43,18 +43,23 @@
namespace cppa { namespace cppa {
class actor;
class local_actor; class local_actor;
class actor_namespace; class actor_namespace;
namespace detail { class raw_access; } namespace detail { class raw_access; }
/**
* @brief Identifies an invalid {@link actor_addr}.
* @relates actor_addr
*/
struct invalid_actor_addr_t { constexpr invalid_actor_addr_t() { } }; struct invalid_actor_addr_t { constexpr invalid_actor_addr_t() { } };
constexpr invalid_actor_addr_t invalid_actor_addr = invalid_actor_addr_t{}; constexpr invalid_actor_addr_t invalid_actor_addr = invalid_actor_addr_t{};
/**
* @brief Stores the address of typed as well as untyped actors.
*/
class actor_addr : util::comparable<actor_addr> class actor_addr : util::comparable<actor_addr>
, util::comparable<actor_addr, actor>
, util::comparable<actor_addr, abstract_actor*> , util::comparable<actor_addr, abstract_actor*>
, util::comparable<actor_addr, abstract_actor_ptr> { , util::comparable<actor_addr, abstract_actor_ptr> {
...@@ -64,37 +69,45 @@ class actor_addr : util::comparable<actor_addr> ...@@ -64,37 +69,45 @@ class actor_addr : util::comparable<actor_addr>
public: public:
actor_addr() = default; actor_addr() = default;
actor_addr(actor_addr&&) = default; actor_addr(actor_addr&&) = default;
actor_addr(const actor_addr&) = default; actor_addr(const actor_addr&) = default;
actor_addr& operator=(actor_addr&&) = default; actor_addr& operator=(actor_addr&&) = default;
actor_addr& operator=(const actor_addr&) = default;
actor_addr(const actor&); actor_addr& operator=(const actor_addr&) = default;
actor_addr& operator=(const actor&);
actor_addr(const invalid_actor_addr_t&); actor_addr(const invalid_actor_addr_t&);
actor_addr operator=(const invalid_actor_addr_t&); actor_addr operator=(const invalid_actor_addr_t&);
explicit operator bool() const; inline explicit operator bool() const {
bool operator!() const; return valid();
}
inline bool operator!() const {
return !valid();
}
inline bool valid() const { inline bool valid() const {
return static_cast<bool>(*this); return m_ops.valid();
} }
intptr_t compare(const actor& other) const;
intptr_t compare(const actor_addr& other) const; intptr_t compare(const actor_addr& other) const;
intptr_t compare(const abstract_actor* other) const; intptr_t compare(const abstract_actor* other) const;
inline intptr_t compare(const abstract_actor_ptr& other) const { inline intptr_t compare(const abstract_actor_ptr& other) const {
return compare(other.get()); return compare(other.get());
} }
inline untyped_actor_handle* operator->() const { inline const untyped_actor_handle* operator->() const {
// this const cast is safe, because untyped_actor_handle cannot be return &m_ops;
// modified anyways and the offered operations are intended to }
// be called on const elements
return const_cast<untyped_actor_handle*>(&m_ops); inline const untyped_actor_handle& operator*() const {
return m_ops;
} }
private: private:
......
...@@ -41,14 +41,14 @@ namespace cppa { ...@@ -41,14 +41,14 @@ namespace cppa {
#ifdef CPPA_DOCUMENTATION #ifdef CPPA_DOCUMENTATION
/** /**
* @brief Policy tag that causes {@link untyped_actor::become} to * @brief Policy tag that causes {@link event_based_actor::become} to
* discard the current behavior. * discard the current behavior.
* @relates local_actor * @relates local_actor
*/ */
constexpr auto discard_behavior; constexpr auto discard_behavior;
/** /**
* @brief Policy tag that causes {@link untyped_actor::become} to * @brief Policy tag that causes {@link event_based_actor::become} to
* keep the current behavior available. * keep the current behavior available.
* @relates local_actor * @relates local_actor
*/ */
......
...@@ -45,7 +45,7 @@ namespace cppa { ...@@ -45,7 +45,7 @@ namespace cppa {
/** /**
* @extends local_actor * @extends local_actor
*/ */
class blocking_untyped_actor : public extend<local_actor>::with<mailbox_based> { class blocking_actor : public extend<local_actor>::with<mailbox_based> {
public: public:
...@@ -89,14 +89,13 @@ class blocking_untyped_actor : public extend<local_actor>::with<mailbox_based> { ...@@ -89,14 +89,13 @@ class blocking_untyped_actor : public extend<local_actor>::with<mailbox_based> {
response_future(const response_future&) = default; response_future(const response_future&) = default;
response_future& operator=(const response_future&) = default; response_future& operator=(const response_future&) = default;
inline response_future(const message_id& from, inline response_future(const message_id& from, blocking_actor* self)
blocking_untyped_actor* self)
: m_mid(from), m_self(self) { } : m_mid(from), m_self(self) { }
private: private:
message_id m_mid; message_id m_mid;
blocking_untyped_actor* m_self; blocking_actor* m_self;
}; };
...@@ -153,7 +152,8 @@ class blocking_untyped_actor : public extend<local_actor>::with<mailbox_based> { ...@@ -153,7 +152,8 @@ class blocking_untyped_actor : public extend<local_actor>::with<mailbox_based> {
const util::duration& rtime, const util::duration& rtime,
Ts&&... what) { Ts&&... what) {
static_assert(sizeof...(Ts) > 0, "no message to send"); static_assert(sizeof...(Ts) > 0, "no message to send");
return timed_sync_send_tuple(rtime, dest, make_any_tuple(std::forward<Ts>(what)...)); return timed_sync_send_tuple(rtime, dest,
make_any_tuple(std::forward<Ts>(what)...));
} }
typedef std::chrono::high_resolution_clock::time_point timeout_type; typedef std::chrono::high_resolution_clock::time_point timeout_type;
...@@ -207,7 +207,7 @@ class blocking_untyped_actor : public extend<local_actor>::with<mailbox_based> { ...@@ -207,7 +207,7 @@ class blocking_untyped_actor : public extend<local_actor>::with<mailbox_based> {
*/ */
template<typename... Ts> template<typename... Ts>
void receive(Ts&&... args) { void receive(Ts&&... args) {
static_assert(sizeof...(Ts), "receive() requires at least one argument"); static_assert(sizeof...(Ts), "at least one argument required");
dequeue(match_expr_convert(std::forward<Ts>(args)...)); dequeue(match_expr_convert(std::forward<Ts>(args)...));
} }
...@@ -282,7 +282,8 @@ class blocking_untyped_actor : public extend<local_actor>::with<mailbox_based> { ...@@ -282,7 +282,8 @@ class blocking_untyped_actor : public extend<local_actor>::with<mailbox_based> {
/** /**
* @brief Receives messages until @p stmt returns true. * @brief Receives messages until @p stmt returns true.
* *
* Semantically equal to: <tt>do { receive(...); } while (stmt() == false);</tt> * Semantically equal to:
* <tt>do { receive(...); } while (stmt() == false);</tt>
* *
* <b>Usage example:</b> * <b>Usage example:</b>
* @code * @code
......
...@@ -47,10 +47,7 @@ struct invalid_actor_t; ...@@ -47,10 +47,7 @@ struct invalid_actor_t;
namespace detail { class raw_access; } namespace detail { class raw_access; }
/** /**
* @brief Interface for all message receivers. * @brief A handle to instances of {@link abstract_channel}.
*
* This interface describes an entity that can receive messages
* and is implemented by {@link actor} and {@link group}.
*/ */
class channel : util::comparable<channel> class channel : util::comparable<channel>
, util::comparable<channel, actor> , util::comparable<channel, actor>
...@@ -64,12 +61,14 @@ class channel : util::comparable<channel> ...@@ -64,12 +61,14 @@ class channel : util::comparable<channel>
channel(const actor&); channel(const actor&);
channel(const std::nullptr_t&);
channel(const invalid_actor_t&); channel(const invalid_actor_t&);
template<typename T> template<typename T>
channel(intrusive_ptr<T> ptr, typename std::enable_if<std::is_base_of<abstract_channel, T>::value>::type* = 0) : m_ptr(ptr) { } channel(intrusive_ptr<T> ptr,
typename std::enable_if<
std::is_base_of<abstract_channel, T>::value
>::type* = 0)
: m_ptr(ptr) { }
channel(abstract_channel* ptr); channel(abstract_channel* ptr);
...@@ -85,7 +84,8 @@ class channel : util::comparable<channel> ...@@ -85,7 +84,8 @@ class channel : util::comparable<channel>
intptr_t compare(const abstract_channel* other) const; intptr_t compare(const abstract_channel* other) const;
static intptr_t compare(const abstract_channel* lhs, const abstract_channel* rhs); static intptr_t compare(const abstract_channel* lhs,
const abstract_channel* rhs);
private: private:
......
...@@ -58,11 +58,11 @@ ...@@ -58,11 +58,11 @@
#include "cppa/scoped_actor.hpp" #include "cppa/scoped_actor.hpp"
#include "cppa/spawn_options.hpp" #include "cppa/spawn_options.hpp"
#include "cppa/actor_ostream.hpp" #include "cppa/actor_ostream.hpp"
#include "cppa/untyped_actor.hpp"
#include "cppa/abstract_actor.hpp" #include "cppa/abstract_actor.hpp"
#include "cppa/blocking_actor.hpp"
#include "cppa/system_messages.hpp" #include "cppa/system_messages.hpp"
#include "cppa/response_promise.hpp" #include "cppa/response_promise.hpp"
#include "cppa/blocking_untyped_actor.hpp" #include "cppa/event_based_actor.hpp"
#include "cppa/util/type_traits.hpp" #include "cppa/util/type_traits.hpp"
...@@ -459,10 +459,15 @@ inline void anon_send(const channel& receiver, Ts&&... args) { ...@@ -459,10 +459,15 @@ inline void anon_send(const channel& receiver, Ts&&... args) {
anon_send_tuple(receiver, make_any_tuple(std::forward<Ts>(args)...)); anon_send_tuple(receiver, make_any_tuple(std::forward<Ts>(args)...));
} }
inline void anon_send_exit(const actor_addr&, std::uint32_t) { // implemented in local_actor.cpp
void anon_send_exit(const actor_addr& whom, std::uint32_t reason);
inline void anon_send_exit(const actor& whom, std::uint32_t reason) {
whom->enqueue({invalid_actor_addr, whom, message_id{}.with_high_priority()},
make_any_tuple(exit_msg{invalid_actor_addr, reason}));
} }
/** /**
* @brief Blocks execution of this actor until all * @brief Blocks execution of this actor until all
* other actors finished execution. * other actors finished execution.
......
...@@ -45,13 +45,13 @@ class any_tuple; ...@@ -45,13 +45,13 @@ class any_tuple;
class actor_addr; class actor_addr;
class actor_proxy; class actor_proxy;
class scoped_actor; class scoped_actor;
class untyped_actor;
class abstract_actor; class abstract_actor;
class blocking_actor;
class message_header; class message_header;
class partial_function; class partial_function;
class uniform_type_info; class uniform_type_info;
class event_based_actor;
class primitive_variant; class primitive_variant;
class blocking_untyped_actor;
// structs // structs
struct anything; struct anything;
......
...@@ -33,21 +33,21 @@ ...@@ -33,21 +33,21 @@
#include <type_traits> #include <type_traits>
#include "cppa/untyped_actor.hpp" #include "cppa/event_based_actor.hpp"
namespace cppa { namespace detail { namespace cppa { namespace detail {
class functor_based_actor : public untyped_actor { class functor_based_actor : public event_based_actor {
public: public:
typedef std::function<behavior(untyped_actor*)> make_behavior_fun; typedef std::function<behavior(event_based_actor*)> make_behavior_fun;
typedef std::function<void(untyped_actor*)> void_fun; typedef std::function<void(event_based_actor*)> void_fun;
template<typename F, typename... Ts> template<typename F, typename... Ts>
functor_based_actor(F f, Ts&&... vs) { functor_based_actor(F f, Ts&&... vs) {
untyped_actor* dummy = nullptr; event_based_actor* dummy = nullptr;
create(dummy, f, std::forward<Ts>(vs)...); create(dummy, f, std::forward<Ts>(vs)...);
} }
...@@ -55,7 +55,7 @@ class functor_based_actor : public untyped_actor { ...@@ -55,7 +55,7 @@ class functor_based_actor : public untyped_actor {
private: private:
void create(untyped_actor*, void_fun); void create(event_based_actor*, void_fun);
template<class Actor, typename F, typename... Ts> template<class Actor, typename F, typename... Ts>
auto create(Actor*, F f, Ts&&... vs) -> auto create(Actor*, F f, Ts&&... vs) ->
......
...@@ -31,20 +31,20 @@ ...@@ -31,20 +31,20 @@
#ifndef FUNCTOR_BASED_BLOCKING_ACTOR_HPP #ifndef FUNCTOR_BASED_BLOCKING_ACTOR_HPP
#define FUNCTOR_BASED_BLOCKING_ACTOR_HPP #define FUNCTOR_BASED_BLOCKING_ACTOR_HPP
#include "cppa/blocking_untyped_actor.hpp" #include "cppa/blocking_actor.hpp"
namespace cppa { namespace cppa {
namespace detail { namespace detail {
class functor_based_blocking_actor : public blocking_untyped_actor { class functor_based_blocking_actor : public blocking_actor {
public: public:
typedef std::function<void (blocking_untyped_actor*)> act_fun; typedef std::function<void (blocking_actor*)> act_fun;
template<typename F, typename... Ts> template<typename F, typename... Ts>
functor_based_blocking_actor(F f, Ts&&... vs) { functor_based_blocking_actor(F f, Ts&&... vs) {
blocking_untyped_actor* dummy = nullptr; blocking_actor* dummy = nullptr;
create(dummy, f, std::forward<Ts>(vs)...); create(dummy, f, std::forward<Ts>(vs)...);
} }
...@@ -54,7 +54,7 @@ class functor_based_blocking_actor : public blocking_untyped_actor { ...@@ -54,7 +54,7 @@ class functor_based_blocking_actor : public blocking_untyped_actor {
private: private:
void create(blocking_untyped_actor*, act_fun); void create(blocking_actor*, act_fun);
template<class Actor, typename F, typename T0, typename... Ts> template<class Actor, typename F, typename T0, typename... Ts>
auto create(Actor* dummy, F f, T0&& v0, Ts&&... vs) -> auto create(Actor* dummy, F f, T0&& v0, Ts&&... vs) ->
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#include "cppa/logging.hpp" #include "cppa/logging.hpp"
#include "cppa/resumable.hpp" #include "cppa/resumable.hpp"
#include "cppa/blocking_actor.hpp"
#include "cppa/mailbox_element.hpp" #include "cppa/mailbox_element.hpp"
#include "cppa/blocking_untyped_actor.hpp"
#include "cppa/policy/scheduling_policy.hpp" #include "cppa/policy/scheduling_policy.hpp"
...@@ -152,7 +152,7 @@ class proper_actor_base : public Policies::resume_policy::template mixin<Base, D ...@@ -152,7 +152,7 @@ class proper_actor_base : public Policies::resume_policy::template mixin<Base, D
template<class Base, template<class Base,
class Policies, class Policies,
bool OverrideDequeue = std::is_base_of<blocking_untyped_actor, Base>::value> bool OverrideDequeue = std::is_base_of<blocking_actor, Base>::value>
class proper_actor : public proper_actor_base<Base, class proper_actor : public proper_actor_base<Base,
proper_actor<Base, proper_actor<Base,
Policies, Policies,
...@@ -201,10 +201,10 @@ class proper_actor : public proper_actor_base<Base, ...@@ -201,10 +201,10 @@ class proper_actor : public proper_actor_base<Base,
CPPA_LOG_DEBUG(std::distance(this->cache_begin(), e) CPPA_LOG_DEBUG(std::distance(this->cache_begin(), e)
<< " elements in cache"); << " elements in cache");
for (auto i = this->cache_begin(); i != e; ++i) { for (auto i = this->cache_begin(); i != e; ++i) {
auto res = this->invoke_policy().invoke_message(this, *i, bhvr, mid); auto im = this->invoke_policy().invoke_message(this, *i, bhvr, mid);
if (res || !*i) { if (im || !*i) {
this->cache_erase(i); this->cache_erase(i);
if (res) return true; if (im) return true;
// start anew, because we have invalidated our iterators now // start anew, because we have invalidated our iterators now
return invoke_message_from_cache(); return invoke_message_from_cache();
} }
...@@ -244,7 +244,7 @@ class proper_actor<Base, Policies,true> : public proper_actor_base<Base, ...@@ -244,7 +244,7 @@ class proper_actor<Base, Policies,true> : public proper_actor_base<Base,
this->scheduling_policy().launch(this, is_hidden); this->scheduling_policy().launch(this, is_hidden);
} }
// implement blocking_untyped_actor::dequeue_response // implement blocking_actor::dequeue_response
void dequeue_response(behavior& bhvr, message_id mid) override { void dequeue_response(behavior& bhvr, message_id mid) override {
// try to dequeue from cache first // try to dequeue from cache first
......
...@@ -65,12 +65,6 @@ class raw_access { ...@@ -65,12 +65,6 @@ class raw_access {
}; };
// utility function to get raw access + cast to a related type in one call
template<typename T>
T* actor_addr_cast(const actor_addr& hdl) {
return static_cast<T*>(raw_access::get(hdl));
}
} } // namespace cppa::detail } } // namespace cppa::detail
#endif // CPPA_RAW_ACCESS_HPP #endif // CPPA_RAW_ACCESS_HPP
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
namespace cppa { namespace cppa {
class untyped_actor; class event_based_actor;
class continue_helper { class continue_helper {
...@@ -50,7 +50,7 @@ class continue_helper { ...@@ -50,7 +50,7 @@ class continue_helper {
typedef int message_id_wrapper_tag; typedef int message_id_wrapper_tag;
inline continue_helper(message_id mid, untyped_actor* self) inline continue_helper(message_id mid, event_based_actor* self)
: m_mid(mid), m_self(self) { } : m_mid(mid), m_self(self) { }
template<typename F> template<typename F>
...@@ -69,15 +69,15 @@ class continue_helper { ...@@ -69,15 +69,15 @@ class continue_helper {
private: private:
message_id m_mid; message_id m_mid;
untyped_actor* m_self; event_based_actor* m_self;
}; };
/** /**
* @extends local_actor * @extends local_actor
*/ */
class untyped_actor : public extend<local_actor>::with<mailbox_based, class event_based_actor : public extend<local_actor>::
behavior_stack_based> { with<mailbox_based, behavior_stack_based> {
protected: protected:
...@@ -124,13 +124,13 @@ class untyped_actor : public extend<local_actor>::with<mailbox_based, ...@@ -124,13 +124,13 @@ class untyped_actor : public extend<local_actor>::with<mailbox_based,
response_future& operator=(const response_future&) = default; response_future& operator=(const response_future&) = default;
inline response_future(const message_id& from, untyped_actor* self) inline response_future(const message_id& from, event_based_actor* self)
: m_mid(from), m_self(self) { } : m_mid(from), m_self(self) { }
private: private:
message_id m_mid; message_id m_mid;
untyped_actor* m_self; event_based_actor* m_self;
inline void check_consistency() { } inline void check_consistency() { }
...@@ -173,7 +173,8 @@ class untyped_actor : public extend<local_actor>::with<mailbox_based, ...@@ -173,7 +173,8 @@ class untyped_actor : public extend<local_actor>::with<mailbox_based,
const util::duration& rtime, const util::duration& rtime,
Ts&&... what) { Ts&&... what) {
static_assert(sizeof...(Ts) > 0, "no message to send"); static_assert(sizeof...(Ts) > 0, "no message to send");
return timed_sync_send_tuple(rtime, dest, make_any_tuple(std::forward<Ts>(what)...)); return timed_sync_send_tuple(rtime, dest,
make_any_tuple(std::forward<Ts>(what)...));
} }
}; };
......
...@@ -162,7 +162,8 @@ class middleman { ...@@ -162,7 +162,8 @@ class middleman {
* to the event loop of the middleman. * to the event loop of the middleman.
* @note This member function is thread-safe. * @note This member function is thread-safe.
*/ */
virtual void register_acceptor(const actor_addr& pa, peer_acceptor* ptr) = 0; virtual void register_acceptor(const actor_addr& pa,
peer_acceptor* ptr) = 0;
/** /**
* @brief Returns the namespace that contains all remote actors * @brief Returns the namespace that contains all remote actors
......
...@@ -170,6 +170,10 @@ class local_actor : public extend<abstract_actor>::with<memory_cached> { ...@@ -170,6 +170,10 @@ class local_actor : public extend<abstract_actor>::with<memory_cached> {
void send_exit(const actor_addr& whom, std::uint32_t reason); void send_exit(const actor_addr& whom, std::uint32_t reason);
inline void send_exit(const actor& whom, std::uint32_t reason) {
send_exit(whom->address(), reason);
}
/** /**
* @brief Sends a message to @p whom that is delayed by @p rel_time. * @brief Sends a message to @p whom that is delayed by @p rel_time.
* @param whom Receiver of the message. * @param whom Receiver of the message.
......
...@@ -67,7 +67,7 @@ class context_switching_resume { ...@@ -67,7 +67,7 @@ class context_switching_resume {
mixin(Ts&&... args) mixin(Ts&&... args)
: Base(std::forward<Ts>(args)...) : Base(std::forward<Ts>(args)...)
, m_fiber(context_switching_resume::trampoline, , m_fiber(context_switching_resume::trampoline,
static_cast<blocking_untyped_actor*>(this)) { } static_cast<blocking_actor*>(this)) { }
resumable::resume_result resume(util::fiber* from) override { resumable::resume_result resume(util::fiber* from) override {
CPPA_REQUIRE(from != nullptr); CPPA_REQUIRE(from != nullptr);
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include <type_traits> #include <type_traits>
#include "cppa/util/dptr.hpp" #include "cppa/util/dptr.hpp"
#include "cppa/untyped_actor.hpp" #include "cppa/event_based_actor.hpp"
namespace cppa { namespace cppa {
...@@ -45,11 +45,11 @@ namespace cppa { ...@@ -45,11 +45,11 @@ namespace cppa {
* to initialize the derived actor with its @p init_state member. * to initialize the derived actor with its @p init_state member.
* @tparam Derived Direct subclass of @p sb_actor. * @tparam Derived Direct subclass of @p sb_actor.
*/ */
template<class Derived, class Base = untyped_actor> template<class Derived, class Base = event_based_actor>
class sb_actor : public Base { class sb_actor : public Base {
static_assert(std::is_base_of<untyped_actor, Base>::value, static_assert(std::is_base_of<event_based_actor, Base>::value,
"Base must be untyped_actor or a derived type"); "Base must be event_based_actor or a derived type");
protected: protected:
...@@ -58,7 +58,7 @@ class sb_actor : public Base { ...@@ -58,7 +58,7 @@ class sb_actor : public Base {
public: public:
/** /**
* @brief Overrides {@link untyped_actor::make_behavior()} and sets * @brief Overrides {@link event_based_actor::make_behavior()} and sets
* the initial actor behavior to <tt>Derived::init_state</tt>. * the initial actor behavior to <tt>Derived::init_state</tt>.
*/ */
behavior make_behavior() override { behavior make_behavior() override {
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
namespace cppa { namespace cppa {
class untyped_actor; class event_based_actor;
class scheduled_actor; class scheduled_actor;
class scheduler_helper; class scheduler_helper;
typedef intrusive_ptr<scheduled_actor> scheduled_actor_ptr; typedef intrusive_ptr<scheduled_actor> scheduled_actor_ptr;
......
...@@ -32,10 +32,13 @@ ...@@ -32,10 +32,13 @@
#define CPPA_SCOPED_ACTOR_HPP #define CPPA_SCOPED_ACTOR_HPP
#include "cppa/behavior.hpp" #include "cppa/behavior.hpp"
#include "cppa/blocking_untyped_actor.hpp" #include "cppa/blocking_actor.hpp"
namespace cppa { namespace cppa {
/**
* @brief A scoped handle to a blocking actor.
*/
class scoped_actor { class scoped_actor {
public: public:
...@@ -48,15 +51,15 @@ class scoped_actor { ...@@ -48,15 +51,15 @@ class scoped_actor {
~scoped_actor(); ~scoped_actor();
inline blocking_untyped_actor* operator->() const { inline blocking_actor* operator->() const {
return m_self.get(); return m_self.get();
} }
inline blocking_untyped_actor& operator*() const { inline blocking_actor& operator*() const {
return *m_self; return *m_self;
} }
inline blocking_untyped_actor* get() const { inline blocking_actor* get() const {
return m_self.get(); return m_self.get();
} }
...@@ -82,7 +85,7 @@ class scoped_actor { ...@@ -82,7 +85,7 @@ class scoped_actor {
bool m_hidden; bool m_hidden;
actor_id m_prev; // used for logging/debugging purposes only actor_id m_prev; // used for logging/debugging purposes only
intrusive_ptr<blocking_untyped_actor> m_self; intrusive_ptr<blocking_actor> m_self;
}; };
......
...@@ -51,50 +51,50 @@ namespace cppa { ...@@ -51,50 +51,50 @@ namespace cppa {
namespace detail { namespace detail {
template<class Impl, spawn_options Options, typename BeforeLaunch, typename... Ts> template<class Impl, spawn_options Opts, typename BeforeLaunch, typename... Ts>
actor spawn_impl(BeforeLaunch before_launch_fun, Ts&&... args) { actor spawn_impl(BeforeLaunch before_launch_fun, Ts&&... args) {
static_assert(std::is_base_of<untyped_actor, Impl>::value || static_assert(std::is_base_of<event_based_actor, Impl>::value ||
(std::is_base_of<blocking_untyped_actor, Impl>::value && (std::is_base_of<blocking_actor, Impl>::value &&
has_blocking_api_flag(Options)), has_blocking_api_flag(Opts)),
"Impl is not a derived type of untyped_actor or " "Impl is not a derived type of event_based_actor or "
"is a derived type of blocking_untyped_actor but " "is a derived type of blocking_actor but "
"blocking_api_flag is missing"); "blocking_api_flag is missing");
static_assert(is_unbound(Options), static_assert(is_unbound(Opts),
"top-level spawns cannot have monitor or link flag"); "top-level spawns cannot have monitor or link flag");
CPPA_LOGF_TRACE("spawn " << detail::demangle<Impl>()); CPPA_LOGF_TRACE("spawn " << detail::demangle<Impl>());
// runtime check wheter context_switching_resume can be used, // runtime check wheter context_switching_resume can be used,
// i.e., add the detached flag if libcppa compiled without fiber support // i.e., add the detached flag if libcppa compiled without fiber support
// when using the blocking API // when using the blocking API
if (has_blocking_api_flag(Options) if (has_blocking_api_flag(Opts)
&& !has_detach_flag(Options) && !has_detach_flag(Opts)
&& util::fiber::is_disabled_feature()) { && util::fiber::is_disabled_feature()) {
return spawn_impl<Impl, Options + detached>(before_launch_fun, return spawn_impl<Impl, Opts + detached>(before_launch_fun,
std::forward<Ts>(args)...); std::forward<Ts>(args)...);
} }
/* /*
using scheduling_policy = typename std::conditional< using scheduling_policy = typename std::conditional<
has_detach_flag(Options), has_detach_flag(Opts),
policy::no_scheduling, policy::no_scheduling,
policy::cooperative_scheduling policy::cooperative_scheduling
>::type; >::type;
*/ */
using scheduling_policy = policy::no_scheduling; using scheduling_policy = policy::no_scheduling;
using priority_policy = typename std::conditional< using priority_policy = typename std::conditional<
has_priority_aware_flag(Options), has_priority_aware_flag(Opts),
policy::prioritizing, policy::prioritizing,
policy::not_prioritizing policy::not_prioritizing
>::type; >::type;
using resume_policy = typename std::conditional< using resume_policy = typename std::conditional<
has_blocking_api_flag(Options), has_blocking_api_flag(Opts),
typename std::conditional< typename std::conditional<
has_detach_flag(Options), has_detach_flag(Opts),
policy::no_resume, policy::no_resume,
policy::context_switching_resume policy::context_switching_resume
>::type, >::type,
policy::event_based_resume policy::event_based_resume
>::type; >::type;
using invoke_policy = typename std::conditional< using invoke_policy = typename std::conditional<
has_blocking_api_flag(Options), has_blocking_api_flag(Opts),
policy::nestable_invoke, policy::nestable_invoke,
policy::sequential_invoke policy::sequential_invoke
>::type; >::type;
...@@ -106,7 +106,7 @@ actor spawn_impl(BeforeLaunch before_launch_fun, Ts&&... args) { ...@@ -106,7 +106,7 @@ actor spawn_impl(BeforeLaunch before_launch_fun, Ts&&... args) {
auto ptr = make_counted<proper_impl>(std::forward<Ts>(args)...); auto ptr = make_counted<proper_impl>(std::forward<Ts>(args)...);
CPPA_PUSH_AID(ptr->id()); CPPA_PUSH_AID(ptr->id());
before_launch_fun(ptr.get()); before_launch_fun(ptr.get());
ptr->launch(has_hide_flag(Options)); ptr->launch(has_hide_flag(Opts));
return ptr; return ptr;
} }
...@@ -131,9 +131,9 @@ struct spawn_fwd<scoped_actor> { ...@@ -131,9 +131,9 @@ struct spawn_fwd<scoped_actor> {
// forwards the arguments to spawn_impl, replacing pointers // forwards the arguments to spawn_impl, replacing pointers
// to actors with instances of 'actor' // to actors with instances of 'actor'
template<class Impl, spawn_options Options, typename BeforeLaunch, typename... Ts> template<class Impl, spawn_options Opts, typename BeforeLaunch, typename... Ts>
actor spawn_fwd_args(BeforeLaunch before_launch_fun, Ts&&... args) { actor spawn_fwd_args(BeforeLaunch before_launch_fun, Ts&&... args) {
return spawn_impl<Impl, Options>( return spawn_impl<Impl, Opts>(
before_launch_fun, before_launch_fun,
spawn_fwd<typename util::rm_const_and_ref<Ts>::type>::fwd( spawn_fwd<typename util::rm_const_and_ref<Ts>::type>::fwd(
std::forward<Ts>(args))...); std::forward<Ts>(args))...);
...@@ -149,13 +149,13 @@ actor spawn_fwd_args(BeforeLaunch before_launch_fun, Ts&&... args) { ...@@ -149,13 +149,13 @@ actor spawn_fwd_args(BeforeLaunch before_launch_fun, Ts&&... args) {
/** /**
* @brief Spawns an actor of type @p Impl. * @brief Spawns an actor of type @p Impl.
* @param args Constructor arguments. * @param args Constructor arguments.
* @tparam Impl Subtype of {@link untyped_actor} or {@link sb_actor}. * @tparam Impl Subtype of {@link event_based_actor} or {@link sb_actor}.
* @tparam Options Optional flags to modify <tt>spawn</tt>'s behavior. * @tparam Opts Optional flags to modify <tt>spawn</tt>'s behavior.
* @returns An {@link actor} to the spawned {@link actor}. * @returns An {@link actor} to the spawned {@link actor}.
*/ */
template<class Impl, spawn_options Options, typename... Ts> template<class Impl, spawn_options Opts, typename... Ts>
actor spawn(Ts&&... args) { actor spawn(Ts&&... args) {
return detail::spawn_fwd_args<Impl, Options>( return detail::spawn_fwd_args<Impl, Opts>(
[](local_actor*) { /* no-op as BeforeLaunch callback */ }, [](local_actor*) { /* no-op as BeforeLaunch callback */ },
std::forward<Ts>(args)...); std::forward<Ts>(args)...);
} }
...@@ -163,38 +163,38 @@ actor spawn(Ts&&... args) { ...@@ -163,38 +163,38 @@ actor spawn(Ts&&... args) {
/** /**
* @brief Spawns a new {@link actor} that evaluates given arguments. * @brief Spawns a new {@link actor} that evaluates given arguments.
* @param args A functor followed by its arguments. * @param args A functor followed by its arguments.
* @tparam Options Optional flags to modify <tt>spawn</tt>'s behavior. * @tparam Opts Optional flags to modify <tt>spawn</tt>'s behavior.
* @returns An {@link actor} to the spawned {@link actor}. * @returns An {@link actor} to the spawned {@link actor}.
*/ */
//template<spawn_options Options = no_spawn_options, typename... Ts> //template<spawn_options Opts = no_spawn_options, typename... Ts>
template<spawn_options Options, typename... Ts> template<spawn_options Opts, typename... Ts>
actor spawn(Ts&&... args) { actor spawn(Ts&&... args) {
static_assert(sizeof...(Ts) > 0, "too few arguments provided"); static_assert(sizeof...(Ts) > 0, "too few arguments provided");
using base_class = typename std::conditional< using base_class = typename std::conditional<
has_blocking_api_flag(Options), has_blocking_api_flag(Opts),
detail::functor_based_blocking_actor, detail::functor_based_blocking_actor,
detail::functor_based_actor detail::functor_based_actor
>::type; >::type;
return spawn<base_class, Options>(std::forward<Ts>(args)...); return spawn<base_class, Opts>(std::forward<Ts>(args)...);
} }
/** /**
* @brief Spawns a new actor that evaluates given arguments and * @brief Spawns a new actor that evaluates given arguments and
* immediately joins @p grp. * immediately joins @p grp.
* @param args A functor followed by its arguments. * @param args A functor followed by its arguments.
* @tparam Options Optional flags to modify <tt>spawn</tt>'s behavior. * @tparam Opts Optional flags to modify <tt>spawn</tt>'s behavior.
* @returns An {@link actor} to the spawned {@link actor}. * @returns An {@link actor} to the spawned {@link actor}.
* @note The spawned has joined the group before this function returns. * @note The spawned has joined the group before this function returns.
*/ */
template<spawn_options Options, typename... Ts> template<spawn_options Opts, typename... Ts>
actor spawn_in_group(const group_ptr& grp, Ts&&... args) { actor spawn_in_group(const group_ptr& grp, Ts&&... args) {
static_assert(sizeof...(Ts) > 0, "too few arguments provided"); static_assert(sizeof...(Ts) > 0, "too few arguments provided");
using base_class = typename std::conditional< using base_class = typename std::conditional<
has_blocking_api_flag(Options), has_blocking_api_flag(Opts),
detail::functor_based_blocking_actor, detail::functor_based_blocking_actor,
detail::functor_based_actor detail::functor_based_actor
>::type; >::type;
return detail::spawn_fwd_args<base_class, Options>( return detail::spawn_fwd_args<base_class, Opts>(
[&](local_actor* ptr) { ptr->join(grp); }, [&](local_actor* ptr) { ptr->join(grp); },
std::forward<Ts>(args)...); std::forward<Ts>(args)...);
} }
...@@ -202,20 +202,20 @@ actor spawn_in_group(const group_ptr& grp, Ts&&... args) { ...@@ -202,20 +202,20 @@ actor spawn_in_group(const group_ptr& grp, Ts&&... args) {
/** /**
* @brief Spawns an actor of type @p Impl that immediately joins @p grp. * @brief Spawns an actor of type @p Impl that immediately joins @p grp.
* @param args Constructor arguments. * @param args Constructor arguments.
* @tparam Impl Subtype of {@link untyped_actor} or {@link sb_actor}. * @tparam Impl Subtype of {@link event_based_actor} or {@link sb_actor}.
* @tparam Options Optional flags to modify <tt>spawn</tt>'s behavior. * @tparam Opts Optional flags to modify <tt>spawn</tt>'s behavior.
* @returns An {@link actor} to the spawned {@link actor}. * @returns An {@link actor} to the spawned {@link actor}.
* @note The spawned has joined the group before this function returns. * @note The spawned has joined the group before this function returns.
*/ */
template<class Impl, spawn_options Options, typename... Ts> template<class Impl, spawn_options Opts, typename... Ts>
actor spawn_in_group(const group_ptr& grp, Ts&&... args) { actor spawn_in_group(const group_ptr& grp, Ts&&... args) {
return detail::spawn_fwd_args<Impl, Options>( return detail::spawn_fwd_args<Impl, Opts>(
[&](local_actor* ptr) { ptr->join(grp); }, [&](local_actor* ptr) { ptr->join(grp); },
std::forward<Ts>(args)...); std::forward<Ts>(args)...);
} }
/* /*
template<class Impl, spawn_options Options = no_spawn_options, typename... Ts> template<class Impl, spawn_options Opts = no_spawn_options, typename... Ts>
typename Impl::typed_pointer_type spawn_typed(Ts&&... args) { typename Impl::typed_pointer_type spawn_typed(Ts&&... args) {
static_assert(util::tl_is_distinct<typename Impl::signatures>::value, static_assert(util::tl_is_distinct<typename Impl::signatures>::value,
"typed actors are not allowed to define " "typed actors are not allowed to define "
...@@ -223,13 +223,13 @@ typename Impl::typed_pointer_type spawn_typed(Ts&&... args) { ...@@ -223,13 +223,13 @@ typename Impl::typed_pointer_type spawn_typed(Ts&&... args) {
auto p = make_counted<Impl>(std::forward<Ts>(args)...); auto p = make_counted<Impl>(std::forward<Ts>(args)...);
using result_type = typename Impl::typed_pointer_type; using result_type = typename Impl::typed_pointer_type;
return result_type::cast_from( return result_type::cast_from(
eval_sopts(Options, get_scheduler()->exec(Options, std::move(p))) eval_sopts(Opts, get_scheduler()->exec(Opts, std::move(p)))
); );
} }
*/ */
/*TODO: /*TODO:
template<spawn_options Options, typename... Ts> template<spawn_options Opts, typename... Ts>
typed_actor<typename detail::deduce_signature<Ts>::type...> typed_actor<typename detail::deduce_signature<Ts>::type...>
spawn_typed(const match_expr<Ts...>& me) { spawn_typed(const match_expr<Ts...>& me) {
static_assert(util::conjunction< static_assert(util::conjunction<
...@@ -246,7 +246,7 @@ spawn_typed(const match_expr<Ts...>& me) { ...@@ -246,7 +246,7 @@ spawn_typed(const match_expr<Ts...>& me) {
using impl = detail::default_typed_actor< using impl = detail::default_typed_actor<
typename detail::deduce_signature<Ts>::type... typename detail::deduce_signature<Ts>::type...
>; >;
return spawn_typed<impl, Options>(me); return spawn_typed<impl, Opts>(me);
} }
template<typename... Ts> template<typename... Ts>
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
#include "cppa/replies_to.hpp" #include "cppa/replies_to.hpp"
#include "cppa/typed_behavior.hpp" #include "cppa/typed_behavior.hpp"
#include "cppa/untyped_actor.hpp" #include "cppa/event_based_actor.hpp"
#include "cppa/detail/typed_actor_util.hpp" #include "cppa/detail/typed_actor_util.hpp"
...@@ -43,7 +43,7 @@ template<typename... Signatures> ...@@ -43,7 +43,7 @@ template<typename... Signatures>
class typed_actor_ptr; class typed_actor_ptr;
template<typename... Signatures> template<typename... Signatures>
class typed_actor : public untyped_actor { class typed_actor : public event_based_actor {
public: public:
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include "cppa/abstract_actor.hpp" #include "cppa/abstract_actor.hpp"
#include "cppa/util/comparable.hpp"
namespace cppa { namespace cppa {
class actor; class actor;
...@@ -41,9 +43,9 @@ namespace detail { class raw_access; } ...@@ -41,9 +43,9 @@ namespace detail { class raw_access; }
/** /**
* @brief Encapsulates actor operations that are valid for both {@link actor} * @brief Encapsulates actor operations that are valid for both {@link actor}
* and {@link actor_addr} handles. * and {@link actor_addr}.
*/ */
class untyped_actor_handle { class untyped_actor_handle : util::comparable<untyped_actor_handle> {
friend class actor; friend class actor;
friend class actor_addr; friend class actor_addr;
...@@ -53,7 +55,7 @@ class untyped_actor_handle { ...@@ -53,7 +55,7 @@ class untyped_actor_handle {
untyped_actor_handle() = default; untyped_actor_handle() = default;
inline bool attach(attachable_ptr ptr); inline bool attach(attachable_ptr ptr) const;
/** /**
* @brief Convenience function that attaches the functor * @brief Convenience function that attaches the functor
...@@ -67,7 +69,7 @@ class untyped_actor_handle { ...@@ -67,7 +69,7 @@ class untyped_actor_handle {
* otherwise (actor already exited) @p false. * otherwise (actor already exited) @p false.
*/ */
template<typename F> template<typename F>
bool attach_functor(F&& f); bool attach_functor(F&& f) const;
inline actor_id id() const; inline actor_id id() const;
...@@ -81,6 +83,12 @@ class untyped_actor_handle { ...@@ -81,6 +83,12 @@ class untyped_actor_handle {
*/ */
bool is_remote() const; bool is_remote() const;
inline bool valid() const {
return static_cast<bool>(m_ptr);
}
intptr_t compare(const untyped_actor_handle& other) const;
protected: protected:
inline untyped_actor_handle(abstract_actor_ptr ptr) : m_ptr(std::move(ptr)) { } inline untyped_actor_handle(abstract_actor_ptr ptr) : m_ptr(std::move(ptr)) { }
...@@ -104,7 +112,7 @@ struct functor_attachable : attachable { ...@@ -104,7 +112,7 @@ struct functor_attachable : attachable {
}; };
template<typename F> template<typename F>
bool untyped_actor_handle::attach_functor(F&& f) { bool untyped_actor_handle::attach_functor(F&& f) const {
typedef typename util::rm_const_and_ref<F>::type f_type; typedef typename util::rm_const_and_ref<F>::type f_type;
typedef functor_attachable<f_type> impl; typedef functor_attachable<f_type> impl;
return attach(attachable_ptr{new impl(std::forward<F>(f))}); return attach(attachable_ptr{new impl(std::forward<F>(f))});
...@@ -114,7 +122,7 @@ inline actor_id untyped_actor_handle::id() const { ...@@ -114,7 +122,7 @@ inline actor_id untyped_actor_handle::id() const {
return (m_ptr) ? m_ptr->id() : 0; return (m_ptr) ? m_ptr->id() : 0;
} }
inline bool untyped_actor_handle::attach(attachable_ptr ptr) { inline bool untyped_actor_handle::attach(attachable_ptr ptr) const {
return m_ptr ? m_ptr->attach(std::move(ptr)) : false; return m_ptr ? m_ptr->attach(std::move(ptr)) : false;
} }
......
...@@ -112,7 +112,7 @@ constexpr int max_req_interval = 300; ...@@ -112,7 +112,7 @@ constexpr int max_req_interval = 300;
} // namespace <anonymous> } // namespace <anonymous>
// provides print utility and each base_actor has a parent // provides print utility and each base_actor has a parent
class base_actor : public untyped_actor { class base_actor : public event_based_actor {
protected: protected:
...@@ -308,7 +308,7 @@ class curl_master : public base_actor { ...@@ -308,7 +308,7 @@ class curl_master : public base_actor {
public: public:
curl_master() : base_actor(nullptr, "curl_master", color::magenta) { } curl_master() : base_actor(invalid_actor, "curl_master", color::magenta) { }
protected: protected:
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
using namespace std; using namespace std;
using namespace cppa; using namespace cppa;
behavior mirror(untyped_actor* self) { behavior mirror(event_based_actor* self) {
// wait for messages // wait for messages
return ( return (
// invoke this lambda expression if we receive a string // invoke this lambda expression if we receive a string
...@@ -20,7 +20,7 @@ behavior mirror(untyped_actor* self) { ...@@ -20,7 +20,7 @@ behavior mirror(untyped_actor* self) {
); );
} }
void hello_world(untyped_actor* self, const actor& buddy) { void hello_world(event_based_actor* self, const actor& buddy) {
// send "Hello World!" to our buddy ... // send "Hello World!" to our buddy ...
self->sync_send(buddy, "Hello World!").then( self->sync_send(buddy, "Hello World!").then(
// ... and wait for a response // ... and wait for a response
......
...@@ -13,7 +13,7 @@ using std::endl; ...@@ -13,7 +13,7 @@ using std::endl;
using namespace cppa; using namespace cppa;
// implementation using the blocking API // implementation using the blocking API
void blocking_math_fun(blocking_untyped_actor* self) { void blocking_math_fun(blocking_actor* self) {
bool done = false; bool done = false;
self->do_receive ( self->do_receive (
// "arg_match" matches the parameter types of given lambda expression // "arg_match" matches the parameter types of given lambda expression
...@@ -34,7 +34,7 @@ void blocking_math_fun(blocking_untyped_actor* self) { ...@@ -34,7 +34,7 @@ void blocking_math_fun(blocking_untyped_actor* self) {
).until(gref(done)); ).until(gref(done));
} }
void calculator(untyped_actor* self) { void calculator(event_based_actor* self) {
// execute this behavior until actor terminates // execute this behavior until actor terminates
self->become ( self->become (
on(atom("plus"), arg_match) >> [](int a, int b) { on(atom("plus"), arg_match) >> [](int a, int b) {
...@@ -50,7 +50,7 @@ void calculator(untyped_actor* self) { ...@@ -50,7 +50,7 @@ void calculator(untyped_actor* self) {
); );
} }
void tester(untyped_actor* self, const actor& testee) { void tester(event_based_actor* self, const actor& testee) {
self->link_to(testee); self->link_to(testee);
// will be invoked if we receive an unexpected response message // will be invoked if we receive an unexpected response message
self->on_sync_failure([=] { self->on_sync_failure([=] {
......
...@@ -53,7 +53,7 @@ void draw_kirby(const animation_step& animation) { ...@@ -53,7 +53,7 @@ void draw_kirby(const animation_step& animation) {
} }
// uses a message-based loop to iterate over all animation steps // uses a message-based loop to iterate over all animation steps
void dancing_kirby(untyped_actor* self) { void dancing_kirby(event_based_actor* self) {
// let's get it started // let's get it started
self->send(self, atom("Step"), size_t{0}); self->send(self, atom("Step"), size_t{0});
self->become ( self->become (
......
...@@ -17,7 +17,7 @@ using namespace std; ...@@ -17,7 +17,7 @@ using namespace std;
using namespace cppa; using namespace cppa;
// either taken by a philosopher or available // either taken by a philosopher or available
void chopstick(untyped_actor* self) { void chopstick(event_based_actor* self) {
self->become( self->become(
on(atom("take"), arg_match) >> [=](const actor& philos) { on(atom("take"), arg_match) >> [=](const actor& philos) {
// tell philosopher it took this chopstick // tell philosopher it took this chopstick
...@@ -71,7 +71,7 @@ void chopstick(untyped_actor* self) { ...@@ -71,7 +71,7 @@ void chopstick(untyped_actor* self) {
* [ X = right => Y = left ] * [ X = right => Y = left ]
*/ */
struct philosopher : untyped_actor { struct philosopher : event_based_actor {
std::string name; // the name of this philosopher std::string name; // the name of this philosopher
actor left; // left chopstick actor left; // left chopstick
......
...@@ -26,7 +26,7 @@ using namespace cppa; ...@@ -26,7 +26,7 @@ using namespace cppa;
using namespace cppa::placeholders; using namespace cppa::placeholders;
// our "service" // our "service"
void calculator(untyped_actor* self) { void calculator(event_based_actor* self) {
self->become ( self->become (
on(atom("plus"), arg_match) >> [](int a, int b) -> any_tuple { on(atom("plus"), arg_match) >> [](int a, int b) -> any_tuple {
return make_any_tuple(atom("result"), a + b); return make_any_tuple(atom("result"), a + b);
...@@ -49,13 +49,13 @@ inline string trim(std::string s) { ...@@ -49,13 +49,13 @@ inline string trim(std::string s) {
return s; return s;
} }
void client_bhvr(untyped_actor* self, const string& host, uint16_t port, const actor& server) { void client_bhvr(event_based_actor* self, const string& host, uint16_t port, const actor& server) {
// recover from sync failures by trying to reconnect to server // recover from sync failures by trying to reconnect to server
if (!self->has_sync_failure_handler()) { if (!self->has_sync_failure_handler()) {
self->on_sync_failure([=] { self->on_sync_failure([=] {
aout(self) << "*** lost connection to " << host aout(self) << "*** lost connection to " << host
<< ":" << port << endl; << ":" << port << endl;
client_bhvr(self, host, port, nullptr); client_bhvr(self, host, port, invalid_actor);
}); });
} }
// connect to server if needed // connect to server if needed
...@@ -74,7 +74,7 @@ void client_bhvr(untyped_actor* self, const string& host, uint16_t port, const a ...@@ -74,7 +74,7 @@ void client_bhvr(untyped_actor* self, const string& host, uint16_t port, const a
} }
} }
self->become ( self->become (
on_arg_match.when(_x1.in({atom("plus"), atom("minus")}) && gval(server) != nullptr) >> [=](atom_value op, int lhs, int rhs) { on_arg_match.when(_x1.in({atom("plus"), atom("minus")}) && gval(server) != invalid_actor) >> [=](atom_value op, int lhs, int rhs) {
self->sync_send_tuple(server, self->last_dequeued()).then( self->sync_send_tuple(server, self->last_dequeued()).then(
on(atom("result"), arg_match) >> [=](int result) { on(atom("result"), arg_match) >> [=](int result) {
aout(self) << lhs << " " aout(self) << lhs << " "
...@@ -86,15 +86,15 @@ void client_bhvr(untyped_actor* self, const string& host, uint16_t port, const a ...@@ -86,15 +86,15 @@ void client_bhvr(untyped_actor* self, const string& host, uint16_t port, const a
}, },
on_arg_match >> [=](const down_msg&) { on_arg_match >> [=](const down_msg&) {
aout(self) << "*** server down, try to reconnect ..." << endl; aout(self) << "*** server down, try to reconnect ..." << endl;
client_bhvr(self, host, port, nullptr); client_bhvr(self, host, port, invalid_actor);
}, },
on(atom("rebind"), arg_match) >> [=](const string& host, uint16_t port) { on(atom("rebind"), arg_match) >> [=](const string& host, uint16_t port) {
aout(self) << "*** rebind to new server: " aout(self) << "*** rebind to new server: "
<< host << ":" << port << endl; << host << ":" << port << endl;
client_bhvr(self, host, port, nullptr); client_bhvr(self, host, port, invalid_actor);
}, },
on(atom("reconnect")) >> [=] { on(atom("reconnect")) >> [=] {
client_bhvr(self, host, port, nullptr); client_bhvr(self, host, port, invalid_actor);
} }
); );
} }
...@@ -108,7 +108,7 @@ void client_repl(const string& host, uint16_t port) { ...@@ -108,7 +108,7 @@ void client_repl(const string& host, uint16_t port) {
"connect <host> <port> Reconfigure server" "connect <host> <port> Reconfigure server"
<< endl << endl; << endl << endl;
string line; string line;
auto client = spawn(client_bhvr, host, port, nullptr); auto client = spawn(client_bhvr, host, port, invalid_actor);
const char connect[] = "connect "; const char connect[] = "connect ";
while (getline(cin, line)) { while (getline(cin, line)) {
line = trim(std::move(line)); // ignore leading and trailing whitespaces line = trim(std::move(line)); // ignore leading and trailing whitespaces
......
...@@ -42,7 +42,7 @@ any_tuple split_line(const line& l) { ...@@ -42,7 +42,7 @@ any_tuple split_line(const line& l) {
return any_tuple::view(std::move(result)); return any_tuple::view(std::move(result));
} }
void client(untyped_actor* self, const string& name) { void client(event_based_actor* self, const string& name) {
self->become ( self->become (
on(atom("broadcast"), arg_match) >> [=](const string& message) { on(atom("broadcast"), arg_match) >> [=](const string& message) {
for(auto& dest : self->joined_groups()) { for(auto& dest : self->joined_groups()) {
......
...@@ -42,7 +42,7 @@ bool operator==( const foo2& lhs, const foo2& rhs ) { ...@@ -42,7 +42,7 @@ bool operator==( const foo2& lhs, const foo2& rhs ) {
} }
// receives `remaining` messages // receives `remaining` messages
void testee(untyped_actor* self, size_t remaining) { void testee(event_based_actor* self, size_t remaining) {
auto set_next_behavior = [=] { auto set_next_behavior = [=] {
if (remaining > 1) testee(self, remaining - 1); if (remaining > 1) testee(self, remaining - 1);
else self->quit(); else self->quit();
......
...@@ -39,7 +39,7 @@ bool operator==(const foo& lhs, const foo& rhs) { ...@@ -39,7 +39,7 @@ bool operator==(const foo& lhs, const foo& rhs) {
&& lhs.b() == rhs.b(); && lhs.b() == rhs.b();
} }
void testee(untyped_actor* self) { void testee(event_based_actor* self) {
self->become ( self->become (
on<foo>() >> [=](const foo& val) { on<foo>() >> [=](const foo& val) {
aout(self) << "foo(" aout(self) << "foo("
......
...@@ -46,7 +46,7 @@ typedef int (foo::*foo_getter)() const; ...@@ -46,7 +46,7 @@ typedef int (foo::*foo_getter)() const;
// a member function pointer to set an attribute of foo // a member function pointer to set an attribute of foo
typedef void (foo::*foo_setter)(int); typedef void (foo::*foo_setter)(int);
void testee(untyped_actor* self) { void testee(event_based_actor* self) {
self->become ( self->become (
on<foo>() >> [=](const foo& val) { on<foo>() >> [=](const foo& val) {
aout(self) << "foo(" aout(self) << "foo("
......
...@@ -79,7 +79,7 @@ bool operator==(const baz& lhs, const baz& rhs) { ...@@ -79,7 +79,7 @@ bool operator==(const baz& lhs, const baz& rhs) {
} }
// receives `remaining` messages // receives `remaining` messages
void testee(untyped_actor* self, size_t remaining) { void testee(event_based_actor* self, size_t remaining) {
auto set_next_behavior = [=] { auto set_next_behavior = [=] {
if (remaining > 1) testee(self, remaining - 1); if (remaining > 1) testee(self, remaining - 1);
else self->quit(); else self->quit();
......
...@@ -131,7 +131,7 @@ class tree_type_info : public util::abstract_uniform_type_info<tree> { ...@@ -131,7 +131,7 @@ class tree_type_info : public util::abstract_uniform_type_info<tree> {
typedef std::vector<tree> tree_vector; typedef std::vector<tree> tree_vector;
// receives `remaining` messages // receives `remaining` messages
void testee(untyped_actor* self, size_t remaining) { void testee(event_based_actor* self, size_t remaining) {
auto set_next_behavior = [=] { auto set_next_behavior = [=] {
if (remaining > 1) testee(self, remaining - 1); if (remaining > 1) testee(self, remaining - 1);
else self->quit(); else self->quit();
......
...@@ -66,10 +66,14 @@ abstract_actor::abstract_actor() ...@@ -66,10 +66,14 @@ abstract_actor::abstract_actor()
: m_id(get_actor_registry()->next_id()), m_is_proxy(false) : m_id(get_actor_registry()->next_id()), m_is_proxy(false)
, m_exit_reason(exit_reason::not_exited) { } , m_exit_reason(exit_reason::not_exited) { }
void abstract_actor::link_to(const actor& whom) {
link_to(whom->address());
}
bool abstract_actor::link_to_impl(const actor_addr& other) { bool abstract_actor::link_to_impl(const actor_addr& other) {
if (other && other != this) { if (other && other != this) {
guard_type guard{m_mtx}; guard_type guard{m_mtx};
auto ptr = detail::actor_addr_cast<abstract_actor>(other); auto ptr = detail::raw_access::get(other);
// send exit message if already exited // send exit message if already exited
if (exited()) { if (exited()) {
ptr->enqueue({address(), ptr}, ptr->enqueue({address(), ptr},
...@@ -147,7 +151,7 @@ bool abstract_actor::establish_backlink(const actor_addr& other) { ...@@ -147,7 +151,7 @@ bool abstract_actor::establish_backlink(const actor_addr& other) {
if (reason == exit_reason::not_exited) { if (reason == exit_reason::not_exited) {
auto i = std::find(m_links.begin(), m_links.end(), other); auto i = std::find(m_links.begin(), m_links.end(), other);
if (i == m_links.end()) { if (i == m_links.end()) {
m_links.push_back(detail::actor_addr_cast<abstract_actor>(other)); m_links.push_back(detail::raw_access::get(other));
return true; return true;
} }
} }
...@@ -165,7 +169,7 @@ bool abstract_actor::unlink_from_impl(const actor_addr& other) { ...@@ -165,7 +169,7 @@ bool abstract_actor::unlink_from_impl(const actor_addr& other) {
if (!other) return false; if (!other) return false;
guard_type guard{m_mtx}; guard_type guard{m_mtx};
// remove_backlink returns true if this actor is linked to other // remove_backlink returns true if this actor is linked to other
auto ptr = detail::actor_addr_cast<abstract_actor>(other); auto ptr = detail::raw_access::get(other);
if (!exited() && ptr->remove_backlink(address())) { if (!exited() && ptr->remove_backlink(address())) {
auto i = std::find(m_links.begin(), m_links.end(), ptr); auto i = std::find(m_links.begin(), m_links.end(), ptr);
CPPA_REQUIRE(i != m_links.end()); CPPA_REQUIRE(i != m_links.end());
......
...@@ -35,22 +35,19 @@ ...@@ -35,22 +35,19 @@
#include "cppa/actor_addr.hpp" #include "cppa/actor_addr.hpp"
#include "cppa/actor_proxy.hpp" #include "cppa/actor_proxy.hpp"
#include "cppa/local_actor.hpp" #include "cppa/local_actor.hpp"
#include "cppa/untyped_actor.hpp" #include "cppa/event_based_actor.hpp"
#include "cppa/blocking_untyped_actor.hpp" #include "cppa/blocking_actor.hpp"
namespace cppa { namespace cppa {
actor::actor(const std::nullptr_t&) : m_ops(nullptr) { } actor::actor(const invalid_actor_t&) : m_ops(nullptr) { }
actor::actor(actor_proxy* ptr) : m_ops(ptr) { }
actor::actor(untyped_actor* ptr) : m_ops(ptr) { }
actor::actor(blocking_untyped_actor* ptr) : m_ops(ptr) { }
actor::actor(abstract_actor* ptr) : m_ops(ptr) { } actor::actor(abstract_actor* ptr) : m_ops(ptr) { }
actor::actor(const invalid_actor_t&) : m_ops(nullptr) { } actor& actor::operator=(const invalid_actor_t&) {
m_ops.m_ptr.reset();
return *this;
}
void actor::handle::enqueue(const message_header& hdr, any_tuple msg) const { void actor::handle::enqueue(const message_header& hdr, any_tuple msg) const {
if (m_ptr) m_ptr->enqueue(hdr, std::move(msg)); if (m_ptr) m_ptr->enqueue(hdr, std::move(msg));
...@@ -60,4 +57,16 @@ intptr_t actor::compare(const actor& other) const { ...@@ -60,4 +57,16 @@ intptr_t actor::compare(const actor& other) const {
return channel::compare(m_ops.m_ptr.get(), other.m_ops.m_ptr.get()); return channel::compare(m_ops.m_ptr.get(), other.m_ops.m_ptr.get());
} }
intptr_t actor::compare(const invalid_actor_t&) const {
return valid() ? 1 : 0;
}
intptr_t actor::compare(const actor_addr& other) const {
return m_ops.compare(*other);
}
void actor::swap(actor& other) {
m_ops.m_ptr.swap(other.m_ops.m_ptr);
}
} // namespace cppa } // namespace cppa
...@@ -42,24 +42,10 @@ intptr_t compare_impl(const abstract_actor* lhs, const abstract_actor* rhs) { ...@@ -42,24 +42,10 @@ intptr_t compare_impl(const abstract_actor* lhs, const abstract_actor* rhs) {
} }
} // namespace <anonymous> } // namespace <anonymous>
actor_addr::actor_addr(const actor& other) : m_ops(detail::raw_access::get(other)) { }
actor_addr::actor_addr(const invalid_actor_addr_t&) : m_ops(nullptr) { } actor_addr::actor_addr(const invalid_actor_addr_t&) : m_ops(nullptr) { }
actor_addr::actor_addr(abstract_actor* ptr) : m_ops(ptr) { } actor_addr::actor_addr(abstract_actor* ptr) : m_ops(ptr) { }
actor_addr::operator bool() const {
return static_cast<bool>(m_ops.m_ptr);
}
bool actor_addr::operator!() const {
return !(m_ops.m_ptr);
}
intptr_t actor_addr::compare(const actor& other) const {
return compare_impl(m_ops.m_ptr.get(), detail::raw_access::get(other));
}
intptr_t actor_addr::compare(const actor_addr& other) const { intptr_t actor_addr::compare(const actor_addr& other) const {
return compare_impl(m_ops.m_ptr.get(), other.m_ops.m_ptr.get()); return compare_impl(m_ops.m_ptr.get(), other.m_ops.m_ptr.get());
} }
...@@ -68,11 +54,6 @@ intptr_t actor_addr::compare(const abstract_actor* other) const { ...@@ -68,11 +54,6 @@ intptr_t actor_addr::compare(const abstract_actor* other) const {
return compare_impl(m_ops.m_ptr.get(), other); return compare_impl(m_ops.m_ptr.get(), other);
} }
actor_addr& actor_addr::operator=(const actor& other) {
m_ops.m_ptr = detail::raw_access::get(other);
return *this;
}
actor_addr actor_addr::operator=(const invalid_actor_addr_t&) { actor_addr actor_addr::operator=(const invalid_actor_addr_t&) {
m_ops.m_ptr.reset(); m_ops.m_ptr.reset();
return *this; return *this;
......
...@@ -57,7 +57,7 @@ void actor_namespace::write(serializer* sink, const actor_addr& ptr) { ...@@ -57,7 +57,7 @@ void actor_namespace::write(serializer* sink, const actor_addr& ptr) {
else { else {
// register locally running actors to be able to deserialize them later // register locally running actors to be able to deserialize them later
if (!ptr->is_remote()) { if (!ptr->is_remote()) {
get_actor_registry()->put(ptr->id(), detail::actor_addr_cast<abstract_actor>(ptr)); get_actor_registry()->put(ptr->id(), detail::raw_access::get(ptr));
} }
auto& pinf = ptr->node(); auto& pinf = ptr->node();
sink->write_value(ptr->id()); // actor id sink->write_value(ptr->id()); // actor id
......
...@@ -31,30 +31,30 @@ ...@@ -31,30 +31,30 @@
#include "cppa/logging.hpp" #include "cppa/logging.hpp"
#include "cppa/scheduler.hpp" #include "cppa/scheduler.hpp"
#include "cppa/singletons.hpp" #include "cppa/singletons.hpp"
#include "cppa/blocking_untyped_actor.hpp" #include "cppa/blocking_actor.hpp"
#include "cppa/detail/actor_registry.hpp" #include "cppa/detail/actor_registry.hpp"
namespace cppa { namespace cppa {
void blocking_untyped_actor::response_future::await(behavior& bhvr) { void blocking_actor::response_future::await(behavior& bhvr) {
m_self->dequeue_response(bhvr, m_mid); m_self->dequeue_response(bhvr, m_mid);
} }
void blocking_untyped_actor::await_all_other_actors_done() { void blocking_actor::await_all_other_actors_done() {
get_actor_registry()->await_running_count_equal(1); get_actor_registry()->await_running_count_equal(1);
} }
blocking_untyped_actor::response_future blocking_actor::response_future
blocking_untyped_actor::sync_send_tuple(const actor& dest, any_tuple what) { blocking_actor::sync_send_tuple(const actor& dest, any_tuple what) {
auto nri = new_request_id(); auto nri = new_request_id();
dest->enqueue({address(), dest, nri}, std::move(what)); dest->enqueue({address(), dest, nri}, std::move(what));
return {nri.response_id(), this}; return {nri.response_id(), this};
} }
blocking_untyped_actor::response_future blocking_actor::response_future
blocking_untyped_actor::timed_sync_send_tuple(const util::duration& rtime, blocking_actor::timed_sync_send_tuple(const util::duration& rtime,
const actor& dest, const actor& dest,
any_tuple what) { any_tuple what) {
return {timed_sync_send_tuple_impl(message_priority::normal, dest, rtime, return {timed_sync_send_tuple_impl(message_priority::normal, dest, rtime,
...@@ -62,7 +62,7 @@ blocking_untyped_actor::timed_sync_send_tuple(const util::duration& rtime, ...@@ -62,7 +62,7 @@ blocking_untyped_actor::timed_sync_send_tuple(const util::duration& rtime,
this}; this};
} }
void blocking_untyped_actor::quit(std::uint32_t reason) { void blocking_actor::quit(std::uint32_t reason) {
planned_exit_reason(reason); planned_exit_reason(reason);
throw actor_exited(reason); throw actor_exited(reason);
} }
......
...@@ -36,8 +36,6 @@ ...@@ -36,8 +36,6 @@
namespace cppa { namespace cppa {
channel::channel(const std::nullptr_t&) : m_ptr(nullptr) { }
channel::channel(const invalid_actor_t&) : m_ptr(nullptr) { } channel::channel(const invalid_actor_t&) : m_ptr(nullptr) { }
channel::channel(const actor& other) : m_ptr(detail::raw_access::get(other)) { } channel::channel(const actor& other) : m_ptr(detail::raw_access::get(other)) { }
......
...@@ -40,16 +40,16 @@ namespace cppa { ...@@ -40,16 +40,16 @@ namespace cppa {
namespace policy { namespace policy {
void context_switching_resume::trampoline(void* this_ptr) { void context_switching_resume::trampoline(void* this_ptr) {
auto _this = reinterpret_cast<blocking_untyped_actor*>(this_ptr); auto self = reinterpret_cast<blocking_actor*>(this_ptr);
auto shut_actor_down = [_this](std::uint32_t reason) { auto shut_actor_down = [self](std::uint32_t reason) {
if (_this->planned_exit_reason() == exit_reason::not_exited) { if (self->planned_exit_reason() == exit_reason::not_exited) {
_this->planned_exit_reason(reason); self->planned_exit_reason(reason);
} }
_this->on_exit(); self->on_exit();
_this->cleanup(_this->planned_exit_reason()); self->cleanup(self->planned_exit_reason());
}; };
try { try {
_this->act(); self->act();
shut_actor_down(exit_reason::normal); shut_actor_down(exit_reason::normal);
} }
catch (actor_exited& e) { catch (actor_exited& e) {
...@@ -77,6 +77,4 @@ void context_switching_resume::trampoline(void*) { ...@@ -77,6 +77,4 @@ void context_switching_resume::trampoline(void*) {
} // namespace policy } // namespace policy
} // namespace cppa } // namespace cppa
namespace cppa { int keep_compiler_happy_function() { return 42; } }
#endif // ifdef CPPA_DISABLE_CONTEXT_SWITCHING #endif // ifdef CPPA_DISABLE_CONTEXT_SWITCHING
...@@ -31,11 +31,12 @@ ...@@ -31,11 +31,12 @@
#include "cppa/scheduler.hpp" #include "cppa/scheduler.hpp"
#include "cppa/singletons.hpp" #include "cppa/singletons.hpp"
#include "cppa/message_id.hpp" #include "cppa/message_id.hpp"
#include "cppa/untyped_actor.hpp" #include "cppa/event_based_actor.hpp"
namespace cppa { namespace cppa {
continue_helper& continue_helper::continue_with(behavior::continuation_fun fun) { continue_helper&
continue_helper::continue_with(behavior::continuation_fun fun) {
auto ref_opt = m_self->bhvr_stack().sync_handler(m_mid); auto ref_opt = m_self->bhvr_stack().sync_handler(m_mid);
if (ref_opt) { if (ref_opt) {
behavior cpy = *ref_opt; behavior cpy = *ref_opt;
...@@ -45,19 +46,19 @@ continue_helper& continue_helper::continue_with(behavior::continuation_fun fun) ...@@ -45,19 +46,19 @@ continue_helper& continue_helper::continue_with(behavior::continuation_fun fun)
return *this; return *this;
} }
void untyped_actor::forward_to(const actor& whom) { void event_based_actor::forward_to(const actor& whom) {
forward_message(whom, message_priority::normal); forward_message(whom, message_priority::normal);
} }
untyped_actor::response_future untyped_actor::sync_send_tuple(const actor& dest, event_based_actor::response_future
any_tuple what) { event_based_actor::sync_send_tuple(const actor& dest, any_tuple what) {
auto nri = new_request_id(); auto nri = new_request_id();
dest->enqueue({address(), dest, nri}, std::move(what)); dest->enqueue({address(), dest, nri}, std::move(what));
return {nri.response_id(), this}; return {nri.response_id(), this};
} }
untyped_actor::response_future event_based_actor::response_future
untyped_actor::timed_sync_send_tuple(const util::duration& rtime, event_based_actor::timed_sync_send_tuple(const util::duration& rtime,
const actor& dest, const actor& dest,
any_tuple what) { any_tuple what) {
return {timed_sync_send_tuple_impl(message_priority::normal, dest, rtime, return {timed_sync_send_tuple_impl(message_priority::normal, dest, rtime,
......
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
namespace cppa { namespace cppa {
namespace detail { namespace detail {
void functor_based_actor::create(untyped_actor*, void_fun fun) { void functor_based_actor::create(event_based_actor*, void_fun fun) {
m_make_behavior = [=](untyped_actor* self) -> behavior { m_make_behavior = [=](event_based_actor* self) -> behavior {
fun(self); fun(self);
return behavior{}; return behavior{};
}; };
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
namespace cppa { namespace cppa {
namespace detail { namespace detail {
void functor_based_blocking_actor::create(blocking_untyped_actor*, act_fun fun) { void functor_based_blocking_actor::create(blocking_actor*, act_fun fun) {
m_act = fun; m_act = fun;
} }
......
...@@ -87,7 +87,7 @@ const std::string& group::module_name() const { ...@@ -87,7 +87,7 @@ const std::string& group::module_name() const {
return get_module()->name(); return get_module()->name();
} }
struct group_nameserver : untyped_actor { struct group_nameserver : event_based_actor {
behavior make_behavior() override { behavior make_behavior() override {
return ( return (
on(atom("GET_GROUP"), arg_match) >> [](const std::string& name) { on(atom("GET_GROUP"), arg_match) >> [](const std::string& name) {
......
...@@ -40,8 +40,8 @@ ...@@ -40,8 +40,8 @@
#include "cppa/any_tuple.hpp" #include "cppa/any_tuple.hpp"
#include "cppa/serializer.hpp" #include "cppa/serializer.hpp"
#include "cppa/deserializer.hpp" #include "cppa/deserializer.hpp"
#include "cppa/untyped_actor.hpp"
#include "cppa/message_header.hpp" #include "cppa/message_header.hpp"
#include "cppa/event_based_actor.hpp"
#include "cppa/io/middleman.hpp" #include "cppa/io/middleman.hpp"
...@@ -132,7 +132,7 @@ class local_group : public group { ...@@ -132,7 +132,7 @@ class local_group : public group {
typedef intrusive_ptr<local_group> local_group_ptr; typedef intrusive_ptr<local_group> local_group_ptr;
class local_broker : public untyped_actor { class local_broker : public event_based_actor {
public: public:
...@@ -218,8 +218,8 @@ class local_group_proxy : public local_group { ...@@ -218,8 +218,8 @@ class local_group_proxy : public local_group {
template<typename... Ts> template<typename... Ts>
local_group_proxy(actor remote_broker, Ts&&... args) local_group_proxy(actor remote_broker, Ts&&... args)
: super(false, forward<Ts>(args)...) { : super(false, forward<Ts>(args)...) {
CPPA_REQUIRE(m_broker == nullptr); CPPA_REQUIRE(m_broker == invalid_actor);
CPPA_REQUIRE(remote_broker != nullptr); CPPA_REQUIRE(remote_broker != invalid_actor);
m_broker = move(remote_broker); m_broker = move(remote_broker);
m_proxy_broker = spawn<proxy_broker, hidden>(this); m_proxy_broker = spawn<proxy_broker, hidden>(this);
} }
...@@ -230,7 +230,7 @@ class local_group_proxy : public local_group { ...@@ -230,7 +230,7 @@ class local_group_proxy : public local_group {
if (res.first) { if (res.first) {
if (res.second == 1) { if (res.second == 1) {
// join the remote source // join the remote source
send_as(nullptr, m_broker, atom("JOIN"), m_proxy_broker); anon_send(m_broker, atom("JOIN"), m_proxy_broker);
} }
return {who, this}; return {who, this};
} }
...@@ -244,7 +244,7 @@ class local_group_proxy : public local_group { ...@@ -244,7 +244,7 @@ class local_group_proxy : public local_group {
if (res.first && res.second == 0) { if (res.first && res.second == 0) {
// leave the remote source, // leave the remote source,
// because there's no more subscriber on this node // because there's no more subscriber on this node
send_as(nullptr, m_broker, atom("LEAVE"), m_proxy_broker); anon_send(m_broker, atom("LEAVE"), m_proxy_broker);
} }
} }
...@@ -261,7 +261,7 @@ class local_group_proxy : public local_group { ...@@ -261,7 +261,7 @@ class local_group_proxy : public local_group {
typedef intrusive_ptr<local_group_proxy> local_group_proxy_ptr; typedef intrusive_ptr<local_group_proxy> local_group_proxy_ptr;
class proxy_broker : public untyped_actor { class proxy_broker : public event_based_actor {
public: public:
...@@ -339,7 +339,7 @@ class local_group_module : public group::module { ...@@ -339,7 +339,7 @@ class local_group_module : public group::module {
void serialize(local_group* ptr, serializer* sink) { void serialize(local_group* ptr, serializer* sink) {
// serialize identifier & broker // serialize identifier & broker
sink->write_value(ptr->identifier()); sink->write_value(ptr->identifier());
CPPA_REQUIRE(ptr->broker() != nullptr); CPPA_REQUIRE(ptr->broker() != invalid_actor);
m_actor_utype->serialize(&ptr->broker(), sink); m_actor_utype->serialize(&ptr->broker(), sink);
} }
...@@ -411,7 +411,7 @@ class shared_map : public ref_counted { ...@@ -411,7 +411,7 @@ class shared_map : public ref_counted {
lock_type guard(m_mtx); lock_type guard(m_mtx);
auto i = m_instances.find(key); auto i = m_instances.find(key);
if (i == m_instances.end()) { if (i == m_instances.end()) {
send_as(nullptr, m_worker, atom("FETCH"), key); anon_send(m_worker, atom("FETCH"), key);
do { do {
m_cond.wait(guard); m_cond.wait(guard);
} while ((i = m_instances.find(key)) == m_instances.end()); } while ((i = m_instances.find(key)) == m_instances.end());
...@@ -462,7 +462,7 @@ class remote_group_module : public group::module { ...@@ -462,7 +462,7 @@ class remote_group_module : public group::module {
auto sm = make_counted<shared_map>(); auto sm = make_counted<shared_map>();
group::module_ptr _this = this; group::module_ptr _this = this;
m_map = sm; m_map = sm;
m_map->m_worker = spawn<hidden>([=](untyped_actor* self) -> behavior { m_map->m_worker = spawn<hidden>([=](event_based_actor* self) -> behavior {
CPPA_LOGC_TRACE(detail::demangle(typeid(*_this)), CPPA_LOGC_TRACE(detail::demangle(typeid(*_this)),
"remote_group_module$worker", "remote_group_module$worker",
""); "");
......
...@@ -55,12 +55,10 @@ class down_observer : public attachable { ...@@ -55,12 +55,10 @@ class down_observer : public attachable {
} }
void actor_exited(std::uint32_t reason) { void actor_exited(std::uint32_t reason) {
if (m_observer) { auto ptr = detail::raw_access::get(m_observer);
auto ptr = detail::actor_addr_cast<abstract_actor>(m_observer);
message_header hdr{m_observed, ptr, message_id{}.with_high_priority()}; message_header hdr{m_observed, ptr, message_id{}.with_high_priority()};
hdr.deliver(make_any_tuple(down_msg{m_observed, reason})); hdr.deliver(make_any_tuple(down_msg{m_observed, reason}));
} }
}
bool matches(const attachable::token& match_token) { bool matches(const attachable::token& match_token) {
if (match_token.subtype == typeid(down_observer)) { if (match_token.subtype == typeid(down_observer)) {
...@@ -72,15 +70,13 @@ class down_observer : public attachable { ...@@ -72,15 +70,13 @@ class down_observer : public attachable {
}; };
constexpr const char* s_default_debug_name = "actor";
} // namespace <anonymous> } // namespace <anonymous>
local_actor::local_actor() local_actor::local_actor()
: m_trap_exit(false) : m_trap_exit(false)
, m_dummy_node(), m_current_node(&m_dummy_node) , m_dummy_node(), m_current_node(&m_dummy_node)
, m_planned_exit_reason(exit_reason::not_exited) , m_planned_exit_reason(exit_reason::not_exited)
, m_state(actor_state::ready) { , m_state(actor_state::ready) {
m_node = node_id::get(); m_node = node_id::get();
} }
...@@ -88,13 +84,13 @@ local_actor::~local_actor() { } ...@@ -88,13 +84,13 @@ local_actor::~local_actor() { }
void local_actor::monitor(const actor_addr& whom) { void local_actor::monitor(const actor_addr& whom) {
if (!whom) return; if (!whom) return;
auto ptr = detail::actor_addr_cast<abstract_actor>(whom); auto ptr = detail::raw_access::get(whom);
ptr->attach(attachable_ptr{new down_observer(address(), whom)}); ptr->attach(attachable_ptr{new down_observer(address(), whom)});
} }
void local_actor::demonitor(const actor_addr& whom) { void local_actor::demonitor(const actor_addr& whom) {
if (!whom) return; if (!whom) return;
auto ptr = detail::actor_addr_cast<abstract_actor>(whom); auto ptr = detail::raw_access::get(whom);
attachable::token mtoken{typeid(down_observer), this}; attachable::token mtoken{typeid(down_observer), this};
ptr->detach(mtoken); ptr->detach(mtoken);
} }
...@@ -124,10 +120,10 @@ void local_actor::reply_message(any_tuple&& what) { ...@@ -124,10 +120,10 @@ void local_actor::reply_message(any_tuple&& what) {
if (!whom) return; if (!whom) return;
auto& id = m_current_node->mid; auto& id = m_current_node->mid;
if (id.valid() == false || id.is_response()) { if (id.valid() == false || id.is_response()) {
send_tuple(detail::actor_addr_cast<abstract_actor>(whom), std::move(what)); send_tuple(detail::raw_access::get(whom), std::move(what));
} }
else if (!id.is_answered()) { else if (!id.is_answered()) {
auto ptr = detail::actor_addr_cast<abstract_actor>(whom); auto ptr = detail::raw_access::get(whom);
ptr->enqueue({address(), ptr, id.response_id()}, std::move(what)); ptr->enqueue({address(), ptr, id.response_id()}, std::move(what));
id.mark_as_answered(); id.mark_as_answered();
} }
...@@ -207,4 +203,10 @@ message_id local_actor::timed_sync_send_tuple_impl(message_priority mp, ...@@ -207,4 +203,10 @@ message_id local_actor::timed_sync_send_tuple_impl(message_priority mp,
return rri; return rri;
} }
void anon_send_exit(const actor_addr& whom, std::uint32_t reason) {
auto ptr = detail::raw_access::get(whom);
ptr->enqueue({invalid_actor_addr, ptr, message_id{}.with_high_priority()},
make_any_tuple(exit_msg{invalid_actor_addr, reason}));
}
} // namespace cppa } // namespace cppa
...@@ -267,58 +267,65 @@ void peer::kill_proxy(const actor_addr& sender, ...@@ -267,58 +267,65 @@ void peer::kill_proxy(const actor_addr& sender,
void peer::deliver(const message_header& hdr, any_tuple msg) { void peer::deliver(const message_header& hdr, any_tuple msg) {
CPPA_LOG_TRACE(""); CPPA_LOG_TRACE("");
if (hdr.sender && hdr.sender->is_remote()) { if (hdr.sender && hdr.sender->is_remote()) {
auto ptr = detail::actor_addr_cast<actor_proxy>(hdr.sender); // is_remote() is guaranteed to return true if and only if
// the actor is derived from actor_proxy, hence we do not
// need to use a dynamic_cast here
auto ptr = static_cast<actor_proxy*>(detail::raw_access::get(hdr.sender));
ptr->deliver(hdr, std::move(msg)); ptr->deliver(hdr, std::move(msg));
} }
else hdr.deliver(std::move(msg)); else hdr.deliver(std::move(msg));
} }
void peer::link(const actor_addr& sender, const actor_addr& receiver) { void peer::link(const actor_addr& lhs, const actor_addr& rhs) {
// this message is sent from default_actor_proxy in link_to and // this message is sent from default_actor_proxy in link_to and
// establish_backling to cause the original actor (sender) to establish // establish_backling to cause the original actor (sender) to establish
// a link to ptr as well // a link to ptr as well
CPPA_LOG_TRACE(CPPA_TARG(sender, to_string) << ", " CPPA_LOG_TRACE(CPPA_TARG(lhs, to_string) << ", "
<< CPPA_TARG(receiver, to_string)); << CPPA_TARG(rhs, to_string));
CPPA_LOG_ERROR_IF(!sender, "received 'LINK' from invalid sender"); CPPA_LOG_ERROR_IF(!lhs, "received 'LINK' from invalid sender");
CPPA_LOG_ERROR_IF(!receiver, "received 'LINK' with invalid receiver"); CPPA_LOG_ERROR_IF(!rhs, "received 'LINK' with invalid receiver");
if (!sender || !receiver) return; if (!lhs || !rhs) return;
auto locally_link_proxy = [](const actor_addr& lhs, const actor_addr& rhs) { auto locally_link_proxy = [](const actor_addr& proxy, const actor_addr& addr) {
detail::actor_addr_cast<actor_proxy>(lhs)->local_link_to(rhs); // again, no need to to use a dynamic_cast here
auto ptr = static_cast<actor_proxy*>(detail::raw_access::get(proxy));
ptr->local_link_to(addr);
}; };
switch ((sender->is_remote() ? 0x10 : 0x00) | (receiver->is_remote() ? 0x01 : 0x00)) { switch ((lhs->is_remote() ? 0x10 : 0x00) | (rhs->is_remote() ? 0x01 : 0x00)) {
case 0x00: // both local case 0x00: // both local
case 0x11: // both remote case 0x11: // both remote
detail::actor_addr_cast<abstract_actor>(sender)->link_to(receiver); detail::raw_access::get(lhs)->link_to(rhs);
break; break;
case 0x10: // sender is remote case 0x10: // sender is remote
locally_link_proxy(sender, receiver); locally_link_proxy(lhs, rhs);
break; break;
case 0x01: // receiver is remote case 0x01: // receiver is remote
locally_link_proxy(receiver, sender); locally_link_proxy(rhs, lhs);
break; break;
default: CPPA_LOG_ERROR("logic error"); default: CPPA_LOG_ERROR("logic error");
} }
} }
void peer::unlink(const actor_addr& sender, const actor_addr& receiver) { void peer::unlink(const actor_addr& lhs, const actor_addr& rhs) {
CPPA_LOG_TRACE(CPPA_TARG(sender, to_string) << ", " CPPA_LOG_TRACE(CPPA_TARG(lhs, to_string) << ", "
<< CPPA_TARG(receiver, to_string)); << CPPA_TARG(rhs, to_string));
CPPA_LOG_ERROR_IF(!sender, "received 'UNLINK' from invalid sender"); CPPA_LOG_ERROR_IF(!lhs, "received 'UNLINK' from invalid sender");
CPPA_LOG_ERROR_IF(!receiver, "received 'UNLINK' with invalid target"); CPPA_LOG_ERROR_IF(!rhs, "received 'UNLINK' with invalid target");
if (!sender || !receiver) return; if (!lhs || !rhs) return;
auto locally_unlink_proxy = [](const actor_addr& lhs, const actor_addr& rhs) { auto locally_unlink_proxy = [](const actor_addr& proxy, const actor_addr& addr) {
detail::actor_addr_cast<actor_proxy>(lhs)->local_unlink_from(rhs); // again, no need to to use a dynamic_cast here
auto ptr = static_cast<actor_proxy*>(detail::raw_access::get(proxy));
ptr->local_unlink_from(addr);
}; };
switch ((sender->is_remote() ? 0x10 : 0x00) | (receiver->is_remote() ? 0x01 : 0x00)) { switch ((lhs->is_remote() ? 0x10 : 0x00) | (rhs->is_remote() ? 0x01 : 0x00)) {
case 0x00: // both local case 0x00: // both local
case 0x11: // both remote case 0x11: // both remote
detail::actor_addr_cast<abstract_actor>(sender)->unlink_from(receiver); detail::raw_access::get(lhs)->unlink_from(rhs);
break; break;
case 0x10: // sender is remote case 0x10: // sender is remote
locally_unlink_proxy(sender, receiver); locally_unlink_proxy(lhs, rhs);
break; break;
case 0x01: // receiver is remote case 0x01: // receiver is remote
locally_unlink_proxy(receiver, sender); locally_unlink_proxy(rhs, lhs);
break; break;
default: CPPA_LOG_ERROR("logic error"); default: CPPA_LOG_ERROR("logic error");
} }
......
...@@ -52,7 +52,7 @@ response_promise::operator bool() const { ...@@ -52,7 +52,7 @@ response_promise::operator bool() const {
void response_promise::deliver(any_tuple msg) { void response_promise::deliver(any_tuple msg) {
if (m_to) { if (m_to) {
auto ptr = detail::actor_addr_cast<abstract_actor>(m_to); auto ptr = detail::raw_access::get(m_to);
ptr->enqueue({m_from, ptr, m_id}, move(msg)); ptr->enqueue({m_from, ptr, m_id}, move(msg));
m_to = invalid_actor_addr; m_to = invalid_actor_addr;
} }
......
...@@ -95,7 +95,7 @@ inline void insert_dmsg(Map& storage, const util::duration& d, ...@@ -95,7 +95,7 @@ inline void insert_dmsg(Map& storage, const util::duration& d,
storage.insert(std::make_pair(std::move(tout), std::move(dmsg))); storage.insert(std::make_pair(std::move(tout), std::move(dmsg)));
} }
class timer_actor final : public detail::proper_actor<blocking_untyped_actor, class timer_actor final : public detail::proper_actor<blocking_actor,
timer_actor_policies> { timer_actor_policies> {
public: public:
...@@ -194,7 +194,7 @@ class scheduler_helper { ...@@ -194,7 +194,7 @@ class scheduler_helper {
static void timer_loop(timer_actor* self); static void timer_loop(timer_actor* self);
static void printer_loop(blocking_untyped_actor* self); static void printer_loop(blocking_actor* self);
}; };
...@@ -202,7 +202,7 @@ void scheduler_helper::timer_loop(timer_actor* self) { ...@@ -202,7 +202,7 @@ void scheduler_helper::timer_loop(timer_actor* self) {
self->act(); self->act();
} }
void scheduler_helper::printer_loop(blocking_untyped_actor* self) { void scheduler_helper::printer_loop(blocking_actor* self) {
std::map<actor_addr, std::string> out; std::map<actor_addr, std::string> out;
auto flush_output = [&out](const actor_addr& s) { auto flush_output = [&out](const actor_addr& s) {
auto i = out.find(s); auto i = out.find(s);
......
...@@ -39,11 +39,11 @@ namespace cppa { ...@@ -39,11 +39,11 @@ namespace cppa {
namespace { namespace {
struct impl : blocking_untyped_actor { struct impl : blocking_actor {
void act() override { } void act() override { }
}; };
blocking_untyped_actor* alloc() { blocking_actor* alloc() {
using namespace policy; using namespace policy;
return new detail::proper_actor<impl, return new detail::proper_actor<impl,
policies<no_scheduling, policies<no_scheduling,
......
...@@ -42,10 +42,11 @@ namespace cppa { namespace detail { ...@@ -42,10 +42,11 @@ namespace cppa { namespace detail {
sync_request_bouncer::sync_request_bouncer(std::uint32_t r) sync_request_bouncer::sync_request_bouncer(std::uint32_t r)
: rsn(r == exit_reason::not_exited ? exit_reason::normal : r) { } : rsn(r == exit_reason::not_exited ? exit_reason::normal : r) { }
void sync_request_bouncer::operator()(const actor_addr& sender, const message_id& mid) const { void sync_request_bouncer::operator()(const actor_addr& sender,
const message_id& mid) const {
CPPA_REQUIRE(rsn != exit_reason::not_exited); CPPA_REQUIRE(rsn != exit_reason::not_exited);
if (sender && mid.is_request()) { if (sender && mid.is_request()) {
auto ptr = detail::actor_addr_cast<abstract_actor>(sender); auto ptr = detail::raw_access::get(sender);
ptr->enqueue({invalid_actor_addr, ptr, mid.response_id()}, ptr->enqueue({invalid_actor_addr, ptr, mid.response_id()},
make_any_tuple(atom("EXITED"), rsn)); make_any_tuple(atom("EXITED"), rsn));
} }
......
...@@ -68,9 +68,10 @@ using namespace io; ...@@ -68,9 +68,10 @@ using namespace io;
void publish(actor whom, std::unique_ptr<acceptor> aptr) { void publish(actor whom, std::unique_ptr<acceptor> aptr) {
CPPA_LOGF_TRACE(CPPA_TARG(whom, to_string) << ", " << CPPA_MARG(aptr, get)); CPPA_LOGF_TRACE(CPPA_TARG(whom, to_string) << ", " << CPPA_MARG(aptr, get));
if (!whom) return; if (!whom) return;
get_actor_registry()->put(whom->id(), detail::actor_addr_cast<abstract_actor>(whom)); get_actor_registry()->put(whom->id(), detail::raw_access::get(whom));
auto mm = get_middleman(); auto mm = get_middleman();
mm->register_acceptor(whom, new peer_acceptor(mm, move(aptr), whom)); auto addr = whom->address();
mm->register_acceptor(addr, new peer_acceptor(mm, move(aptr), addr));
} }
void publish(actor whom, std::uint16_t port, const char* addr) { void publish(actor whom, std::uint16_t port, const char* addr) {
......
...@@ -190,7 +190,7 @@ void serialize_impl(const actor& ptr, serializer* sink) { ...@@ -190,7 +190,7 @@ void serialize_impl(const actor& ptr, serializer* sink) {
void deserialize_impl(actor& ptr, deserializer* source) { void deserialize_impl(actor& ptr, deserializer* source) {
actor_addr addr; actor_addr addr;
deserialize_impl(addr, source); deserialize_impl(addr, source);
ptr = detail::raw_access::unsafe_cast(detail::actor_addr_cast<abstract_actor>(addr)); ptr = detail::raw_access::unsafe_cast(addr);
} }
void serialize_impl(const group_ptr& ptr, serializer* sink) { void serialize_impl(const group_ptr& ptr, serializer* sink) {
...@@ -255,7 +255,7 @@ void deserialize_impl(channel& ptrref, deserializer* source) { ...@@ -255,7 +255,7 @@ void deserialize_impl(channel& ptrref, deserializer* source) {
case 1: { case 1: {
actor tmp; actor tmp;
deserialize_impl(tmp, source); deserialize_impl(tmp, source);
ptrref = detail::actor_addr_cast<abstract_actor>(tmp); ptrref = detail::raw_access::get(tmp);
break; break;
} }
case 2: { case 2: {
...@@ -273,7 +273,10 @@ void deserialize_impl(channel& ptrref, deserializer* source) { ...@@ -273,7 +273,10 @@ void deserialize_impl(channel& ptrref, deserializer* source) {
void serialize_impl(const any_tuple& tup, serializer* sink) { void serialize_impl(const any_tuple& tup, serializer* sink) {
auto tname = tup.tuple_type_names(); auto tname = tup.tuple_type_names();
auto uti = get_uniform_type_info_map()->by_uniform_name(tname ? *tname : detail::get_tuple_type_names(*tup.vals())); auto uti = get_uniform_type_info_map()
->by_uniform_name(tname
? *tname
: detail::get_tuple_type_names(*tup.vals()));
if (uti == nullptr) { if (uti == nullptr) {
std::string err = "could not get uniform type info for \""; std::string err = "could not get uniform type info for \"";
err += tname ? *tname : detail::get_tuple_type_names(*tup.vals()); err += tname ? *tname : detail::get_tuple_type_names(*tup.vals());
...@@ -520,7 +523,8 @@ class int_tinfo : public abstract_int_tinfo { ...@@ -520,7 +523,8 @@ class int_tinfo : public abstract_int_tinfo {
bool equals(const std::type_info& ti) const { bool equals(const std::type_info& ti) const {
auto tptr = &ti; auto tptr = &ti;
return std::any_of(m_natives.begin(), m_natives.end(), [tptr](const std::type_info* ptr) { return std::any_of(m_natives.begin(), m_natives.end(),
[tptr](const std::type_info* ptr) {
return types_equal(ptr, tptr); return types_equal(ptr, tptr);
}); });
} }
...@@ -787,21 +791,21 @@ class utim_impl : public uniform_type_info_map { ...@@ -787,21 +791,21 @@ class utim_impl : public uniform_type_info_map {
auto cmp = [](pointer lhs, pointer rhs) { auto cmp = [](pointer lhs, pointer rhs) {
return strcmp(lhs->name(), rhs->name()) < 0; return strcmp(lhs->name(), rhs->name()) < 0;
}; };
if (!std::is_sorted(m_builtin_types.begin(), m_builtin_types.end(), cmp)) { auto& arr = m_builtin_types;
std::cerr << "FATAL: uniform type map not sorted" << std::endl; if (!std::is_sorted(arr.begin(), arr.end(), cmp)) {
std::cerr << "FATAL: uniform type map not sorted" << std::endl
std::cerr << "order is:" << std::endl; << "order is:" << std::endl;
for (auto ptr : m_builtin_types) std::cerr << ptr->name() << std::endl; for (auto ptr : arr) std::cerr << ptr->name() << std::endl;
std::sort(arr.begin(), arr.end(), cmp);
std::sort(m_builtin_types.begin(), m_builtin_types.end(), cmp); std::cerr << std::endl << "order should be:" << std::endl;
std::cerr << "\norder should be:" << std::endl; for (auto ptr : arr) std::cerr << ptr->name() << std::endl;
for (auto ptr : m_builtin_types) std::cerr << ptr->name() << std::endl;
abort(); abort();
} }
auto cmp2 = [](const char** lhs, const char** rhs) { auto cmp2 = [](const char** lhs, const char** rhs) {
return strcmp(lhs[0], rhs[0]) < 0; return strcmp(lhs[0], rhs[0]) < 0;
}; };
if (!std::is_sorted(std::begin(mapped_type_names), std::end(mapped_type_names), cmp2)) { if (!std::is_sorted(std::begin(mapped_type_names),
std::end(mapped_type_names), cmp2)) {
std::cerr << "FATAL: mapped_type_names not sorted" << std::endl; std::cerr << "FATAL: mapped_type_names not sorted" << std::endl;
abort(); abort();
} }
...@@ -847,7 +851,8 @@ class utim_impl : public uniform_type_info_map { ...@@ -847,7 +851,8 @@ class utim_impl : public uniform_type_info_map {
pointer insert(std::unique_ptr<uniform_type_info> uti) { pointer insert(std::unique_ptr<uniform_type_info> uti) {
std::unique_lock<util::shared_spinlock> guard(m_lock); std::unique_lock<util::shared_spinlock> guard(m_lock);
auto e = m_user_types.end(); auto e = m_user_types.end();
auto i = std::lower_bound(m_user_types.begin(), e, uti.get(), [](uniform_type_info* lhs, pointer rhs) { auto i = std::lower_bound(m_user_types.begin(), e, uti.get(),
[](uniform_type_info* lhs, pointer rhs) {
return strcmp(lhs->name(), rhs->name()) < 0; return strcmp(lhs->name(), rhs->name()) < 0;
}); });
if (i == e) { if (i == e) {
...@@ -934,7 +939,8 @@ class utim_impl : public uniform_type_info_map { ...@@ -934,7 +939,8 @@ class utim_impl : public uniform_type_info_map {
pointer find_name(const Container& c, const std::string& name) const { pointer find_name(const Container& c, const std::string& name) const {
auto e = c.end(); auto e = c.end();
// both containers are sorted // both containers are sorted
auto i = std::lower_bound(c.begin(), e, name, [](pointer p, const std::string& n) { auto i = std::lower_bound(c.begin(), e, name,
[](pointer p, const std::string& n) {
return p->name() < n; return p->name() < n;
}); });
return (i != e && (*i)->name() == name) ? *i : nullptr; return (i != e && (*i)->name() == name) ? *i : nullptr;
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
\******************************************************************************/ \******************************************************************************/
#include "cppa/channel.hpp"
#include "cppa/actor_addr.hpp" #include "cppa/actor_addr.hpp"
#include "cppa/untyped_actor_handle.hpp" #include "cppa/untyped_actor_handle.hpp"
...@@ -45,4 +46,9 @@ bool untyped_actor_handle::is_remote() const { ...@@ -45,4 +46,9 @@ bool untyped_actor_handle::is_remote() const {
return m_ptr ? m_ptr->is_proxy() : false; return m_ptr ? m_ptr->is_proxy() : false;
} }
intptr_t untyped_actor_handle::compare(const untyped_actor_handle& other) const {
return channel::compare(m_ptr.get(), other.m_ptr.get());
}
} // namespace cppa } // namespace cppa
...@@ -57,27 +57,27 @@ size_t pongs() { ...@@ -57,27 +57,27 @@ size_t pongs() {
return s_pongs; return s_pongs;
} }
void ping(blocking_untyped_actor* self, size_t num_pings) { void ping(blocking_actor* self, size_t num_pings) {
CPPA_LOGF_TRACE("num_pings = " << num_pings); CPPA_LOGF_TRACE("num_pings = " << num_pings);
s_pongs = 0; s_pongs = 0;
self->receive_loop(ping_behavior(self, num_pings)); self->receive_loop(ping_behavior(self, num_pings));
} }
void event_based_ping(untyped_actor* self, size_t num_pings) { void event_based_ping(event_based_actor* self, size_t num_pings) {
CPPA_LOGF_TRACE("num_pings = " << num_pings); CPPA_LOGF_TRACE("num_pings = " << num_pings);
s_pongs = 0; s_pongs = 0;
self->become(ping_behavior(self, num_pings)); self->become(ping_behavior(self, num_pings));
} }
void pong(blocking_untyped_actor* self, actor ping_actor) { void pong(blocking_actor* self, actor ping_actor) {
CPPA_LOGF_TRACE("ping_actor = " << to_string(ping_actor)); CPPA_LOGF_TRACE("ping_actor = " << to_string(ping_actor));
self->send(ping_actor, atom("pong"), 0); // kickoff self->send(ping_actor, atom("pong"), 0); // kickoff
self->receive_loop(pong_behavior(self)); self->receive_loop(pong_behavior(self));
} }
void event_based_pong(untyped_actor* self, actor ping_actor) { void event_based_pong(event_based_actor* self, actor ping_actor) {
CPPA_LOGF_TRACE("ping_actor = " << to_string(ping_actor)); CPPA_LOGF_TRACE("ping_actor = " << to_string(ping_actor));
CPPA_REQUIRE(ping_actor != nullptr); CPPA_REQUIRE(ping_actor != invalid_actor);
self->send(ping_actor, atom("pong"), 0); // kickoff self->send(ping_actor, atom("pong"), 0); // kickoff
self->become(pong_behavior(self)); self->become(pong_behavior(self));
} }
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
#include <cstddef> #include <cstddef>
#include "cppa/cppa_fwd.hpp" #include "cppa/cppa_fwd.hpp"
void ping(cppa::blocking_untyped_actor*, size_t num_pings); void ping(cppa::blocking_actor*, size_t num_pings);
void event_based_ping(cppa::untyped_actor*, size_t num_pings); void event_based_ping(cppa::event_based_actor*, size_t num_pings);
void pong(cppa::blocking_untyped_actor*, cppa::actor ping_actor); void pong(cppa::blocking_actor*, cppa::actor ping_actor);
void event_based_pong(cppa::untyped_actor*, cppa::actor ping_actor); void event_based_pong(cppa::event_based_actor*, cppa::actor ping_actor);
// returns the number of messages ping received // returns the number of messages ping received
size_t pongs(); size_t pongs();
......
...@@ -29,12 +29,12 @@ void foo() { ...@@ -29,12 +29,12 @@ void foo() {
} }
struct mirror { struct mirror {
mirror(blocking_untyped_actor* self) : m_self(self) { } mirror(blocking_actor* self) : m_self(self) { }
template<typename... Ts> template<typename... Ts>
void operator()(Ts&&... args) { void operator()(Ts&&... args) {
m_self->send(m_self, std::forward<Ts>(args)...); m_self->send(m_self, std::forward<Ts>(args)...);
} }
blocking_untyped_actor* m_self; blocking_actor* m_self;
}; };
int main() { int main() {
......
...@@ -39,7 +39,7 @@ using namespace cppa; ...@@ -39,7 +39,7 @@ using namespace cppa;
namespace { constexpr size_t message_size = sizeof(atom_value) + sizeof(int); } namespace { constexpr size_t message_size = sizeof(atom_value) + sizeof(int); }
void ping(cppa::untyped_actor* self, size_t num_pings) { void ping(cppa::event_based_actor* self, size_t num_pings) {
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
auto count = std::make_shared<size_t>(0); auto count = std::make_shared<size_t>(0);
self->become ( self->become (
...@@ -59,7 +59,7 @@ void ping(cppa::untyped_actor* self, size_t num_pings) { ...@@ -59,7 +59,7 @@ void ping(cppa::untyped_actor* self, size_t num_pings) {
); );
} }
void pong(cppa::untyped_actor* self) { void pong(cppa::event_based_actor* self) {
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
self->become ( self->become (
on(atom("ping"), arg_match) on(atom("ping"), arg_match)
...@@ -85,9 +85,11 @@ void pong(cppa::untyped_actor* self) { ...@@ -85,9 +85,11 @@ void pong(cppa::untyped_actor* self) {
void peer(io::broker* self, io::connection_handle hdl, const actor& buddy) { void peer(io::broker* self, io::connection_handle hdl, const actor& buddy) {
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
CPPA_CHECK(self != nullptr);
CPPA_CHECK(buddy != invalid_actor);
self->monitor(buddy); self->monitor(buddy);
if (self->num_connections() == 0) { if (self->num_connections() == 0) {
cout << "num_connections() != 1" << endl; cerr << "num_connections() != 1" << endl;
throw std::logic_error("num_connections() != 1"); throw std::logic_error("num_connections() != 1");
} }
auto write = [=](atom_value type, int value) { auto write = [=](atom_value type, int value) {
...@@ -145,7 +147,7 @@ int main(int argc, char** argv) { ...@@ -145,7 +147,7 @@ int main(int argc, char** argv) {
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
auto cl = spawn_io(peer, "localhost", port, p); auto cl = spawn_io(peer, "localhost", port, p);
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
send_as(nullptr, p, atom("kickoff"), cl); anon_send(p, atom("kickoff"), cl);
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
}); });
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
......
...@@ -21,7 +21,7 @@ using std::endl; ...@@ -21,7 +21,7 @@ using std::endl;
using std::string; using std::string;
using namespace cppa; using namespace cppa;
void testee(untyped_actor* self, int current_value, int final_result) { void testee(event_based_actor* self, int current_value, int final_result) {
self->become( self->become(
on_arg_match >> [=](int result) { on_arg_match >> [=](int result) {
auto next = result + current_value; auto next = result + current_value;
......
...@@ -22,7 +22,7 @@ typedef std::pair<std::string, std::string> string_pair; ...@@ -22,7 +22,7 @@ typedef std::pair<std::string, std::string> string_pair;
typedef vector<actor> actor_vector; typedef vector<actor> actor_vector;
void reflector(untyped_actor* self) { void reflector(event_based_actor* self) {
self->become ( self->become (
others() >> [=] { others() >> [=] {
CPPA_LOGF_INFO("reflect and quit"); CPPA_LOGF_INFO("reflect and quit");
...@@ -32,7 +32,7 @@ void reflector(untyped_actor* self) { ...@@ -32,7 +32,7 @@ void reflector(untyped_actor* self) {
); );
} }
void spawn5_server_impl(untyped_actor* self, actor client, group_ptr grp) { void spawn5_server_impl(event_based_actor* self, actor client, group_ptr grp) {
CPPA_LOGF_TRACE(CPPA_TARG(client, to_string) CPPA_LOGF_TRACE(CPPA_TARG(client, to_string)
<< ", " << CPPA_TARG(grp, to_string)); << ", " << CPPA_TARG(grp, to_string));
self->spawn_in_group(grp, reflector); self->spawn_in_group(grp, reflector);
...@@ -103,7 +103,7 @@ void spawn5_server_impl(untyped_actor* self, actor client, group_ptr grp) { ...@@ -103,7 +103,7 @@ void spawn5_server_impl(untyped_actor* self, actor client, group_ptr grp) {
} }
// receive seven reply messages (2 local, 5 remote) // receive seven reply messages (2 local, 5 remote)
void spawn5_server(untyped_actor* self, actor client, bool inverted) { void spawn5_server(event_based_actor* self, actor client, bool inverted) {
if (!inverted) spawn5_server_impl(self, client, group::get("local", "foobar")); if (!inverted) spawn5_server_impl(self, client, group::get("local", "foobar"));
else { else {
CPPA_LOGF_INFO("request group"); CPPA_LOGF_INFO("request group");
...@@ -115,7 +115,7 @@ void spawn5_server(untyped_actor* self, actor client, bool inverted) { ...@@ -115,7 +115,7 @@ void spawn5_server(untyped_actor* self, actor client, bool inverted) {
} }
} }
void spawn5_client(untyped_actor* self) { void spawn5_client(event_based_actor* self) {
self->become ( self->become (
on(atom("GetGroup")) >> []() -> group_ptr { on(atom("GetGroup")) >> []() -> group_ptr {
CPPA_LOGF_INFO("received {'GetGroup'}"); CPPA_LOGF_INFO("received {'GetGroup'}");
...@@ -139,7 +139,7 @@ void spawn5_client(untyped_actor* self) { ...@@ -139,7 +139,7 @@ void spawn5_client(untyped_actor* self) {
} // namespace <anonymous> } // namespace <anonymous>
template<typename F> template<typename F>
void await_down(untyped_actor* self, actor ptr, F continuation) { void await_down(event_based_actor* self, actor ptr, F continuation) {
self->become ( self->become (
on_arg_match >> [=](const down_msg& dm) -> bool { on_arg_match >> [=](const down_msg& dm) -> bool {
if (dm.source == ptr) { if (dm.source == ptr) {
...@@ -153,7 +153,7 @@ void await_down(untyped_actor* self, actor ptr, F continuation) { ...@@ -153,7 +153,7 @@ void await_down(untyped_actor* self, actor ptr, F continuation) {
static constexpr size_t num_pings = 10; static constexpr size_t num_pings = 10;
class client : public untyped_actor { class client : public event_based_actor {
public: public:
...@@ -233,7 +233,7 @@ class client : public untyped_actor { ...@@ -233,7 +233,7 @@ class client : public untyped_actor {
}; };
class server : public untyped_actor { class server : public event_based_actor {
public: public:
......
...@@ -56,7 +56,7 @@ class event_testee : public sb_actor<event_testee> { ...@@ -56,7 +56,7 @@ class event_testee : public sb_actor<event_testee> {
// quits after 5 timeouts // quits after 5 timeouts
actor spawn_event_testee2(actor parent) { actor spawn_event_testee2(actor parent) {
struct impl : untyped_actor { struct impl : event_based_actor {
actor parent; actor parent;
impl(actor parent) : parent(parent) { } impl(actor parent) : parent(parent) { }
behavior wait4timeout(int remaining) { behavior wait4timeout(int remaining) {
...@@ -114,7 +114,7 @@ struct chopstick : public sb_actor<chopstick> { ...@@ -114,7 +114,7 @@ struct chopstick : public sb_actor<chopstick> {
class testee_actor { class testee_actor {
void wait4string(blocking_untyped_actor* self) { void wait4string(blocking_actor* self) {
bool string_received = false; bool string_received = false;
self->do_receive ( self->do_receive (
on<string>() >> [&] { on<string>() >> [&] {
...@@ -127,7 +127,7 @@ class testee_actor { ...@@ -127,7 +127,7 @@ class testee_actor {
.until(gref(string_received)); .until(gref(string_received));
} }
void wait4float(blocking_untyped_actor* self) { void wait4float(blocking_actor* self) {
bool float_received = false; bool float_received = false;
self->do_receive ( self->do_receive (
on<float>() >> [&] { on<float>() >> [&] {
...@@ -143,7 +143,7 @@ class testee_actor { ...@@ -143,7 +143,7 @@ class testee_actor {
public: public:
void operator()(blocking_untyped_actor* self) { void operator()(blocking_actor* self) {
self->receive_loop ( self->receive_loop (
on<int>() >> [&] { on<int>() >> [&] {
wait4float(self); wait4float(self);
...@@ -157,7 +157,7 @@ class testee_actor { ...@@ -157,7 +157,7 @@ class testee_actor {
}; };
// self->receives one timeout and quits // self->receives one timeout and quits
void testee1(untyped_actor* self) { void testee1(event_based_actor* self) {
CPPA_LOGF_TRACE(""); CPPA_LOGF_TRACE("");
self->become(after(chrono::milliseconds(10)) >> [=] { self->become(after(chrono::milliseconds(10)) >> [=] {
CPPA_LOGF_TRACE(""); CPPA_LOGF_TRACE("");
...@@ -165,7 +165,7 @@ void testee1(untyped_actor* self) { ...@@ -165,7 +165,7 @@ void testee1(untyped_actor* self) {
}); });
} }
void testee2(untyped_actor* self, actor other) { void testee2(event_based_actor* self, actor other) {
self->link_to(other); self->link_to(other);
self->send(other, uint32_t(1)); self->send(other, uint32_t(1));
self->become ( self->become (
...@@ -262,7 +262,7 @@ class fixed_stack : public sb_actor<fixed_stack> { ...@@ -262,7 +262,7 @@ class fixed_stack : public sb_actor<fixed_stack> {
}; };
behavior echo_actor(untyped_actor* self) { behavior echo_actor(event_based_actor* self) {
return ( return (
others() >> [=]() -> any_tuple { others() >> [=]() -> any_tuple {
self->quit(exit_reason::normal); self->quit(exit_reason::normal);
...@@ -282,7 +282,7 @@ struct simple_mirror : sb_actor<simple_mirror> { ...@@ -282,7 +282,7 @@ struct simple_mirror : sb_actor<simple_mirror> {
}; };
behavior high_priority_testee(untyped_actor* self) { behavior high_priority_testee(event_based_actor* self) {
self->send(self, atom("b")); self->send(self, atom("b"));
self->send(message_priority::high, self, atom("a")); self->send(message_priority::high, self, atom("a"));
// 'a' must be self->received before 'b' // 'a' must be self->received before 'b'
...@@ -305,13 +305,13 @@ behavior high_priority_testee(untyped_actor* self) { ...@@ -305,13 +305,13 @@ behavior high_priority_testee(untyped_actor* self) {
); );
} }
struct high_priority_testee_class : untyped_actor { struct high_priority_testee_class : event_based_actor {
behavior make_behavior() override { behavior make_behavior() override {
return high_priority_testee(this); return high_priority_testee(this);
} }
}; };
struct master : untyped_actor { struct master : event_based_actor {
behavior make_behavior() override { behavior make_behavior() override {
return ( return (
on(atom("done")) >> [=] { on(atom("done")) >> [=] {
...@@ -321,7 +321,7 @@ struct master : untyped_actor { ...@@ -321,7 +321,7 @@ struct master : untyped_actor {
} }
}; };
struct slave : untyped_actor { struct slave : event_based_actor {
slave(actor master) : master{master} { } slave(actor master) : master{master} { }
...@@ -337,13 +337,13 @@ struct slave : untyped_actor { ...@@ -337,13 +337,13 @@ struct slave : untyped_actor {
}; };
void test_serial_reply() { void test_serial_reply() {
auto mirror_behavior = [=](untyped_actor* self) { auto mirror_behavior = [=](event_based_actor* self) {
self->become(others() >> [=]() -> any_tuple { self->become(others() >> [=]() -> any_tuple {
CPPA_LOGF_INFO("return self->last_dequeued()"); CPPA_LOGF_INFO("return self->last_dequeued()");
return self->last_dequeued(); return self->last_dequeued();
}); });
}; };
auto master = spawn([=](untyped_actor* self) { auto master = spawn([=](event_based_actor* self) {
cout << "ID of master: " << self->id() << endl; cout << "ID of master: " << self->id() << endl;
// spawn 5 mirror actors // spawn 5 mirror actors
auto c0 = self->spawn<linked>(mirror_behavior); auto c0 = self->spawn<linked>(mirror_behavior);
...@@ -450,7 +450,7 @@ void test_or_else() { ...@@ -450,7 +450,7 @@ void test_or_else() {
void test_continuation() { void test_continuation() {
auto mirror = spawn<simple_mirror>(); auto mirror = spawn<simple_mirror>();
spawn([=](untyped_actor* self) { spawn([=](event_based_actor* self) {
self->sync_send(mirror, 42).then( self->sync_send(mirror, 42).then(
on(42) >> [] { on(42) >> [] {
return "fourty-two"; return "fourty-two";
...@@ -473,7 +473,7 @@ void test_continuation() { ...@@ -473,7 +473,7 @@ void test_continuation() {
void test_simple_reply_response() { void test_simple_reply_response() {
scoped_actor self; scoped_actor self;
auto s = spawn([](untyped_actor* self) -> behavior { auto s = spawn([](event_based_actor* self) -> behavior {
return ( return (
others() >> [=]() -> any_tuple { others() >> [=]() -> any_tuple {
CPPA_CHECK(self->last_dequeued() == make_any_tuple(atom("hello"))); CPPA_CHECK(self->last_dequeued() == make_any_tuple(atom("hello")));
...@@ -655,7 +655,7 @@ void test_spawn() { ...@@ -655,7 +655,7 @@ void test_spawn() {
self->await_all_other_actors_done(); self->await_all_other_actors_done();
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
auto sync_testee1 = spawn<blocking_api>([](blocking_untyped_actor* self) { auto sync_testee1 = spawn<blocking_api>([](blocking_actor* self) {
self->receive ( self->receive (
on(atom("get")) >> [] { on(atom("get")) >> [] {
return make_cow_tuple(42, 2); return make_cow_tuple(42, 2);
...@@ -696,7 +696,7 @@ void test_spawn() { ...@@ -696,7 +696,7 @@ void test_spawn() {
CPPA_PRINT("test sync send"); CPPA_PRINT("test sync send");
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
auto sync_testee = spawn<blocking_api>([](blocking_untyped_actor* self) { auto sync_testee = spawn<blocking_api>([](blocking_actor* self) {
self->receive ( self->receive (
on("hi", arg_match) >> [&](actor from) { on("hi", arg_match) >> [&](actor from) {
self->sync_send(from, "whassup?", self).await( self->sync_send(from, "whassup?", self).await(
...@@ -745,7 +745,7 @@ void test_spawn() { ...@@ -745,7 +745,7 @@ void test_spawn() {
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
auto inflater = [](untyped_actor* self, const string& name, actor buddy) { auto inflater = [](event_based_actor* self, const string& name, actor buddy) {
CPPA_LOGF_TRACE(CPPA_ARG(self) << ", " << CPPA_ARG(name) CPPA_LOGF_TRACE(CPPA_ARG(self) << ", " << CPPA_ARG(name)
<< ", " << CPPA_TARG(buddy, to_string)); << ", " << CPPA_TARG(buddy, to_string));
self->become( self->become(
...@@ -776,7 +776,7 @@ void test_spawn() { ...@@ -776,7 +776,7 @@ void test_spawn() {
// - the lambda is always executed in the current actor's thread // - the lambda is always executed in the current actor's thread
// but using spawn_next in a message handler could // but using spawn_next in a message handler could
// still cause undefined behavior! // still cause undefined behavior!
auto kr34t0r = [&spawn_next](untyped_actor* self, const string& name, actor pal) { auto kr34t0r = [&spawn_next](event_based_actor* self, const string& name, actor pal) {
if (name == "Joe" && !pal) { if (name == "Joe" && !pal) {
pal = spawn_next("Bob", self); pal = spawn_next("Bob", self);
} }
...@@ -827,7 +827,7 @@ void test_spawn() { ...@@ -827,7 +827,7 @@ void test_spawn() {
// create some actors linked to one single actor // create some actors linked to one single actor
// and kill them all through killing the link // and kill them all through killing the link
auto legion = spawn([](untyped_actor* self) { auto legion = spawn([](event_based_actor* self) {
CPPA_LOGF_INFO("spawn 1, 000 actors"); CPPA_LOGF_INFO("spawn 1, 000 actors");
for (int i = 0; i < 1000; ++i) { for (int i = 0; i < 1000; ++i) {
self->spawn<event_testee, linked>(); self->spawn<event_testee, linked>();
......
...@@ -19,7 +19,7 @@ struct float_or_int : sb_actor<float_or_int> { ...@@ -19,7 +19,7 @@ struct float_or_int : sb_actor<float_or_int> {
); );
}; };
struct popular_actor : untyped_actor { // popular actors have a buddy struct popular_actor : event_based_actor { // popular actors have a buddy
actor m_buddy; actor m_buddy;
popular_actor(const actor& buddy) : m_buddy(buddy) { } popular_actor(const actor& buddy) : m_buddy(buddy) { }
inline const actor& buddy() const { return m_buddy; } inline const actor& buddy() const { return m_buddy; }
...@@ -137,7 +137,7 @@ struct D : popular_actor { ...@@ -137,7 +137,7 @@ struct D : popular_actor {
* X * * X *
\******************************************************************************/ \******************************************************************************/
struct server : untyped_actor { struct server : event_based_actor {
behavior make_behavior() override { behavior make_behavior() override {
auto die = [=] { quit(exit_reason::user_shutdown); }; auto die = [=] { quit(exit_reason::user_shutdown); };
...@@ -165,7 +165,7 @@ void test_sync_send() { ...@@ -165,7 +165,7 @@ void test_sync_send() {
self->on_sync_failure([&] { self->on_sync_failure([&] {
CPPA_FAILURE("received: " << to_string(self->last_dequeued())); CPPA_FAILURE("received: " << to_string(self->last_dequeued()));
}); });
self->spawn<monitored + blocking_api>([](blocking_untyped_actor* self) { self->spawn<monitored + blocking_api>([](blocking_actor* self) {
CPPA_LOGC_TRACE("NONE", "main$sync_failure_test", "id = " << self->id()); CPPA_LOGC_TRACE("NONE", "main$sync_failure_test", "id = " << self->id());
int invocations = 0; int invocations = 0;
auto foi = self->spawn<float_or_int, linked>(); auto foi = self->spawn<float_or_int, linked>();
...@@ -280,9 +280,9 @@ void test_sync_send() { ...@@ -280,9 +280,9 @@ void test_sync_send() {
CPPA_CHECKPOINT(); CPPA_CHECKPOINT();
// test use case 3 // test use case 3
self->spawn<monitored + blocking_api>([](blocking_untyped_actor* self) { // client self->spawn<monitored + blocking_api>([](blocking_actor* self) { // client
auto s = self->spawn<server, linked>(); // server auto s = self->spawn<server, linked>(); // server
auto w = self->spawn<linked>([](untyped_actor* self) { // worker auto w = self->spawn<linked>([](event_based_actor* self) { // worker
self->become(on(atom("request")) >> []{ return atom("response"); }); self->become(on(atom("request")) >> []{ return atom("response"); });
}); });
// first 'idle', then 'request' // first 'idle', then 'request'
......
...@@ -87,7 +87,7 @@ optional<int> str2int(const std::string& str) { ...@@ -87,7 +87,7 @@ optional<int> str2int(const std::string& str) {
CPPA_FAILURE(#FunName " erroneously invoked"); \ CPPA_FAILURE(#FunName " erroneously invoked"); \
} else { CPPA_CHECKPOINT(); } static_cast<void>(42) } else { CPPA_CHECKPOINT(); } static_cast<void>(42)
struct dummy_receiver : untyped_actor { struct dummy_receiver : event_based_actor {
behavior make_behavior() override { behavior make_behavior() override {
return ( return (
on_arg_match >> [=](expensive_copy_struct& ecs) -> expensive_copy_struct { on_arg_match >> [=](expensive_copy_struct& ecs) -> expensive_copy_struct {
......
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