Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/acto/acto.h
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,9 @@ namespace this_thread {
/**
* Processes all messages for objects
* binded to the current thread (with aoBindToThread option).
* @return true if at least one message has been processed.
*/
void process_messages();
bool process_messages();

template <typename D>
inline void sleep_for(const D duration) {
Expand Down
4 changes: 2 additions & 2 deletions src/acto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ void join(const actor_ref& obj) {
obj.join();
}

void this_thread::process_messages() {
core::runtime_t::instance()->process_binded_actors();
bool this_thread::process_messages() {
return core::runtime_t::instance()->process_binded_actors();
}

void shutdown() {
Expand Down
11 changes: 8 additions & 3 deletions src/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ struct binding_context_t {
* Processes all available messages for the actors.
*
* @param need_delete delete actors after process all messages.
* @return true if at least one message has been processed.
*/
void process_actors(const bool need_delete) {
bool process_actors(const bool need_delete) {
auto runtime = runtime_t::instance();
bool something_was_processed = false;
// TODO: - switch between active actors to balance message processing.
// - detect message loop.
for (auto ai = actors.cbegin(); ai != actors.cend(); ++ai) {
while (auto msg = (*ai)->select_message()) {
runtime->handle_message(*ai, std::move(msg));
something_was_processed = true;
}
if (need_delete) {
runtime->deconstruct_object(*ai);
Expand All @@ -52,6 +55,8 @@ struct binding_context_t {

actors.clear();
}

return something_was_processed;
}
};

Expand Down Expand Up @@ -211,8 +216,8 @@ void runtime_t::join(object_t* const obj) {
node.on_deleted.wait();
}

void runtime_t::process_binded_actors() {
thread_context.process_actors(false);
bool runtime_t::process_binded_actors() {
return thread_context.process_actors(false);
}

unsigned long runtime_t::release(object_t* const obj) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class runtime_t : public worker_t::callbacks {
void join(object_t* const obj);

/// -
void process_binded_actors();
bool process_binded_actors();

/// -
unsigned long release(object_t* const obj);
Expand Down