Commit b8168356 authored by neverlord's avatar neverlord

more refactoring

parent 6f113f7c
CXX = /opt/local/bin/g++-mp-4.5 CXX = /opt/local/bin/g++-mp-4.5
#CXXFLAGS = -std=c++0x -pedantic -Wall -Wextra -O2 -I/opt/local/include/ CXXFLAGS = -std=c++0x -pedantic -Wall -Wextra -O2 -I/opt/local/include/
CXXFLAGS = -std=c++0x -pedantic -Wall -Wextra -g -O0 -I/opt/local/include/ #CXXFLAGS = -std=c++0x -pedantic -Wall -Wextra -g -O0 -I/opt/local/include/
LIBS = -L/opt/local/lib -lboost_thread-mt LIBS = -L/opt/local/lib -lboost_thread-mt
...@@ -10,7 +10,7 @@ class actor : public channel ...@@ -10,7 +10,7 @@ class actor : public channel
public: public:
virtual void link(const intrusive_ptr<actor>& other) = 0; virtual void link_to(const intrusive_ptr<actor>& other) = 0;
}; };
......
...@@ -53,7 +53,6 @@ bool match(const untyped_tuple& what, const ValuesTuple& vals, ...@@ -53,7 +53,6 @@ bool match(const untyped_tuple& what, const ValuesTuple& vals,
std::vector<std::size_t> tmp(mappings); std::vector<std::size_t> tmp(mappings);
view_type view(what.vals(), std::move(tmp)); view_type view(what.vals(), std::move(tmp));
return compare_first_elements(view, vals); return compare_first_elements(view, vals);
// return view == vals;
} }
return false; return false;
} }
......
...@@ -8,11 +8,12 @@ namespace cppa { class invoke_rules; } ...@@ -8,11 +8,12 @@ namespace cppa { class invoke_rules; }
namespace cppa { namespace cppa {
class message_queue : public channel class message_queue
{ {
public: public:
virtual void enqueue(const message&) = 0;
virtual const message& dequeue() = 0; virtual const message& dequeue() = 0;
virtual void dequeue(invoke_rules&) = 0; virtual void dequeue(invoke_rules&) = 0;
virtual bool try_dequeue(message&) = 0; virtual bool try_dequeue(message&) = 0;
......
...@@ -106,7 +106,7 @@ struct actor_impl : context ...@@ -106,7 +106,7 @@ struct actor_impl : context
m_mbox.enqueue(msg); m_mbox.enqueue(msg);
} }
virtual void link(const intrusive_ptr<actor>&) { } virtual void link_to(const intrusive_ptr<actor>&) { }
virtual void unlink(const intrusive_ptr<actor>&) { } virtual void unlink(const intrusive_ptr<actor>&) { }
...@@ -128,6 +128,11 @@ boost::condition_variable m_ra_cv; ...@@ -128,6 +128,11 @@ boost::condition_variable m_ra_cv;
void run_actor_impl(intrusive_ptr<actor_impl> m_impl) void run_actor_impl(intrusive_ptr<actor_impl> m_impl)
{ {
{
actor_impl* self_ptr = m_impl.get();
self_ptr->ref();
m_this_context.reset(self_ptr);
}
actor_behavior* ab = m_impl->m_behavior; actor_behavior* ab = m_impl->m_behavior;
if (ab) if (ab)
{ {
......
...@@ -103,7 +103,7 @@ class local_group : public group ...@@ -103,7 +103,7 @@ class local_group : public group
//local_group* m_local_group = new local_group; //local_group* m_local_group = new local_group;
intrusive_ptr<local_group> m_local_group; intrusive_ptr<local_group> m_local_group(new local_group);
intrusive_ptr<local_group> local(const char*) intrusive_ptr<local_group> local(const char*)
{ {
...@@ -138,10 +138,22 @@ struct storage ...@@ -138,10 +138,22 @@ struct storage
}; };
void foo_actor_ptr() void consumer(actor_ptr main_actor)
{ {
receive(on<int>() >> [](int i) { int result = 0;
reply(i); for (int i = 0; i < 5; ++i)
{
receive(on<int>() >> [&](int x) {
result += x;
});
}
send(main_actor, result);
}
void producer(actor_ptr consume_actor)
{
receive(on<int>() >> [&](int i) {
send(consume_actor, i);
}); });
} }
...@@ -152,24 +164,25 @@ std::size_t test__local_group() ...@@ -152,24 +164,25 @@ std::size_t test__local_group()
std::list<intrusive_ptr<group::subscription>> m_subscriptions; std::list<intrusive_ptr<group::subscription>> m_subscriptions;
auto self_ptr = self();
auto consume_actor = spawn([=]() { consumer(self_ptr); });
auto lg = local("foobar"); auto lg = local("foobar");
for (int i = 0; i < 5; ++i) for (int i = 0; i < 5; ++i)
{ {
m_subscriptions.push_back(lg->subscribe(spawn(foo_actor_ptr))); auto fa = spawn([=]() { producer(consume_actor); });
auto sptr = lg->subscribe(fa);
m_subscriptions.push_back(sptr);
} }
send(lg, 1); send(lg, 1);
int result = 0; await_all_actors_done();
for (int i = 0; i < 5; ++i) receive(on<int>() >> [&](int x) {
{ CPPA_CHECK_EQUAL(x, 5);
receive(on<int>() >> [&result](int x) { });
result += x;
});
}
CPPA_CHECK_EQUAL(result, 5);
return CPPA_TEST_RESULT; return CPPA_TEST_RESULT;
......
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