Commit d967328b authored by neverlord's avatar neverlord

maintenance

parent 6a73baa0
...@@ -136,6 +136,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor ...@@ -136,6 +136,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor
private: private:
bool handle_message(queue_node& iter); bool handle_message(queue_node& iter);
bool invoke_from_cache();
}; };
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <atomic> #include <atomic>
#include <memory> #include <memory>
#include "cppa/config.hpp"
#include "cppa/detail/thread.hpp" #include "cppa/detail/thread.hpp"
namespace cppa { namespace intrusive { namespace cppa { namespace intrusive {
...@@ -245,8 +246,9 @@ class single_reader_queue ...@@ -245,8 +246,9 @@ class single_reader_queue
// next iteration // next iteration
e = next; e = next;
} }
CPPA_REQUIRE(tmp.empty() == false);
if (iter) *iter = tmp.begin(); if (iter) *iter = tmp.begin();
m_cache.splice(m_cache.end(), tmp); m_cache.splice(m_cache.end(), std::move(tmp));
return true; return true;
} }
// next iteration // next iteration
...@@ -259,11 +261,11 @@ class single_reader_queue ...@@ -259,11 +261,11 @@ class single_reader_queue
{ {
if (!m_cache.empty() || fetch_new_data()) if (!m_cache.empty() || fetch_new_data())
{ {
auto result = std::move(m_cache.front()); unique_pointer result = std::move(m_cache.front());
m_cache.pop_front(); m_cache.pop_front();
return std::move(result); return std::move(result);
} }
return nullptr; return {};
} }
}; };
......
...@@ -86,25 +86,36 @@ bool abstract_event_based_actor::handle_message(queue_node& node) ...@@ -86,25 +86,36 @@ bool abstract_event_based_actor::handle_message(queue_node& node)
} }
} }
bool abstract_event_based_actor::invoke_from_cache()
{
for (auto i = m_mailbox_pos; i != m_mailbox.cache().end(); ++i)
{
if (handle_message(*(*i)))
{
m_mailbox.cache().erase(i);
return true;
}
}
return false;
}
void abstract_event_based_actor::resume(util::fiber*, resume_callback* callback) void abstract_event_based_actor::resume(util::fiber*, resume_callback* callback)
{ {
self.set(this); self.set(this);
auto done_cb = [this, callback]() auto done_cb = [=]()
{ {
m_state.store(abstract_scheduled_actor::done); m_state.store(abstract_scheduled_actor::done);
while (!m_loop_stack.empty()) m_loop_stack.pop_back(); while (!m_loop_stack.empty()) m_loop_stack.pop_back();
on_exit(); on_exit();
callback->exec_done(); callback->exec_done();
}; };
if (m_loop_stack.empty())
{
cleanup(exit_reason::normal);
done_cb();
return;
}
auto& mbox_cache = m_mailbox.cache(); auto& mbox_cache = m_mailbox.cache();
auto mbox_end = mbox_cache.end(); auto mbox_end = mbox_cache.end();
auto rm_fun = [this](queue_node_ptr& ptr) { return handle_message(*ptr); }; /*auto rm_fun = [=](queue_node_ptr& ptr) -> bool
{
CPPA_REQUIRE(ptr.get() != nullptr);
return handle_message(*ptr);
};*/
try try
{ {
for (;;) for (;;)
...@@ -143,12 +154,8 @@ void abstract_event_based_actor::resume(util::fiber*, resume_callback* callback) ...@@ -143,12 +154,8 @@ void abstract_event_based_actor::resume(util::fiber*, resume_callback* callback)
} }
m_mailbox_pos = m_mailbox.try_fetch_more(); m_mailbox_pos = m_mailbox.try_fetch_more();
} }
m_mailbox_pos = std::find_if(m_mailbox_pos, mbox_end, rm_fun); m_mailbox_pos = (invoke_from_cache()) ? mbox_cache.begin()
if (m_mailbox_pos != mbox_end) : mbox_cache.end();
{
mbox_cache.erase(m_mailbox_pos);
m_mailbox_pos = mbox_cache.begin();
}
} }
} }
catch (actor_exited& what) catch (actor_exited& what)
......
...@@ -144,6 +144,7 @@ void abstract_scheduled_actor::request_timeout(util::duration const& d) ...@@ -144,6 +144,7 @@ void abstract_scheduled_actor::request_timeout(util::duration const& d)
auto abstract_scheduled_actor::filter_msg(any_tuple const& msg) -> filter_result auto abstract_scheduled_actor::filter_msg(any_tuple const& msg) -> filter_result
{ {
CPPA_REQUIRE(msg.cvals().get() != nullptr);
if ( msg.size() == 2 if ( msg.size() == 2
&& msg.type_at(0) == t_atom_ui32_types[0] && msg.type_at(0) == t_atom_ui32_types[0]
&& msg.type_at(1) == t_atom_ui32_types[1]) && msg.type_at(1) == t_atom_ui32_types[1])
......
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