Commit e520075d authored by Dominik Charousset's avatar Dominik Charousset

Use self ptr to retrieve context in promise

parent 625ff651
...@@ -256,7 +256,7 @@ public: ...@@ -256,7 +256,7 @@ public:
auto& mid = ptr->mid; auto& mid = ptr->mid;
if (mid.is_answered()) if (mid.is_answered())
return {}; return {};
return {this->context(), this->ctrl(), *ptr}; return {this->ctrl(), *ptr};
} }
/// Creates a `response_promise` to respond to a request later on. /// Creates a `response_promise` to respond to a request later on.
......
...@@ -41,8 +41,9 @@ public: ...@@ -41,8 +41,9 @@ public:
/// Constructs an invalid response promise. /// Constructs an invalid response promise.
response_promise(); response_promise();
response_promise(execution_unit* ctx, strong_actor_ptr self, response_promise(none_t);
mailbox_element& src);
response_promise(strong_actor_ptr self, mailbox_element& src);
response_promise(response_promise&&) = default; response_promise(response_promise&&) = default;
response_promise(const response_promise&) = default; response_promise(const response_promise&) = default;
...@@ -81,7 +82,7 @@ public: ...@@ -81,7 +82,7 @@ public:
dest->enqueue(make_mailbox_element(std::move(source_), mid, dest->enqueue(make_mailbox_element(std::move(source_), mid,
std::move(stages_), std::move(stages_),
std::forward<Ts>(xs)...), std::forward<Ts>(xs)...),
ctx_); context());
} }
return {}; return {};
} }
...@@ -114,9 +115,10 @@ public: ...@@ -114,9 +115,10 @@ public:
} }
private: private:
execution_unit* context();
response_promise deliver_impl(message msg); response_promise deliver_impl(message msg);
execution_unit* ctx_;
strong_actor_ptr self_; strong_actor_ptr self_;
strong_actor_ptr source_; strong_actor_ptr source_;
forwarding_stack stages_; forwarding_stack stages_;
......
...@@ -35,9 +35,8 @@ public: ...@@ -35,9 +35,8 @@ public:
/// Constructs an invalid response promise. /// Constructs an invalid response promise.
typed_response_promise() = default; typed_response_promise() = default;
inline typed_response_promise(execution_unit* ctx, strong_actor_ptr self, inline typed_response_promise(strong_actor_ptr self, mailbox_element& src)
mailbox_element& src) : promise_(std::move(self), src) {
: promise_(ctx, std::move(self), src) {
// nop // nop
} }
......
...@@ -32,10 +32,8 @@ response_promise::response_promise() ...@@ -32,10 +32,8 @@ response_promise::response_promise()
// nop // nop
} }
response_promise::response_promise(execution_unit* ctx, strong_actor_ptr self, response_promise::response_promise(strong_actor_ptr self, mailbox_element& src)
mailbox_element& src) : self_(std::move(self)),
: ctx_(ctx),
self_(std::move(self)),
id_(src.mid) { id_(src.mid) {
// form an invalid request promise when initialized from a // form an invalid request promise when initialized from a
// response ID, since CAF always drops messages in this case // response ID, since CAF always drops messages in this case
...@@ -54,18 +52,26 @@ bool response_promise::async() const { ...@@ -54,18 +52,26 @@ bool response_promise::async() const {
return id_.is_async(); return id_.is_async();
} }
execution_unit* response_promise::context() {
return self_ == nullptr
? nullptr
: static_cast<local_actor*>(actor_cast<abstract_actor*>(self_))
->context();
}
response_promise response_promise::deliver_impl(message msg) { response_promise response_promise::deliver_impl(message msg) {
if (!stages_.empty()) { if (!stages_.empty()) {
auto next = std::move(stages_.back()); auto next = std::move(stages_.back());
stages_.pop_back(); stages_.pop_back();
next->enqueue(make_mailbox_element(std::move(source_), id_, next->enqueue(make_mailbox_element(std::move(source_), id_,
std::move(stages_), std::move(msg)), std::move(stages_), std::move(msg)),
ctx_); context());
return *this; return *this;
} }
if (source_) { if (source_) {
source_->enqueue(std::move(self_), id_.response_id(), source_->enqueue(std::move(self_), id_.response_id(),
std::move(msg), ctx_); std::move(msg), context());
source_.reset(); source_.reset();
return *this; return *this;
} }
......
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