Skip to content

Commit

Permalink
just set deleting if terminating
Browse files Browse the repository at this point in the history
  • Loading branch information
artpaul committed Mar 4, 2023
1 parent 229ec8c commit e4a2709
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
5 changes: 3 additions & 2 deletions lib/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct binding_context_t {
}

/**
* Processes all available messages for the acctors.
* Processes all available messages for the actors.
*
* @param need_delete delete actors after process all messages.
*/
Expand Down Expand Up @@ -182,7 +182,8 @@ void runtime_t::handle_message(object_t* obj, std::unique_ptr<msg_t> msg) {
}

if (obj->impl->terminating_) {
deconstruct_object(obj);
std::lock_guard<std::mutex> g(obj->cs);
obj->deleting = true;
}
}

Expand Down
18 changes: 7 additions & 11 deletions lib/worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,36 +73,32 @@ bool worker_t::process() {
std::lock_guard<std::mutex> g(obj->cs);

if (obj->deleting) {
need_delete = true;
// Drain the object's mailbox if it in the deleting state.
if (obj->has_messages()) {
time_slice_ = std::chrono::steady_clock::duration::max();
continue;
}

need_delete = true;
obj->scheduled = false;
} else if (obj->exclusive) {
// Just wait for new messages if the object
// exclusively bound to the thread.
return true;
} else if (obj->has_messages()) {
// Return object to the shared queue.
slots_->push_object(obj);
} else {
if (obj->has_messages()) {
// Return object to the shared queue.
slots_->push_object(obj);
} else {
obj->scheduled = false;
}
obj->scheduled = false;
}

break;
}

if (need_delete) {
if (runtime_t::instance()->release(obj)) {
if (runtime_t::instance()->release(obj)) {
if (need_delete) {
slots_->push_delete(obj);
}
} else {
runtime_t::instance()->release(obj);
}

// Retrieve next object from the shared queue.
Expand Down

0 comments on commit e4a2709

Please sign in to comment.