Commit ec8ba04f authored by Dominik Charousset's avatar Dominik Charousset

Terminate actor pool when out of workers

parent 770a1e8a
......@@ -119,12 +119,15 @@ class actor_pool : public abstract_actor {
void enqueue(mailbox_element_ptr what, execution_unit* host) override;
private:
actor_pool();
private:
bool filter(upgrade_lock<detail::shared_spinlock>&, const actor_addr& sender,
message_id mid, const message& content, execution_unit* host);
// call without m_mtx held
void quit();
detail::shared_spinlock m_mtx;
std::vector<actor> m_workers;
policy m_policy;
......
......@@ -56,6 +56,11 @@ static constexpr uint32_t unhandled_sync_timeout = 0x00005;
*/
static constexpr uint32_t unknown = 0x00006;
/**
* Indicates that an actor pool unexpectedly ran out of workers.
*/
static constexpr uint32_t out_of_workers = 0x00007;
/**
* Indicates that the actor was forced to shutdown by a user-generated event.
*/
......
......@@ -77,7 +77,7 @@ actor_pool::~actor_pool() {
actor actor_pool::make(policy pol) {
intrusive_ptr<actor_pool> ptr;
ptr.reset(new actor_pool);
ptr = make_counted<actor_pool>();
ptr->m_policy = std::move(pol);
return actor_cast<actor>(ptr);
}
......@@ -139,10 +139,7 @@ bool actor_pool::filter(upgrade_lock<detail::shared_spinlock>& guard,
for (auto& w : workers) {
anon_send(w, msg);
}
// we can safely run our cleanup code here
// because abstract_actor has its own lock
cleanup(m_planned_reason);
is_registered(false);
quit();
return true;
}
if (msg.match_elements<down_msg>()) {
......@@ -154,6 +151,11 @@ bool actor_pool::filter(upgrade_lock<detail::shared_spinlock>& guard,
if (i != last) {
m_workers.erase(i);
}
if (m_workers.empty()) {
m_planned_reason = exit_reason::out_of_workers;
unique_guard.unlock();
quit();
}
return true;
}
if (msg.match_elements<sys_atom, put_atom, actor>()) {
......@@ -198,4 +200,11 @@ bool actor_pool::filter(upgrade_lock<detail::shared_spinlock>& guard,
return false;
}
void actor_pool::quit() {
// we can safely run our cleanup code here without holding
// m_mtx because abstract_actor has its own lock
cleanup(m_planned_reason);
is_registered(false);
}
} // namespace caf
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