Commit b36cae49 authored by neverlord's avatar neverlord

fixed threading issue

parent ce955a9c
......@@ -44,9 +44,10 @@
#include "cppa/local_actor.hpp"
#include "cppa/attachable.hpp"
#include "cppa/exit_reason.hpp"
#include "cppa/util/shared_spinlock.hpp"
#include "cppa/detail/thread.hpp"
#include "cppa/detail/recursive_queue_node.hpp"
#include "cppa/intrusive/single_reader_queue.hpp"
namespace cppa {
......@@ -167,36 +168,49 @@ class abstract_actor : public Base
mailbox_type m_mailbox;
util::fixed_vector<mailbox_element*, 10> m_nodes;
util::shared_spinlock m_nodes_lock;
typedef detail::lock_guard<util::shared_spinlock> lock_type;
inline mailbox_element* fetch_node(actor* sender, any_tuple msg)
{
if (m_nodes.empty())
mailbox_element* result = nullptr;
// lifetime scope of guard
{
return new mailbox_element(sender, std::move(msg));
}
else
lock_type guard{m_nodes_lock};
if (m_nodes.not_empty())
{
mailbox_element* result = m_nodes.back();
result = m_nodes.back();
m_nodes.pop_back();
}
}
if (result)
{
result->next = nullptr;
result->marked = false;
result->sender = sender;
result->msg = std::move(msg);
return result;
}
else
{
result = new mailbox_element(sender, std::move(msg));
}
return result;
}
inline void release_node(mailbox_element* node)
{
if (m_nodes.full())
// lifetime scope of guard
{
delete node;
}
else
lock_type guard{m_nodes_lock};
if (m_nodes.full() == false)
{
m_nodes.push_back(node);
return;
}
}
delete node;
}
template<typename... Args>
abstract_actor(Args&&... args) : Base(std::forward<Args>(args)...)
......
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