Commit a8bc03af authored by Dominik Charousset's avatar Dominik Charousset

response_promise::deliver corrected for scheduling

the member function response_promise::deliver no longer breaks
out of the execution unit, i.e., returning a value from a message
handler does no longer have a performance penalty
parent d3b7693d
......@@ -65,6 +65,7 @@ typedef std::uint32_t actor_id;
class actor;
class abstract_actor;
class response_promise;
typedef intrusive_ptr<abstract_actor> abstract_actor_ptr;
......@@ -73,6 +74,8 @@ typedef intrusive_ptr<abstract_actor> abstract_actor_ptr;
*/
class abstract_actor : public abstract_channel {
friend class response_promise;
public:
/**
......
......@@ -33,6 +33,7 @@
#include "cppa/actor.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/actor_addr.hpp"
#include "cppa/message_id.hpp"
namespace cppa {
......@@ -60,7 +61,10 @@ class response_promise {
* @brief Queries whether this promise is still valid, i.e., no response
* was yet delivered to the client.
*/
explicit operator bool() const;
inline explicit operator bool() const {
// handle is valid if it has a receiver
return static_cast<bool>(m_to);
}
/**
* @brief Sends @p response_message and invalidates this handle afterwards.
......
......@@ -46,15 +46,11 @@ response_promise::response_promise(const actor_addr& from,
CPPA_REQUIRE(id.is_response() || !id.valid());
}
response_promise::operator bool() const {
return m_to != nullptr;
}
void response_promise::deliver(any_tuple msg) {
if (m_to) {
auto ptr = detail::raw_access::get(m_to);
// TODO: breaks out of the execution unit
ptr->enqueue({m_from, ptr, m_id}, move(msg), nullptr);
auto to = detail::raw_access::get(m_to);
auto from = detail::raw_access::get(m_from);
to->enqueue({m_from, to, m_id}, move(msg), from->m_host);
m_to = invalid_actor_addr;
}
}
......
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