Skip to content

Commit

Permalink
there is no need to hold reference to the target actor from msg_t
Browse files Browse the repository at this point in the history
  • Loading branch information
artpaul committed Jun 17, 2022
1 parent 6e15b2f commit 8420436
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 18 deletions.
3 changes: 0 additions & 3 deletions lib/acto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,6 @@ msg_t::~msg_t() {
if (sender) {
runtime_t::instance()->release(sender);
}
if (target) {
runtime_t::instance()->release(target);
}
}

object_t* make_instance(actor_ref context,
Expand Down
2 changes: 0 additions & 2 deletions lib/acto.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ struct msg_t : generics::intrusive_t<msg_t> {
/// Sender of the message.
/// Can be empty.
object_t* sender{nullptr};
/// Receiver of the message.
object_t* target{nullptr};

public:
constexpr msg_t(const std::type_index& idx) noexcept
Expand Down
13 changes: 3 additions & 10 deletions lib/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct binding_context_t {
// - detect message loop.
for (auto ai = actors.cbegin(); ai != actors.cend(); ++ai) {
while (auto msg = (*ai)->select_message()) {
runtime->handle_message(std::move(msg));
runtime->handle_message(*ai, std::move(msg));
}
if (need_delete) {
runtime->deconstruct_object(*ai);
Expand Down Expand Up @@ -172,12 +172,8 @@ void runtime_t::deconstruct_object(object_t* const obj) {
}
}

void runtime_t::handle_message(std::unique_ptr<msg_t> msg) {
assert(msg);
assert(msg->target);
assert(msg->target->impl);

object_t* const obj = msg->target;
void runtime_t::handle_message(object_t* obj, std::unique_ptr<msg_t> msg) {
assert(obj->impl);

{
active_actor_guard guard(obj);
Expand Down Expand Up @@ -254,9 +250,6 @@ bool runtime_t::send_on_behalf(object_t* const target,
msg->sender = sender;
acquire(sender);
}
// Acquire reference to the target actor.
msg->target = target;
acquire(target);
}
// Enqueue the message.
target->enqueue(std::move(msg));
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class runtime_t : public worker_t::callbacks {
void deconstruct_object(object_t* const object);

///
void handle_message(std::unique_ptr<msg_t> msg) override;
void handle_message(object_t* obj, std::unique_ptr<msg_t> msg) override;

/// Ждать уничтожения тела объекта
void join(object_t* const obj);
Expand Down
2 changes: 1 addition & 1 deletion lib/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ bool worker_t::process() {
while (true) {
// Handle a message.
if (auto msg = obj->select_message()) {
slots_->handle_message(std::move(msg));
slots_->handle_message(obj, std::move(msg));
// Continue processing messages if the object is bound to the thread or
// the time slice has not been elapsed yet.
if (obj->exclusive ||
Expand Down
2 changes: 1 addition & 1 deletion lib/worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class worker_t : public generics::intrusive_t<worker_t> {
virtual ~callbacks() = default;

/** Process the message. */
virtual void handle_message(std::unique_ptr<msg_t>) = 0;
virtual void handle_message(object_t* obj, std::unique_ptr<msg_t>) = 0;

/** Schedule object to delete. */
virtual void push_delete(object_t* const) = 0;
Expand Down

0 comments on commit 8420436

Please sign in to comment.