diff --git a/include/acto/acto.h b/include/acto/acto.h index af1a2c0..4c74bff 100644 --- a/include/acto/acto.h +++ b/include/acto/acto.h @@ -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 inline void sleep_for(const D duration) { diff --git a/src/acto.cpp b/src/acto.cpp index 17baaba..2bcd1d8 100644 --- a/src/acto.cpp +++ b/src/acto.cpp @@ -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() { diff --git a/src/runtime.cpp b/src/runtime.cpp index f1c68c1..9827c81 100644 --- a/src/runtime.cpp +++ b/src/runtime.cpp @@ -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); @@ -52,6 +55,8 @@ struct binding_context_t { actors.clear(); } + + return something_was_processed; } }; @@ -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) { diff --git a/src/runtime.h b/src/runtime.h index 21067cb..ecdd4bd 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -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);