Commit 4368dde2 authored by Dominik Charousset's avatar Dominik Charousset

changed actor_proxy_cache to provide get_or_put member funciton as well as get

parent 608676f3
......@@ -49,7 +49,13 @@ class actor_proxy_cache {
public:
actor_proxy_ptr get(actor_id aid, std::uint32_t process_id,
// returns existing instance if available or crates a new one
actor_proxy_ptr get_or_put(actor_id aid,
std::uint32_t process_id,
const process_information::node_id_type& node_id);
actor_proxy_ptr get(actor_id aid,
std::uint32_t process_id,
const process_information::node_id_type& node_id);
// @returns true if pptr was successfully removed, false otherwise
......@@ -89,7 +95,7 @@ class actor_proxy_cache {
util::shared_spinlock m_lock;
std::map<key_tuple, actor_proxy_ptr, key_tuple_less> m_entries;
actor_proxy_ptr get_impl(const key_tuple& key);
actor_proxy_ptr get_impl(const key_tuple& key, bool do_put);
};
......
......@@ -37,6 +37,7 @@
#include "cppa/util/shared_lock_guard.hpp"
#include "cppa/util/upgrade_lock_guard.hpp"
#include "cppa/detail/middleman.hpp"
#include "cppa/detail/network_manager.hpp"
#include "cppa/detail/actor_proxy_cache.hpp"
#include "cppa/detail/singleton_manager.hpp"
......@@ -44,34 +45,27 @@
// thread_specific_ptr
//#include <boost/thread/tss.hpp>
namespace {
//boost::thread_specific_ptr<cppa::detail::actor_proxy_cache> s_proxy_cache;
cppa::detail::actor_proxy_cache s_proxy_cache;
namespace cppa { namespace detail {
} // namespace <anonmyous>
namespace { actor_proxy_cache s_proxy_cache; }
namespace cppa { namespace detail {
actor_proxy_cache& get_actor_proxy_cache() { return s_proxy_cache; }
actor_proxy_cache& get_actor_proxy_cache() {
/*
if (s_proxy_cache.get() == nullptr) {
s_proxy_cache.reset(new actor_proxy_cache);
}
return *s_proxy_cache;
*/
return s_proxy_cache;
actor_proxy_ptr actor_proxy_cache::get_or_put(actor_id aid,
std::uint32_t process_id,
const process_information::node_id_type& node_id) {
key_tuple k{node_id, process_id, aid};
return get_impl(k, true);
}
actor_proxy_ptr actor_proxy_cache::get(actor_id aid,
std::uint32_t process_id,
const process_information::node_id_type& node_id) {
key_tuple k{node_id, process_id, aid};
return get_impl(k);
return get_impl(k, false);
}
actor_proxy_ptr actor_proxy_cache::get_impl(const key_tuple& key) {
actor_proxy_ptr actor_proxy_cache::get_impl(const key_tuple& key, bool do_put) {
{ // lifetime scope of shared guard
util::shared_lock_guard<util::shared_spinlock> guard{m_lock};
auto i = m_entries.find(key);
......@@ -79,7 +73,10 @@ actor_proxy_ptr actor_proxy_cache::get_impl(const key_tuple& key) {
return i->second;
}
}
actor_proxy_ptr result{new actor_proxy(std::get<2>(key), new process_information(std::get<1>(key), std::get<0>(key)))};
if (!do_put) { return nullptr; }
process_information_ptr pip(new process_information(std::get<1>(key),
std::get<0>(key)));
actor_proxy_ptr result(new actor_proxy(std::get<2>(key), pip));
{ // lifetime scope of exclusive guard
std::lock_guard<util::shared_spinlock> guard{m_lock};
auto i = m_entries.find(key);
......@@ -91,7 +88,12 @@ actor_proxy_ptr actor_proxy_cache::get_impl(const key_tuple& key) {
result->attach_functor([result](std::uint32_t) {
get_actor_proxy_cache().erase(result);
});
result->enqueue(nullptr, make_any_tuple(atom("MONITOR")));
middleman_enqueue(pip,
nullptr,
nullptr,
make_any_tuple(atom("MONITOR"),
pip,
std::get<2>(key)));
return result;
}
......
......@@ -84,7 +84,7 @@ actor_ptr remote_actor(util::io_stream_ptr_pair peer) {
process_information_ptr pinfptr(new process_information(peer_pid, peer_node_id));
//auto key = std::make_tuple(remote_actor_id, pinfptr->process_id(), pinfptr->node_id());
detail::middleman_add_peer(peer, pinfptr);
return detail::get_actor_proxy_cache().get(remote_actor_id,
return detail::get_actor_proxy_cache().get_or_put(remote_actor_id,
pinfptr->process_id(),
pinfptr->node_id());
}
......
......@@ -232,7 +232,8 @@ class actor_ptr_tinfo : public util::abstract_uniform_type_info<actor_ptr> {
*/
process_information::node_id_type nid;
node_id_from_string(nstr, nid);
ptrref = detail::get_actor_proxy_cache().get(get<std::uint32_t>(ptup[0]),
auto& cache = detail::get_actor_proxy_cache();
ptrref = cache.get_or_put(get<std::uint32_t>(ptup[0]),
get<std::uint32_t>(ptup[1]),
nid);
}
......
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