Commit a271c786 authored by Dominik Charousset's avatar Dominik Charousset

Rename has_behavior to alive

parent ea7b8e3e
...@@ -690,14 +690,9 @@ public: ...@@ -690,14 +690,9 @@ public:
// -- behavior management ---------------------------------------------------- // -- behavior management ----------------------------------------------------
/// Returns whether `true` if the behavior stack is not empty or /// Returns whether `true` if the behavior stack is not empty.
/// if outstanding responses exist, `false` otherwise. inline bool has_behavior() const noexcept {
inline bool has_behavior() const { return !bhvr_stack_.empty();
return !bhvr_stack_.empty()
|| !awaited_responses_.empty()
|| !multiplexed_responses_.empty()
|| !stream_managers_.empty()
|| !pending_stream_managers_.empty();
} }
inline behavior& current_behavior() { inline behavior& current_behavior() {
...@@ -871,6 +866,19 @@ public: ...@@ -871,6 +866,19 @@ public:
/// this function again. /// this function again.
actor_clock::time_point advance_streams(actor_clock::time_point now); actor_clock::time_point advance_streams(actor_clock::time_point now);
// -- properties -------------------------------------------------------------
/// Returns `true` if the actor has a behavior, awaits responses, or
/// participates in streams.
/// @private
inline bool alive() const noexcept {
return !bhvr_stack_.empty()
|| !awaited_responses_.empty()
|| !multiplexed_responses_.empty()
|| !stream_managers_.empty()
|| !pending_stream_managers_.empty();
}
/// @endcond /// @endcond
protected: protected:
......
...@@ -73,7 +73,7 @@ public: ...@@ -73,7 +73,7 @@ public:
this->setf(abstract_actor::is_initialized_flag); this->setf(abstract_actor::is_initialized_flag);
auto bhvr = make_behavior(); auto bhvr = make_behavior();
CAF_LOG_DEBUG_IF(!bhvr, "make_behavior() did not return a behavior:" CAF_LOG_DEBUG_IF(!bhvr, "make_behavior() did not return a behavior:"
<< CAF_ARG(this->has_behavior())); << CAF_ARG2("alive", this->alive()));
if (bhvr) { if (bhvr) {
// make_behavior() did return a behavior instead of using become() // make_behavior() did return a behavior instead of using become()
CAF_LOG_DEBUG("make_behavior() did return a valid behavior"); CAF_LOG_DEBUG("make_behavior() did return a valid behavior");
......
...@@ -38,7 +38,7 @@ void event_based_actor::initialize() { ...@@ -38,7 +38,7 @@ void event_based_actor::initialize() {
setf(is_initialized_flag); setf(is_initialized_flag);
auto bhvr = make_behavior(); auto bhvr = make_behavior();
CAF_LOG_DEBUG_IF(!bhvr, "make_behavior() did not return a behavior:" CAF_LOG_DEBUG_IF(!bhvr, "make_behavior() did not return a behavior:"
<< CAF_ARG(has_behavior())); << CAF_ARG2("alive", alive()));
if (bhvr) { if (bhvr) {
// make_behavior() did return a behavior instead of using become() // make_behavior() did return a behavior instead of using become()
CAF_LOG_DEBUG("make_behavior() did return a valid behavior"); CAF_LOG_DEBUG("make_behavior() did return a valid behavior");
......
...@@ -680,10 +680,8 @@ bool scheduled_actor::activate(execution_unit* ctx) { ...@@ -680,10 +680,8 @@ bool scheduled_actor::activate(execution_unit* ctx) {
CAF_ASSERT(ctx != nullptr); CAF_ASSERT(ctx != nullptr);
CAF_ASSERT(!getf(is_blocking_flag)); CAF_ASSERT(!getf(is_blocking_flag));
context(ctx); context(ctx);
if (getf(is_initialized_flag) if (getf(is_initialized_flag) && (!alive() || getf(is_terminated_flag))) {
&& (!has_behavior() || getf(is_terminated_flag))) { CAF_LOG_DEBUG_IF(!alive(), "resume called on an actor without behavior");
CAF_LOG_DEBUG_IF(!has_behavior(),
"resume called on an actor without behavior");
CAF_LOG_DEBUG_IF(getf(is_terminated_flag), CAF_LOG_DEBUG_IF(getf(is_terminated_flag),
"resume called on a terminated actor"); "resume called on a terminated actor");
return false; return false;
...@@ -781,7 +779,7 @@ bool scheduled_actor::finalize() { ...@@ -781,7 +779,7 @@ bool scheduled_actor::finalize() {
return true; return true;
// An actor is considered alive as long as it has a behavior and didn't set // An actor is considered alive as long as it has a behavior and didn't set
// the terminated flag. // the terminated flag.
if (has_behavior() && !getf(is_terminated_flag)) if (alive() && !getf(is_terminated_flag))
return false; return false;
CAF_LOG_DEBUG("actor either has no behavior or has set an exit reason"); CAF_LOG_DEBUG("actor either has no behavior or has set an exit reason");
on_exit(); on_exit();
......
...@@ -96,7 +96,7 @@ public: ...@@ -96,7 +96,7 @@ public:
this->init_broker(); this->init_broker();
auto bhvr = make_behavior(); auto bhvr = make_behavior();
CAF_LOG_DEBUG_IF(!bhvr, "make_behavior() did not return a behavior:" CAF_LOG_DEBUG_IF(!bhvr, "make_behavior() did not return a behavior:"
<< CAF_ARG(this->has_behavior())); << CAF_ARG2("alive", this->alive()));
if (bhvr) { if (bhvr) {
// make_behavior() did return a behavior instead of using become() // make_behavior() did return a behavior instead of using become()
CAF_LOG_DEBUG("make_behavior() did return a valid behavior"); CAF_LOG_DEBUG("make_behavior() did return a valid behavior");
......
...@@ -37,7 +37,7 @@ void broker::initialize() { ...@@ -37,7 +37,7 @@ void broker::initialize() {
init_broker(); init_broker();
auto bhvr = make_behavior(); auto bhvr = make_behavior();
CAF_LOG_DEBUG_IF(!bhvr, "make_behavior() did not return a behavior:" CAF_LOG_DEBUG_IF(!bhvr, "make_behavior() did not return a behavior:"
<< CAF_ARG(has_behavior())); << CAF_ARG2("alive", alive()));
if (bhvr) { if (bhvr) {
// make_behavior() did return a behavior instead of using become() // make_behavior() did return a behavior instead of using become()
CAF_LOG_DEBUG("make_behavior() did return a valid behavior"); CAF_LOG_DEBUG("make_behavior() did return a valid behavior");
......
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