Commit b3d28e60 authored by neverlord's avatar neverlord

coding style

parent dc5a9bb5
...@@ -44,32 +44,23 @@ using std::uint32_t; ...@@ -44,32 +44,23 @@ using std::uint32_t;
using namespace cppa; using namespace cppa;
struct testee : fsm_actor<testee> struct testee : fsm_actor<testee> {
{
actor_ptr parent; actor_ptr parent;
behavior init_state; behavior init_state;
testee(actor_ptr const& pptr) : parent(pptr) testee(actor_ptr const& pptr) : parent(pptr) {
{ init_state = (
init_state = on(atom("spread"), 0) >> [=]() {
(
on(atom("spread"), 0) >> [=]()
{
send(parent, atom("result"), (uint32_t) 1); send(parent, atom("result"), (uint32_t) 1);
become_void(); become_void();
}, },
on<atom("spread"), int>() >> [=](int x) on<atom("spread"), int>() >> [=](int x) {
{ auto msg = make_any_tuple(atom("spread"), x - 1);
any_tuple msg = make_cow_tuple(atom("spread"), x - 1);
spawn(new testee(this)) << msg; spawn(new testee(this)) << msg;
spawn(new testee(this)) << msg; spawn(new testee(this)) << msg;
become become (
( on<atom("result"), uint32_t>() >> [=](uint32_t r1) {
on<atom("result"), uint32_t>() >> [=](uint32_t r1) become (
{ on<atom("result"), uint32_t>() >> [=](uint32_t r2) {
become
(
on<atom("result"), uint32_t>() >> [=](uint32_t r2)
{
send(parent, atom("result"), r1 + r2); send(parent, atom("result"), r1 + r2);
become_void(); become_void();
} }
...@@ -81,27 +72,19 @@ struct testee : fsm_actor<testee> ...@@ -81,27 +72,19 @@ struct testee : fsm_actor<testee>
} }
}; };
void stacked_testee(actor_ptr parent) void stacked_testee(actor_ptr parent) {
{ receive (
receive on(atom("spread"), 0) >> [&]() {
(
on(atom("spread"), 0) >> [&]()
{
send(parent, atom("result"), (uint32_t) 1); send(parent, atom("result"), (uint32_t) 1);
}, },
on<atom("spread"), int>() >> [&](int x) on<atom("spread"), int>() >> [&](int x) {
{
any_tuple msg = make_cow_tuple(atom("spread"), x-1); any_tuple msg = make_cow_tuple(atom("spread"), x-1);
spawn(stacked_testee, self) << msg; spawn(stacked_testee, self) << msg;
spawn(stacked_testee, self) << msg; spawn(stacked_testee, self) << msg;
receive receive (
( on<atom("result"), uint32_t>() >> [&](uint32_t v1) {
on<atom("result"), uint32_t>() >> [&](uint32_t v1) receive (
{ on<atom("result"),uint32_t>() >> [&](uint32_t v2) {
receive
(
on<atom("result"),uint32_t>() >> [&](uint32_t v2)
{
send(parent, atom("result"), v1 + v2); send(parent, atom("result"), v1 + v2);
} }
); );
...@@ -111,48 +94,38 @@ void stacked_testee(actor_ptr parent) ...@@ -111,48 +94,38 @@ void stacked_testee(actor_ptr parent)
); );
} }
void usage() void usage() {
{
cout << "usage: actor_creation (stacked|event-based) POW" << endl cout << "usage: actor_creation (stacked|event-based) POW" << endl
<< " creates 2^POW actors" << endl << " creates 2^POW actors" << endl
<< endl; << endl;
} }
int main(int argc, char** argv) int main(int argc, char** argv) {
{ if (argc == 3) {
if (argc == 3)
{
int num = rd<int>(argv[2]); int num = rd<int>(argv[2]);
if (strcmp(argv[1], "stacked") == 0) if (strcmp(argv[1], "stacked") == 0) {
{
send(spawn(stacked_testee, self), atom("spread"), num); send(spawn(stacked_testee, self), atom("spread"), num);
} }
else if (strcmp(argv[1], "event-based") == 0) else if (strcmp(argv[1], "event-based") == 0) {
{
send(spawn(new testee(self)), atom("spread"), num); send(spawn(new testee(self)), atom("spread"), num);
} }
else else {
{
usage(); usage();
return 1; return 1;
} }
receive receive (
( on<atom("result"),uint32_t>() >> [=](uint32_t value) {
on<atom("result"),uint32_t>() >> [=](uint32_t value)
{
//cout << "value = " << value << endl //cout << "value = " << value << endl
// << "expected => 2^" << num << " = " // << "expected => 2^" << num << " = "
// << (1 << num) << endl; // << (1 << num) << endl;
if (value != (((uint32_t) 1) << num)) if (value != (((uint32_t) 1) << num)) {
{
cerr << "ERROR: received wrong result!\n"; cerr << "ERROR: received wrong result!\n";
} }
} }
); );
await_all_others_done(); await_all_others_done();
} }
else else {
{
usage(); usage();
return 1; return 1;
} }
......
This diff is collapsed.
...@@ -45,19 +45,14 @@ using std::int64_t; ...@@ -45,19 +45,14 @@ using std::int64_t;
using namespace cppa; using namespace cppa;
struct fsm_receiver : fsm_actor<fsm_receiver> struct fsm_receiver : fsm_actor<fsm_receiver> {
{
int64_t m_value; int64_t m_value;
behavior init_state; behavior init_state;
fsm_receiver(int64_t max) : m_value(0) fsm_receiver(int64_t max) : m_value(0) {
{ init_state = (
init_state = on(atom("msg")) >> [=]() {
(
on(atom("msg")) >> [=]()
{
++m_value; ++m_value;
if (m_value == max) if (m_value == max) {
{
become_void(); become_void();
} }
} }
...@@ -65,63 +60,49 @@ struct fsm_receiver : fsm_actor<fsm_receiver> ...@@ -65,63 +60,49 @@ struct fsm_receiver : fsm_actor<fsm_receiver>
} }
}; };
void receiver(int64_t max) void receiver(int64_t max) {
{
int64_t value; int64_t value;
receive_while(gref(value) < max) receive_while(gref(value) < max) (
//receive_while([&]() { return value < max; }) on(atom("msg")) >> [&]() {
(
on(atom("msg")) >> [&]()
{
++value; ++value;
} }
); );
} }
void sender(actor_ptr whom, int64_t count) void sender(actor_ptr whom, int64_t count) {
{
any_tuple msg = make_cow_tuple(atom("msg")); any_tuple msg = make_cow_tuple(atom("msg"));
for (int64_t i = 0; i < count; ++i) for (int64_t i = 0; i < count; ++i) {
{
whom->enqueue(nullptr, msg); whom->enqueue(nullptr, msg);
} }
} }
void usage() void usage() {
{
cout << "usage: mailbox_performance " cout << "usage: mailbox_performance "
"(stacked|event-based) (sending threads) (msg per thread)" << endl "(stacked|event-based) (sending threads) (msg per thread)" << endl
<< endl; << endl;
} }
int main(int argc, char** argv) int main(int argc, char** argv) {
{ if (argc == 4) {
if (argc == 4)
{
int64_t num_sender = rd<int64_t>(argv[2]); int64_t num_sender = rd<int64_t>(argv[2]);
int64_t num_msgs = rd<int64_t>(argv[3]); int64_t num_msgs = rd<int64_t>(argv[3]);
actor_ptr testee; actor_ptr testee;
if (strcmp(argv[1], "stacked") == 0) if (strcmp(argv[1], "stacked") == 0) {
{
testee = spawn(receiver, num_sender * num_msgs); testee = spawn(receiver, num_sender * num_msgs);
} }
else if (strcmp(argv[1], "event-based") == 0) else if (strcmp(argv[1], "event-based") == 0) {
{
testee = spawn(new fsm_receiver(num_sender * num_msgs)); testee = spawn(new fsm_receiver(num_sender * num_msgs));
} }
else else {
{
usage(); usage();
return 1; return 1;
} }
for (int64_t i = 0; i < num_sender; ++i) for (int64_t i = 0; i < num_sender; ++i) {
{
detail::thread(sender, testee, num_msgs).detach(); detail::thread(sender, testee, num_msgs).detach();
} }
await_all_others_done(); await_all_others_done();
} }
else else {
{
usage(); usage();
return 1; return 1;
} }
......
...@@ -53,12 +53,10 @@ using std::int64_t; ...@@ -53,12 +53,10 @@ using std::int64_t;
using namespace cppa; using namespace cppa;
template<typename T> template<typename T>
T rd(char const* cstr) T rd(char const* cstr) {
{
char* endptr = nullptr; char* endptr = nullptr;
T result = static_cast<T>(strtol(cstr, &endptr, 10)); T result = static_cast<T>(strtol(cstr, &endptr, 10));
if (endptr == nullptr || *endptr != '\0') if (endptr == nullptr || *endptr != '\0') {
{
std::string errstr; std::string errstr;
errstr += "\""; errstr += "\"";
errstr += cstr; errstr += cstr;
...@@ -68,14 +66,12 @@ T rd(char const* cstr) ...@@ -68,14 +66,12 @@ T rd(char const* cstr)
return result; return result;
} }
void usage() void usage() {
{
cerr << "usage: matching (cow_tuple|object_array) {NUM_LOOPS}" << endl; cerr << "usage: matching (cow_tuple|object_array) {NUM_LOOPS}" << endl;
exit(1); exit(1);
} }
int main(int argc, char** argv) int main(int argc, char** argv) {
{
announce<list<int>>(); announce<list<int>>();
if (argc != 3) usage(); if (argc != 3) usage();
auto num_loops = rd<int64_t>(argv[2]); auto num_loops = rd<int64_t>(argv[2]);
...@@ -86,8 +82,7 @@ int main(int argc, char** argv) ...@@ -86,8 +82,7 @@ int main(int argc, char** argv)
any_tuple m5; any_tuple m5;
any_tuple m6; any_tuple m6;
if (strcmp(argv[1], "cow_tuple") == 0) if (strcmp(argv[1], "cow_tuple") == 0) {
{
m1 = make_cow_tuple(atom("msg1"), 0); m1 = make_cow_tuple(atom("msg1"), 0);
m2 = make_cow_tuple(atom("msg2"), 0.0); m2 = make_cow_tuple(atom("msg2"), 0.0);
m3 = make_cow_tuple(atom("msg3"), list<int>{0}); m3 = make_cow_tuple(atom("msg3"), list<int>{0});
...@@ -95,8 +90,7 @@ int main(int argc, char** argv) ...@@ -95,8 +90,7 @@ int main(int argc, char** argv)
m5 = make_cow_tuple(atom("msg5"), 0, 0, 0); m5 = make_cow_tuple(atom("msg5"), 0, 0, 0);
m6 = make_cow_tuple(atom("msg6"), 0, 0.0, "0"); m6 = make_cow_tuple(atom("msg6"), 0, 0.0, "0");
} }
else if (strcmp(argv[1], "object_array") == 0) else if (strcmp(argv[1], "object_array") == 0) {
{
auto m1o = new detail::object_array; auto m1o = new detail::object_array;
m1o->push_back(object::from(atom("msg1"))); m1o->push_back(object::from(atom("msg1")));
m1o->push_back(object::from(0)); m1o->push_back(object::from(0));
...@@ -127,8 +121,7 @@ int main(int argc, char** argv) ...@@ -127,8 +121,7 @@ int main(int argc, char** argv)
m6o->push_back(object::from(std::string("0"))); m6o->push_back(object::from(std::string("0")));
m6 = any_tuple{m6o}; m6 = any_tuple{m6o};
} }
else else {
{
usage(); usage();
} }
int64_t m1matched = 0; int64_t m1matched = 0;
...@@ -137,8 +130,7 @@ int main(int argc, char** argv) ...@@ -137,8 +130,7 @@ int main(int argc, char** argv)
int64_t m4matched = 0; int64_t m4matched = 0;
int64_t m5matched = 0; int64_t m5matched = 0;
int64_t m6matched = 0; int64_t m6matched = 0;
auto part_fun = auto part_fun = (
(
on<atom("msg1"), int>() >> [&]() { ++m1matched; }, on<atom("msg1"), int>() >> [&]() { ++m1matched; },
on<atom("msg2"), double>() >> [&]() { ++m2matched; }, on<atom("msg2"), double>() >> [&]() { ++m2matched; },
on<atom("msg3"), list<int> >() >> [&]() { ++m3matched; }, on<atom("msg3"), list<int> >() >> [&]() { ++m3matched; },
...@@ -146,8 +138,7 @@ int main(int argc, char** argv) ...@@ -146,8 +138,7 @@ int main(int argc, char** argv)
on<atom("msg5"), int, int, int>() >> [&]() { ++m5matched; }, on<atom("msg5"), int, int, int>() >> [&]() { ++m5matched; },
on<atom("msg6"), int, double, string>() >> [&]() { ++m6matched; } on<atom("msg6"), int, double, string>() >> [&]() { ++m6matched; }
); );
for (int64_t i = 0; i < num_loops; ++i) for (int64_t i = 0; i < num_loops; ++i) {
{
part_fun(m1); part_fun(m1);
part_fun(m2); part_fun(m2);
part_fun(m3); part_fun(m3);
......
This diff is collapsed.
...@@ -18,41 +18,33 @@ struct result { uint32_t value; }; ...@@ -18,41 +18,33 @@ struct result { uint32_t value; };
using namespace Theron; using namespace Theron;
struct testee : Actor struct testee : Actor {
{
Address m_parent; Address m_parent;
bool m_first_result_received; bool m_first_result_received;
uint32_t m_first_result; uint32_t m_first_result;
std::vector<ActorRef> m_children; std::vector<ActorRef> m_children;
void spread_handler(spread const& arg, const Address) void spread_handler(spread const& arg, const Address) {
{ if (arg.value == 0) {
if (arg.value == 0)
{
Send(result{1}, m_parent); Send(result{1}, m_parent);
} }
else else {
{
spread msg = {arg.value-1}; spread msg = {arg.value-1};
Parameters params = {GetAddress()}; Parameters params = {GetAddress()};
for (int i = 0; i < 2; ++i) for (int i = 0; i < 2; ++i) {
{
m_children.push_back(GetFramework().CreateActor<testee>(params)); m_children.push_back(GetFramework().CreateActor<testee>(params));
m_children.back().Push(msg, GetAddress()); m_children.back().Push(msg, GetAddress());
} }
} }
} }
void result_handler(result const& arg, const Address) void result_handler(result const& arg, const Address) {
{ if (!m_first_result_received) {
if (!m_first_result_received)
{
m_first_result_received = true; m_first_result_received = true;
m_first_result = arg.value; m_first_result = arg.value;
} }
else else {
{
m_children.clear(); m_children.clear();
Send(result{m_first_result + arg.value}, m_parent); Send(result{m_first_result + arg.value}, m_parent);
} }
...@@ -60,25 +52,21 @@ struct testee : Actor ...@@ -60,25 +52,21 @@ struct testee : Actor
typedef struct { Address arg0; } Parameters; typedef struct { Address arg0; } Parameters;
testee(Parameters const& p) : m_parent(p.arg0), m_first_result_received(false) testee(Parameters const& p) : m_parent(p.arg0), m_first_result_received(false) {
{
RegisterHandler(this, &testee::spread_handler); RegisterHandler(this, &testee::spread_handler);
RegisterHandler(this, &testee::result_handler); RegisterHandler(this, &testee::result_handler);
} }
}; };
void usage() void usage() {
{
cout << "usage: theron_actor_creation _ POW" << endl cout << "usage: theron_actor_creation _ POW" << endl
<< " creates 2^POW actors" << endl << " creates 2^POW actors" << endl
<< endl; << endl;
} }
int main(int argc, char** argv) int main(int argc, char** argv) {
{ if (argc != 3) {
if (argc != 3)
{
usage(); usage();
return 1; return 1;
} }
......
...@@ -18,47 +18,39 @@ using namespace Theron; ...@@ -18,47 +18,39 @@ using namespace Theron;
int64_t t_max = 0; int64_t t_max = 0;
struct receiver : Actor struct receiver : Actor {
{
int64_t m_num; int64_t m_num;
void handler(int64_t const&, const Address from) void handler(int64_t const&, const Address from) {
{
if (++m_num == t_max) if (++m_num == t_max)
Send(t_max, from); Send(t_max, from);
} }
receiver() : m_num(0) receiver() : m_num(0) {
{
RegisterHandler(this, &receiver::handler); RegisterHandler(this, &receiver::handler);
} }
}; };
void send_sender(Framework& f, ActorRef ref, Address waiter, int64_t num) void send_sender(Framework& f, ActorRef ref, Address waiter, int64_t num) {
{
auto addr = ref.GetAddress(); auto addr = ref.GetAddress();
int64_t msg; int64_t msg;
for (int64_t i = 0; i < num; ++i) f.Send(msg, waiter, addr); for (int64_t i = 0; i < num; ++i) f.Send(msg, waiter, addr);
} }
void push_sender(Framework& f, ActorRef ref, Address waiter, int64_t num) void push_sender(Framework& f, ActorRef ref, Address waiter, int64_t num) {
{
int64_t msg; int64_t msg;
for (int64_t i = 0; i < num; ++i) ref.Push(msg, waiter); for (int64_t i = 0; i < num; ++i) ref.Push(msg, waiter);
} }
void usage() void usage() {
{
cout << "usage ('push'|'send') (num_threads) (num_messages)" << endl; cout << "usage ('push'|'send') (num_threads) (num_messages)" << endl;
exit(1); exit(1);
} }
int main(int argc, char** argv) int main(int argc, char** argv) {
{ if (argc != 4) {
if (argc != 4)
{
usage(); usage();
} }
enum { invalid_impl, push_impl, send_impl } impl = invalid_impl; enum { invalid_impl, push_impl, send_impl } impl = invalid_impl;
...@@ -74,8 +66,7 @@ int main(int argc, char** argv) ...@@ -74,8 +66,7 @@ int main(int argc, char** argv)
ActorRef aref(framework.CreateActor<receiver>()); ActorRef aref(framework.CreateActor<receiver>());
std::list<std::thread> threads; std::list<std::thread> threads;
auto impl_fun = (impl == push_impl) ? send_sender : push_sender; auto impl_fun = (impl == push_impl) ? send_sender : push_sender;
for (int64_t i = 0; i < num_sender; ++i) for (int64_t i = 0; i < num_sender; ++i) {
{
threads.push_back(std::thread(impl_fun, std::ref(framework), aref, receiverAddr, num_msgs)); threads.push_back(std::thread(impl_fun, std::ref(framework), aref, receiverAddr, num_msgs));
} }
r.Wait(); r.Wait();
......
...@@ -30,40 +30,32 @@ struct master_done { }; ...@@ -30,40 +30,32 @@ struct master_done { };
struct worker_done { }; struct worker_done { };
struct worker : Actor struct worker : Actor {
{ void handle_calc(calc_msg const& msg, Address from) {
void handle_calc(calc_msg const& msg, Address from)
{
factorize(msg.value); factorize(msg.value);
} }
void handle_master_done(master_done const&, Address from) void handle_master_done(master_done const&, Address from) {
{
Send(worker_done(), from); Send(worker_done(), from);
} }
worker() worker() {
{
RegisterHandler(this, &worker::handle_calc); RegisterHandler(this, &worker::handle_calc);
RegisterHandler(this, &worker::handle_master_done); RegisterHandler(this, &worker::handle_master_done);
} }
}; };
struct chain_link : Actor struct chain_link : Actor {
{
Address next; Address next;
void handle_token(token_msg const& msg, Address) void handle_token(token_msg const& msg, Address) {
{
Send(msg, next); Send(msg, next);
} }
typedef struct { Address next; } Parameters; typedef struct { Address next; } Parameters;
chain_link(Parameters const& p) : next(p.next) chain_link(Parameters const& p) : next(p.next) {
{
RegisterHandler(this, &chain_link::handle_token); RegisterHandler(this, &chain_link::handle_token);
} }
}; };
struct master : Actor struct master : Actor {
{
Address mc; Address mc;
int iteration; int iteration;
int max_iterations; int max_iterations;
...@@ -72,20 +64,17 @@ struct master : Actor ...@@ -72,20 +64,17 @@ struct master : Actor
int ring_size; int ring_size;
int initial_token_value; int initial_token_value;
std::vector<ActorRef> m_children; std::vector<ActorRef> m_children;
void new_ring() void new_ring() {
{
m_children.clear(); m_children.clear();
w.Push(calc_msg{s_task_n}, GetAddress()); w.Push(calc_msg{s_task_n}, GetAddress());
next = GetAddress(); next = GetAddress();
for (int i = 1; i < ring_size; ++i) for (int i = 1; i < ring_size; ++i) {
{
m_children.push_back(GetFramework().CreateActor<chain_link>(chain_link::Parameters{next})); m_children.push_back(GetFramework().CreateActor<chain_link>(chain_link::Parameters{next}));
next = m_children.back().GetAddress(); next = m_children.back().GetAddress();
} }
Send(token_msg{initial_token_value}, next); Send(token_msg{initial_token_value}, next);
} }
void handle_init(init_msg const& msg, Address) void handle_init(init_msg const& msg, Address) {
{
w = GetFramework().CreateActor<worker>(); w = GetFramework().CreateActor<worker>();
iteration = 0; iteration = 0;
ring_size = msg.ring_size; ring_size = msg.ring_size;
...@@ -93,40 +82,32 @@ struct master : Actor ...@@ -93,40 +82,32 @@ struct master : Actor
max_iterations = msg.iterations; max_iterations = msg.iterations;
new_ring(); new_ring();
} }
void handle_token(token_msg const& msg, Address) void handle_token(token_msg const& msg, Address) {
{ if (msg.value == 0) {
if (msg.value == 0) if (++iteration < max_iterations) {
{
if (++iteration < max_iterations)
{
new_ring(); new_ring();
} }
else else {
{
w.Push(master_done(), GetAddress()); w.Push(master_done(), GetAddress());
} }
} }
else else {
{
Send(token_msg{msg.value - 1}, next); Send(token_msg{msg.value - 1}, next);
} }
} }
void handle_worker_done(worker_done const&, Address) void handle_worker_done(worker_done const&, Address) {
{
Send(master_done(), mc); Send(master_done(), mc);
w = ActorRef::Null(); w = ActorRef::Null();
} }
typedef struct { Address mc; } Parameters; typedef struct { Address mc; } Parameters;
master(Parameters const& p) : mc(p.mc), iteration(0) master(Parameters const& p) : mc(p.mc), iteration(0) {
{
RegisterHandler(this, &master::handle_init); RegisterHandler(this, &master::handle_init);
RegisterHandler(this, &master::handle_token); RegisterHandler(this, &master::handle_token);
RegisterHandler(this, &master::handle_worker_done); RegisterHandler(this, &master::handle_worker_done);
} }
}; };
void usage() void usage() {
{
cout << "usage: mailbox_performance " cout << "usage: mailbox_performance "
"'send' (num rings) (ring size) " "'send' (num rings) (ring size) "
"(initial token value) (repetitions)" "(initial token value) (repetitions)"
...@@ -135,8 +116,7 @@ void usage() ...@@ -135,8 +116,7 @@ void usage()
exit(1); exit(1);
} }
int main(int argc, char** argv) int main(int argc, char** argv) {
{
if (argc != 6) usage(); if (argc != 6) usage();
if (strcmp("send", argv[1]) != 0) usage(); if (strcmp("send", argv[1]) != 0) usage();
int num_rings = rd<int>(argv[2]); int num_rings = rd<int>(argv[2]);
...@@ -146,12 +126,10 @@ int main(int argc, char** argv) ...@@ -146,12 +126,10 @@ int main(int argc, char** argv)
Receiver r; Receiver r;
Framework framework(num_cores()); Framework framework(num_cores());
std::vector<ActorRef> masters; std::vector<ActorRef> masters;
for (int i = 0; i < num_rings; ++i) for (int i = 0; i < num_rings; ++i) {
{
masters.push_back(framework.CreateActor<master>(master::Parameters{r.GetAddress()})); masters.push_back(framework.CreateActor<master>(master::Parameters{r.GetAddress()}));
} }
for (ActorRef& m : masters) for (ActorRef& m : masters) {
{
m.Push(init_msg{ring_size, inital_token_value, repetitions}, r.GetAddress()); m.Push(init_msg{ring_size, inital_token_value, repetitions}, r.GetAddress());
} }
for (int i = 0; i < num_rings; ++i) r.Wait(); for (int i = 0; i < num_rings; ++i) r.Wait();
......
...@@ -37,8 +37,7 @@ ...@@ -37,8 +37,7 @@
#include <stdexcept> #include <stdexcept>
#include <algorithm> #include <algorithm>
inline std::vector<std::string> split(std::string const& str, char delim) inline std::vector<std::string> split(std::string const& str, char delim) {
{
std::vector<std::string> result; std::vector<std::string> result;
std::stringstream strs{str}; std::stringstream strs{str};
std::string tmp; std::string tmp;
...@@ -47,12 +46,10 @@ inline std::vector<std::string> split(std::string const& str, char delim) ...@@ -47,12 +46,10 @@ inline std::vector<std::string> split(std::string const& str, char delim)
} }
inline std::string join(std::vector<std::string> const& vec, inline std::string join(std::vector<std::string> const& vec,
std::string const& delim = "") std::string const& delim = "") {
{
if (vec.empty()) return ""; if (vec.empty()) return "";
auto result = vec.front(); auto result = vec.front();
for (auto i = vec.begin() + 1; i != vec.end(); ++i) for (auto i = vec.begin() + 1; i != vec.end(); ++i) {
{
result += delim; result += delim;
result += *i; result += *i;
} }
...@@ -60,12 +57,10 @@ inline std::string join(std::vector<std::string> const& vec, ...@@ -60,12 +57,10 @@ inline std::string join(std::vector<std::string> const& vec,
} }
template<typename T> template<typename T>
T rd(char const* cstr) T rd(char const* cstr) {
{
char* endptr = nullptr; char* endptr = nullptr;
T result = static_cast<T>(strtol(cstr, &endptr, 10)); T result = static_cast<T>(strtol(cstr, &endptr, 10));
if (endptr == nullptr || *endptr != '\0') if (endptr == nullptr || *endptr != '\0') {
{
std::string errstr; std::string errstr;
errstr += "\""; errstr += "\"";
errstr += cstr; errstr += cstr;
...@@ -75,12 +70,10 @@ T rd(char const* cstr) ...@@ -75,12 +70,10 @@ T rd(char const* cstr)
return result; return result;
} }
int num_cores() int num_cores() {
{
char cbuf[100]; char cbuf[100];
FILE* cmd = popen("/bin/cat /proc/cpuinfo | /bin/grep processor | /usr/bin/wc -l", "r"); FILE* cmd = popen("/bin/cat /proc/cpuinfo | /bin/grep processor | /usr/bin/wc -l", "r");
if (fgets(cbuf, 100, cmd) == 0) if (fgets(cbuf, 100, cmd) == 0) {
{
throw std::runtime_error("cannot determine number of cores"); throw std::runtime_error("cannot determine number of cores");
} }
pclose(cmd); pclose(cmd);
...@@ -90,24 +83,19 @@ int num_cores() ...@@ -90,24 +83,19 @@ int num_cores()
return rd<int>(cbuf); return rd<int>(cbuf);
} }
std::vector<uint64_t> factorize(uint64_t n) std::vector<uint64_t> factorize(uint64_t n) {
{
std::vector<uint64_t> result; std::vector<uint64_t> result;
if (n <= 3) if (n <= 3) {
{
result.push_back(n); result.push_back(n);
return std::move(result); return std::move(result);
} }
uint64_t d = 2; uint64_t d = 2;
while(d < n) while(d < n) {
{ if((n % d) == 0) {
if((n % d) == 0)
{
result.push_back(d); result.push_back(d);
n /= d; n /= d;
} }
else else {
{
d = (d == 2) ? 3 : (d + 2); d = (d == 2) ? 3 : (d + 2);
} }
} }
......
...@@ -4,16 +4,13 @@ ...@@ -4,16 +4,13 @@
using std::cout; using std::cout;
using std::endl; using std::endl;
struct pseudo_worker struct pseudo_worker {
{
int m_value; int m_value;
pseudo_worker() : m_value(0) { } pseudo_worker() : m_value(0) { }
void operator()() void operator()() {
{ for (;;) {
for (;;)
{
++m_value; ++m_value;
cout << "value = " << m_value << endl; cout << "value = " << m_value << endl;
cppa_fibre_yield(0); cppa_fibre_yield(0);
...@@ -21,22 +18,18 @@ struct pseudo_worker ...@@ -21,22 +18,18 @@ struct pseudo_worker
} }
}; };
void coroutine() void coroutine() {
{ auto pw = reinterpret_cast<pseudo_worker*>(cppa_fibre_init_switch_arg()); (*pw)();
auto pw = reinterpret_cast<pseudo_worker*>(cppa_fibre_init_switch_arg());
(*pw)();
} }
int main() int main() {
{
pseudo_worker pw; pseudo_worker pw;
cppa_fibre fself; cppa_fibre fself;
cppa_fibre fcoroutine; cppa_fibre fcoroutine;
cppa_fibre_ctor(&fself); cppa_fibre_ctor(&fself);
cppa_fibre_ctor2(&fcoroutine, coroutine, &pw); cppa_fibre_ctor2(&fcoroutine, coroutine, &pw);
cppa_fibre_initialize(&fcoroutine); cppa_fibre_initialize(&fcoroutine);
for (int i = 1; i < 11; ++i) for (int i = 1; i < 11; ++i) {
{
cout << "i = " << i << endl; cout << "i = " << i << endl;
cppa_fibre_switch(&fself, &fcoroutine); cppa_fibre_switch(&fself, &fcoroutine);
} }
......
...@@ -58,8 +58,7 @@ namespace cppa { ...@@ -58,8 +58,7 @@ namespace cppa {
* or {@link cppa::local_actor local_actor}. * or {@link cppa::local_actor local_actor}.
*/ */
template<class Base> template<class Base>
class abstract_actor : public Base class abstract_actor : public Base {
{
typedef std::unique_ptr<attachable> attachable_ptr; typedef std::unique_ptr<attachable> attachable_ptr;
typedef detail::lock_guard<detail::mutex> guard_type; typedef detail::lock_guard<detail::mutex> guard_type;
...@@ -69,23 +68,19 @@ class abstract_actor : public Base ...@@ -69,23 +68,19 @@ class abstract_actor : public Base
typedef detail::recursive_queue_node mailbox_element; typedef detail::recursive_queue_node mailbox_element;
typedef intrusive::single_reader_queue<mailbox_element> mailbox_type; typedef intrusive::single_reader_queue<mailbox_element> mailbox_type;
bool attach(attachable* ptr) // override bool attach(attachable* ptr) { // override
{ if (ptr == nullptr) {
if (ptr == nullptr)
{
guard_type guard(m_mtx); guard_type guard(m_mtx);
return m_exit_reason.load() == exit_reason::not_exited; return m_exit_reason.load() == exit_reason::not_exited;
} }
else else {
{
attachable_ptr uptr(ptr); attachable_ptr uptr(ptr);
std::uint32_t reason; std::uint32_t reason;
// lifetime scope of guard // lifetime scope of guard
{ {
guard_type guard(m_mtx); guard_type guard(m_mtx);
reason = m_exit_reason.load(); reason = m_exit_reason.load();
if (reason == exit_reason::not_exited) if (reason == exit_reason::not_exited) {
{
m_attachables.push_back(std::move(uptr)); m_attachables.push_back(std::move(uptr));
return true; return true;
} }
...@@ -95,8 +90,7 @@ class abstract_actor : public Base ...@@ -95,8 +90,7 @@ class abstract_actor : public Base
} }
} }
void detach(attachable::token const& what) // override void detach(attachable::token const& what) { // override
{
attachable_ptr uptr; attachable_ptr uptr;
// lifetime scope of guard // lifetime scope of guard
{ {
...@@ -105,8 +99,7 @@ class abstract_actor : public Base ...@@ -105,8 +99,7 @@ class abstract_actor : public Base
auto i = std::find_if( auto i = std::find_if(
m_attachables.begin(), end, m_attachables.begin(), end,
[&](attachable_ptr& p) { return p->matches(what); }); [&](attachable_ptr& p) { return p->matches(what); });
if (i != end) if (i != end) {
{
uptr = std::move(*i); uptr = std::move(*i);
m_attachables.erase(i); m_attachables.erase(i);
} }
...@@ -114,24 +107,19 @@ class abstract_actor : public Base ...@@ -114,24 +107,19 @@ class abstract_actor : public Base
// uptr will be destroyed here, without locked mutex // uptr will be destroyed here, without locked mutex
} }
void link_to(intrusive_ptr<actor>& other) // override void link_to(intrusive_ptr<actor>& other) { // override
{
(void) link_to_impl(other); (void) link_to_impl(other);
} }
void unlink_from(intrusive_ptr<actor>& other) // override void unlink_from(intrusive_ptr<actor>& other) { // override
{
(void) unlink_from_impl(other); (void) unlink_from_impl(other);
} }
bool remove_backlink(intrusive_ptr<actor>& other) // override bool remove_backlink(intrusive_ptr<actor>& other) { // override
{ if (other && other != this) {
if (other && other != this)
{
guard_type guard(m_mtx); guard_type guard(m_mtx);
auto i = std::find(m_links.begin(), m_links.end(), other); auto i = std::find(m_links.begin(), m_links.end(), other);
if (i != m_links.end()) if (i != m_links.end()) {
{
m_links.erase(i); m_links.erase(i);
return true; return true;
} }
...@@ -139,26 +127,21 @@ class abstract_actor : public Base ...@@ -139,26 +127,21 @@ class abstract_actor : public Base
return false; return false;
} }
bool establish_backlink(intrusive_ptr<actor>& other) // override bool establish_backlink(intrusive_ptr<actor>& other) { // override
{
std::uint32_t reason = exit_reason::not_exited; std::uint32_t reason = exit_reason::not_exited;
if (other && other != this) if (other && other != this) {
{
guard_type guard(m_mtx); guard_type guard(m_mtx);
reason = m_exit_reason.load(); reason = m_exit_reason.load();
if (reason == exit_reason::not_exited) if (reason == exit_reason::not_exited) {
{
auto i = std::find(m_links.begin(), m_links.end(), other); auto i = std::find(m_links.begin(), m_links.end(), other);
if (i == m_links.end()) if (i == m_links.end()) {
{
m_links.push_back(other); m_links.push_back(other);
return true; return true;
} }
} }
} }
// send exit message without lock // send exit message without lock
if (reason != exit_reason::not_exited) if (reason != exit_reason::not_exited) {
{
other->enqueue(this, make_cow_tuple(atom("EXIT"), reason)); other->enqueue(this, make_cow_tuple(atom("EXIT"), reason));
} }
return false; return false;
...@@ -172,39 +155,31 @@ class abstract_actor : public Base ...@@ -172,39 +155,31 @@ class abstract_actor : public Base
typedef detail::lock_guard<util::shared_spinlock> lock_type; typedef detail::lock_guard<util::shared_spinlock> lock_type;
inline mailbox_element* fetch_node(actor* sender, any_tuple msg) inline mailbox_element* fetch_node(actor* sender, any_tuple msg) {
{
mailbox_element* result = nullptr; mailbox_element* result = nullptr;
// lifetime scope of guard { // lifetime scope of guard
{
lock_type guard{m_nodes_lock}; lock_type guard{m_nodes_lock};
if (m_nodes.not_empty()) if (m_nodes.not_empty()) {
{
result = m_nodes.back(); result = m_nodes.back();
m_nodes.pop_back(); m_nodes.pop_back();
} }
} }
if (result) if (result) {
{
result->next = nullptr; result->next = nullptr;
result->marked = false; result->marked = false;
result->sender = sender; result->sender = sender;
result->msg = std::move(msg); result->msg = std::move(msg);
} }
else else {
{
result = new mailbox_element(sender, std::move(msg)); result = new mailbox_element(sender, std::move(msg));
} }
return result; return result;
} }
inline void release_node(mailbox_element* node) inline void release_node(mailbox_element* node) {
{ { // lifetime scope of guard
// lifetime scope of guard
{
lock_type guard{m_nodes_lock}; lock_type guard{m_nodes_lock};
if (m_nodes.full() == false) if (m_nodes.full() == false) {
{
m_nodes.push_back(node); m_nodes.push_back(node);
return; return;
} }
...@@ -214,25 +189,20 @@ class abstract_actor : public Base ...@@ -214,25 +189,20 @@ class abstract_actor : public Base
template<typename... Args> template<typename... Args>
abstract_actor(Args&&... args) : Base(std::forward<Args>(args)...) abstract_actor(Args&&... args) : Base(std::forward<Args>(args)...)
, m_exit_reason(exit_reason::not_exited) , m_exit_reason(exit_reason::not_exited) {
{
// pre-allocate some nodes // pre-allocate some nodes
for (size_t i = 0; i < m_nodes.max_size() / 2; ++i) for (size_t i = 0; i < m_nodes.max_size() / 2; ++i) {
{
m_nodes.push_back(new mailbox_element); m_nodes.push_back(new mailbox_element);
} }
} }
void cleanup(std::uint32_t reason) void cleanup(std::uint32_t reason) {
{
if (reason == exit_reason::not_exited) return; if (reason == exit_reason::not_exited) return;
decltype(m_links) mlinks; decltype(m_links) mlinks;
decltype(m_attachables) mattachables; decltype(m_attachables) mattachables;
// lifetime scope of guard { // lifetime scope of guard
{
guard_type guard(m_mtx); guard_type guard(m_mtx);
if (m_exit_reason != exit_reason::not_exited) if (m_exit_reason != exit_reason::not_exited) {
{
// already exited // already exited
return; return;
} }
...@@ -244,31 +214,25 @@ class abstract_actor : public Base ...@@ -244,31 +214,25 @@ class abstract_actor : public Base
m_attachables.clear(); m_attachables.clear();
} }
// send exit messages // send exit messages
for (actor_ptr& aptr : mlinks) for (actor_ptr& aptr : mlinks) {
{
aptr->enqueue(this, make_cow_tuple(atom("EXIT"), reason)); aptr->enqueue(this, make_cow_tuple(atom("EXIT"), reason));
} }
for (attachable_ptr& ptr : mattachables) for (attachable_ptr& ptr : mattachables) {
{
ptr->actor_exited(reason); ptr->actor_exited(reason);
} }
} }
bool link_to_impl(intrusive_ptr<actor>& other) bool link_to_impl(intrusive_ptr<actor>& other) {
{ if (other && other != this) {
if (other && other != this)
{
guard_type guard(m_mtx); guard_type guard(m_mtx);
// send exit message if already exited // send exit message if already exited
if (exited()) if (exited()) {
{
other->enqueue(this, make_cow_tuple(atom("EXIT"), other->enqueue(this, make_cow_tuple(atom("EXIT"),
m_exit_reason.load())); m_exit_reason.load()));
} }
// add link if not already linked to other // add link if not already linked to other
// (checked by establish_backlink) // (checked by establish_backlink)
else if (other->establish_backlink(this)) else if (other->establish_backlink(this)) {
{
m_links.push_back(other); m_links.push_back(other);
return true; return true;
} }
...@@ -276,12 +240,10 @@ class abstract_actor : public Base ...@@ -276,12 +240,10 @@ class abstract_actor : public Base
return false; return false;
} }
bool unlink_from_impl(intrusive_ptr<actor>& other) bool unlink_from_impl(intrusive_ptr<actor>& other) {
{
guard_type guard(m_mtx); guard_type guard(m_mtx);
// remove_backlink returns true if this actor is linked to other // remove_backlink returns true if this actor is linked to other
if (other && !exited() && other->remove_backlink(this)) if (other && !exited() && other->remove_backlink(this)) {
{
auto i = std::find(m_links.begin(), m_links.end(), other); auto i = std::find(m_links.begin(), m_links.end(), other);
CPPA_REQUIRE(i != m_links.end()); CPPA_REQUIRE(i != m_links.end());
m_links.erase(i); m_links.erase(i);
...@@ -293,8 +255,7 @@ class abstract_actor : public Base ...@@ -293,8 +255,7 @@ class abstract_actor : public Base
private: private:
// @pre m_mtx.locked() // @pre m_mtx.locked()
bool exited() const bool exited() const {
{
return m_exit_reason.load() != exit_reason::not_exited; return m_exit_reason.load() != exit_reason::not_exited;
} }
......
...@@ -47,8 +47,7 @@ namespace cppa { ...@@ -47,8 +47,7 @@ namespace cppa {
/** /**
* @brief Base class for all event-based actor implementations. * @brief Base class for all event-based actor implementations.
*/ */
class abstract_event_based_actor : public detail::abstract_scheduled_actor class abstract_event_based_actor : public detail::abstract_scheduled_actor {
{
typedef detail::abstract_scheduled_actor super; typedef detail::abstract_scheduled_actor super;
...@@ -74,8 +73,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor ...@@ -74,8 +73,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor
std::vector<std::unique_ptr<detail::recursive_queue_node> > m_cache; std::vector<std::unique_ptr<detail::recursive_queue_node> > m_cache;
enum handle_message_result enum handle_message_result {
{
drop_msg, drop_msg,
msg_handled, msg_handled,
cache_msg cache_msg
...@@ -98,8 +96,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor ...@@ -98,8 +96,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor
* does not accidently uses receive() instead of become(). * does not accidently uses receive() instead of become().
*/ */
template<typename... Args> template<typename... Args>
void receive(Args&&...) void receive(Args&&...) {
{
static_assert((sizeof...(Args) + 1) < 1, static_assert((sizeof...(Args) + 1) < 1,
"You shall not use receive in an event-based actor. " "You shall not use receive in an event-based actor. "
"Use become() instead."); "Use become() instead.");
...@@ -109,8 +106,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor ...@@ -109,8 +106,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor
* @brief Provokes a compiler error. * @brief Provokes a compiler error.
*/ */
template<typename... Args> template<typename... Args>
void receive_loop(Args&&... args) void receive_loop(Args&&... args) {
{
receive(std::forward<Args>(args)...); receive(std::forward<Args>(args)...);
} }
...@@ -118,8 +114,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor ...@@ -118,8 +114,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor
* @brief Provokes a compiler error. * @brief Provokes a compiler error.
*/ */
template<typename... Args> template<typename... Args>
void receive_while(Args&&... args) void receive_while(Args&&... args) {
{
receive(std::forward<Args>(args)...); receive(std::forward<Args>(args)...);
} }
...@@ -127,8 +122,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor ...@@ -127,8 +122,7 @@ class abstract_event_based_actor : public detail::abstract_scheduled_actor
* @brief Provokes a compiler error. * @brief Provokes a compiler error.
*/ */
template<typename... Args> template<typename... Args>
void do_receive(Args&&... args) void do_receive(Args&&... args) {
{
receive(std::forward<Args>(args)...); receive(std::forward<Args>(args)...);
} }
......
...@@ -52,8 +52,7 @@ typedef std::uint32_t actor_id; ...@@ -52,8 +52,7 @@ typedef std::uint32_t actor_id;
/** /**
* @brief Base class for all actor implementations. * @brief Base class for all actor implementations.
*/ */
class actor : public channel class actor : public channel {
{
public: public:
...@@ -224,23 +223,19 @@ typedef intrusive_ptr<actor> actor_ptr; ...@@ -224,23 +223,19 @@ typedef intrusive_ptr<actor> actor_ptr;
* inline and template member function implementations * * inline and template member function implementations *
******************************************************************************/ ******************************************************************************/
inline process_information const& actor::parent_process() const inline process_information const& actor::parent_process() const {
{
return *m_parent_process; return *m_parent_process;
} }
inline process_information_ptr actor::parent_process_ptr() const inline process_information_ptr actor::parent_process_ptr() const {
{
return m_parent_process; return m_parent_process;
} }
inline std::uint32_t actor::id() const inline std::uint32_t actor::id() const {
{
return m_id; return m_id;
} }
inline bool actor::is_proxy() const inline bool actor::is_proxy() const {
{
return m_is_proxy; return m_is_proxy;
} }
...@@ -248,39 +243,33 @@ template<typename T> ...@@ -248,39 +243,33 @@ template<typename T>
bool actor::attach(std::unique_ptr<T>&& ptr, bool actor::attach(std::unique_ptr<T>&& ptr,
typename std::enable_if< typename std::enable_if<
std::is_base_of<attachable,T>::value std::is_base_of<attachable,T>::value
>::type*) >::type*) {
{
return attach(static_cast<attachable*>(ptr.release())); return attach(static_cast<attachable*>(ptr.release()));
} }
template<class F> template<class F>
class functor_attachable : public attachable class functor_attachable : public attachable {
{
F m_functor; F m_functor;
public: public:
template<class FArg> template<class FArg>
functor_attachable(FArg&& arg) : m_functor(std::forward<FArg>(arg)) functor_attachable(FArg&& arg) : m_functor(std::forward<FArg>(arg)) {
{
} }
void actor_exited(std::uint32_t reason) void actor_exited(std::uint32_t reason) {
{
m_functor(reason); m_functor(reason);
} }
bool matches(attachable::token const&) bool matches(attachable::token const&) {
{
return false; return false;
} }
}; };
template<typename F> template<typename F>
bool actor::attach_functor(F&& ftor) bool actor::attach_functor(F&& ftor) {
{
typedef typename util::rm_ref<F>::type f_type; typedef typename util::rm_ref<F>::type f_type;
return attach(new functor_attachable<f_type>(std::forward<F>(ftor))); return attach(new functor_attachable<f_type>(std::forward<F>(ftor)));
} }
......
...@@ -45,8 +45,7 @@ class actor_proxy : public actor { }; ...@@ -45,8 +45,7 @@ class actor_proxy : public actor { };
#else // CPPA_DOCUMENTATION #else // CPPA_DOCUMENTATION
class actor_proxy : public abstract_actor<actor> class actor_proxy : public abstract_actor<actor> {
{
typedef abstract_actor<actor> super; typedef abstract_actor<actor> super;
......
...@@ -110,16 +110,14 @@ bool announce(std::type_info const& tinfo, uniform_type_info* utype); ...@@ -110,16 +110,14 @@ bool announce(std::type_info const& tinfo, uniform_type_info* utype);
*/ */
template<class C, class Parent, typename... Args> template<class C, class Parent, typename... Args>
std::pair<C Parent::*, util::abstract_uniform_type_info<C>*> std::pair<C Parent::*, util::abstract_uniform_type_info<C>*>
compound_member(C Parent::*c_ptr, Args const&... args) compound_member(C Parent::*c_ptr, Args const&... args) {
{
return { c_ptr, new detail::default_uniform_type_info_impl<C>(args...) }; return { c_ptr, new detail::default_uniform_type_info_impl<C>(args...) };
} }
// deals with getter returning a mutable reference // deals with getter returning a mutable reference
template<class C, class Parent, typename... Args> template<class C, class Parent, typename... Args>
std::pair<C& (Parent::*)(), util::abstract_uniform_type_info<C>*> std::pair<C& (Parent::*)(), util::abstract_uniform_type_info<C>*>
compound_member(C& (Parent::*c_ptr)(), Args const&... args) compound_member(C& (Parent::*c_ptr)(), Args const&... args) {
{
return { c_ptr, new detail::default_uniform_type_info_impl<C>(args...) }; return { c_ptr, new detail::default_uniform_type_info_impl<C>(args...) };
} }
...@@ -129,8 +127,7 @@ template<class Parent, typename GRes, ...@@ -129,8 +127,7 @@ template<class Parent, typename GRes,
std::pair<std::pair<GRes (Parent::*)() const, SRes (Parent::*)(SArg)>, std::pair<std::pair<GRes (Parent::*)() const, SRes (Parent::*)(SArg)>,
util::abstract_uniform_type_info<typename util::rm_ref<GRes>::type>*> util::abstract_uniform_type_info<typename util::rm_ref<GRes>::type>*>
compound_member(const std::pair<GRes (Parent::*)() const, SRes (Parent::*)(SArg)>& gspair, compound_member(const std::pair<GRes (Parent::*)() const, SRes (Parent::*)(SArg)>& gspair,
Args const&... args) Args const&... args) {
{
return { gspair, new detail::default_uniform_type_info_impl<typename util::rm_ref<GRes>::type>(args...) }; return { gspair, new detail::default_uniform_type_info_impl<typename util::rm_ref<GRes>::type>(args...) };
} }
...@@ -142,8 +139,7 @@ compound_member(const std::pair<GRes (Parent::*)() const, SRes (Parent::*)(SArg) ...@@ -142,8 +139,7 @@ compound_member(const std::pair<GRes (Parent::*)() const, SRes (Parent::*)(SArg)
* otherwise @c false. * otherwise @c false.
*/ */
template<typename T, typename... Args> template<typename T, typename... Args>
inline bool announce(Args const&... args) inline bool announce(Args const&... args) {
{
return announce(typeid(T), return announce(typeid(T),
new detail::default_uniform_type_info_impl<T>(args...)); new detail::default_uniform_type_info_impl<T>(args...));
} }
......
...@@ -51,8 +51,7 @@ namespace cppa { ...@@ -51,8 +51,7 @@ namespace cppa {
* @brief Describes a fixed-length copy-on-write tuple * @brief Describes a fixed-length copy-on-write tuple
* with elements of any type. * with elements of any type.
*/ */
class any_tuple class any_tuple {
{
public: public:
...@@ -129,15 +128,13 @@ class any_tuple ...@@ -129,15 +128,13 @@ class any_tuple
inline bool empty() const { return size() == 0; } inline bool empty() const { return size() == 0; }
template<typename T> template<typename T>
inline T const& get_as(size_t p) const inline T const& get_as(size_t p) const {
{
CPPA_REQUIRE(*(type_at(p)) == typeid(T)); CPPA_REQUIRE(*(type_at(p)) == typeid(T));
return *reinterpret_cast<T const*>(at(p)); return *reinterpret_cast<T const*>(at(p));
} }
template<typename T> template<typename T>
inline T& get_as_mutable(size_t p) inline T& get_as_mutable(size_t p) {
{
CPPA_REQUIRE(*(type_at(p)) == typeid(T)); CPPA_REQUIRE(*(type_at(p)) == typeid(T));
return *reinterpret_cast<T*>(mutable_at(p)); return *reinterpret_cast<T*>(mutable_at(p));
} }
...@@ -150,13 +147,11 @@ class any_tuple ...@@ -150,13 +147,11 @@ class any_tuple
inline cow_ptr<detail::abstract_tuple> const& vals() const { return m_vals; } inline cow_ptr<detail::abstract_tuple> const& vals() const { return m_vals; }
inline cow_ptr<detail::abstract_tuple> const& cvals() const { return m_vals; } inline cow_ptr<detail::abstract_tuple> const& cvals() const { return m_vals; }
inline std::type_info const* type_token() const inline std::type_info const* type_token() const {
{
return m_vals->type_token(); return m_vals->type_token();
} }
inline detail::tuple_impl_info impl_type() const inline detail::tuple_impl_info impl_type() const {
{
return m_vals->impl_type(); return m_vals->impl_type();
} }
...@@ -166,8 +161,7 @@ class any_tuple ...@@ -166,8 +161,7 @@ class any_tuple
util::is_iterable< util::is_iterable<
typename util::rm_ref<T>::type typename util::rm_ref<T>::type
>::value >::value
>::type* = 0) >::type* = 0) {
{
static constexpr bool can_optimize = std::is_reference<T>::value static constexpr bool can_optimize = std::is_reference<T>::value
&& !std::is_const<T>::value; && !std::is_const<T>::value;
std::integral_constant<bool, can_optimize> token; std::integral_constant<bool, can_optimize> token;
...@@ -180,8 +174,7 @@ class any_tuple ...@@ -180,8 +174,7 @@ class any_tuple
util::is_iterable< util::is_iterable<
typename util::rm_ref<T>::type typename util::rm_ref<T>::type
>::value == false >::value == false
>::type* = 0) >::type* = 0) {
{
typedef typename util::rm_ref<T>::type vtype; typedef typename util::rm_ref<T>::type vtype;
typedef typename detail::implicit_conversions<vtype>::type converted; typedef typename detail::implicit_conversions<vtype>::type converted;
static_assert(util::is_legal_tuple_type<converted>::value, static_assert(util::is_legal_tuple_type<converted>::value,
...@@ -194,8 +187,7 @@ class any_tuple ...@@ -194,8 +187,7 @@ class any_tuple
return any_tuple{simple_view(std::forward<T>(value), token)}; return any_tuple{simple_view(std::forward<T>(value), token)};
} }
void force_detach() void force_detach() {
{
m_vals.detach(); m_vals.detach();
} }
...@@ -211,22 +203,19 @@ class any_tuple ...@@ -211,22 +203,19 @@ class any_tuple
template<typename T> template<typename T>
static inline tup_ptr simple_view(T& value, static inline tup_ptr simple_view(T& value,
std::integral_constant<bool, true>) std::integral_constant<bool, true>) {
{
return new detail::tuple_view<T>(&value); return new detail::tuple_view<T>(&value);
} }
template<typename First, typename Second> template<typename First, typename Second>
static inline tup_ptr simple_view(std::pair<First, Second>& p, static inline tup_ptr simple_view(std::pair<First, Second>& p,
std::integral_constant<bool, true>) std::integral_constant<bool, true>) {
{
return new detail::tuple_view<First, Second>(&p.first, &p.second); return new detail::tuple_view<First, Second>(&p.first, &p.second);
} }
template<typename T> template<typename T>
static inline tup_ptr simple_view(T&& value, static inline tup_ptr simple_view(T&& value,
std::integral_constant<bool, false>) std::integral_constant<bool, false>) {
{
typedef typename util::rm_ref<T>::type vtype; typedef typename util::rm_ref<T>::type vtype;
typedef typename detail::implicit_conversions<vtype>::type converted; typedef typename detail::implicit_conversions<vtype>::type converted;
return new detail::tuple_vals<converted>(std::forward<T>(value)); return new detail::tuple_vals<converted>(std::forward<T>(value));
...@@ -234,23 +223,20 @@ class any_tuple ...@@ -234,23 +223,20 @@ class any_tuple
template<typename First, typename Second> template<typename First, typename Second>
static inline any_tuple view(std::pair<First, Second> p, static inline any_tuple view(std::pair<First, Second> p,
std::integral_constant<bool, false>) std::integral_constant<bool, false>) {
{
return new detail::tuple_vals<First, Second>(std::move(p.first), return new detail::tuple_vals<First, Second>(std::move(p.first),
std::move(p.second)); std::move(p.second));
} }
template<typename T> template<typename T>
static inline detail::abstract_tuple* container_view(T& value, static inline detail::abstract_tuple* container_view(T& value,
std::integral_constant<bool, true>) std::integral_constant<bool, true>) {
{
return new detail::container_tuple_view<T>(&value); return new detail::container_tuple_view<T>(&value);
} }
template<typename T> template<typename T>
static inline detail::abstract_tuple* container_view(T&& value, static inline detail::abstract_tuple* container_view(T&& value,
std::integral_constant<bool, false>) std::integral_constant<bool, false>) {
{
typedef typename util::rm_ref<T>::type ctype; typedef typename util::rm_ref<T>::type ctype;
return new detail::container_tuple_view<T>(new ctype(std::forward<T>(value)), true); return new detail::container_tuple_view<T>(new ctype(std::forward<T>(value)), true);
} }
...@@ -260,22 +246,19 @@ class any_tuple ...@@ -260,22 +246,19 @@ class any_tuple
/** /**
* @relates any_tuple * @relates any_tuple
*/ */
inline bool operator==(any_tuple const& lhs, any_tuple const& rhs) inline bool operator==(any_tuple const& lhs, any_tuple const& rhs) {
{
return lhs.equals(rhs); return lhs.equals(rhs);
} }
/** /**
* @relates any_tuple * @relates any_tuple
*/ */
inline bool operator!=(any_tuple const& lhs, any_tuple const& rhs) inline bool operator!=(any_tuple const& lhs, any_tuple const& rhs) {
{
return !(lhs == rhs); return !(lhs == rhs);
} }
template<typename... Args> template<typename... Args>
inline any_tuple make_any_tuple(Args&&... args) inline any_tuple make_any_tuple(Args&&... args) {
{
return make_cow_tuple(std::forward<Args>(args)...); return make_cow_tuple(std::forward<Args>(args)...);
} }
......
...@@ -40,19 +40,16 @@ namespace cppa { ...@@ -40,19 +40,16 @@ namespace cppa {
*/ */
struct anything { }; struct anything { };
inline bool operator==(anything const&, anything const&) inline bool operator==(anything const&, anything const&) {
{
return true; return true;
} }
inline bool operator!=(anything const&, anything const&) inline bool operator!=(anything const&, anything const&) {
{
return false; return false;
} }
template<typename T> template<typename T>
struct is_anything struct is_anything {
{
static constexpr bool value = std::is_same<T, anything>::value; static constexpr bool value = std::is_same<T, anything>::value;
}; };
......
...@@ -45,8 +45,7 @@ std::string to_string(atom_value const& a); ...@@ -45,8 +45,7 @@ std::string to_string(atom_value const& a);
* @brief Creates an atom from given string literal. * @brief Creates an atom from given string literal.
*/ */
template<size_t Size> template<size_t Size>
constexpr atom_value atom(char const (&str) [Size]) constexpr atom_value atom(char const (&str) [Size]) {
{
// last character is the NULL terminator // last character is the NULL terminator
static_assert(Size <= 11, "only 10 characters are allowed"); static_assert(Size <= 11, "only 10 characters are allowed");
return static_cast<atom_value>(detail::atom_val(str, 0xF)); return static_cast<atom_value>(detail::atom_val(str, 0xF));
......
...@@ -39,8 +39,7 @@ namespace cppa { ...@@ -39,8 +39,7 @@ namespace cppa {
/** /**
* @brief Callback utility class. * @brief Callback utility class.
*/ */
class attachable class attachable {
{
attachable(attachable const&) = delete; attachable(attachable const&) = delete;
attachable& operator=(attachable const&) = delete; attachable& operator=(attachable const&) = delete;
...@@ -54,8 +53,7 @@ class attachable ...@@ -54,8 +53,7 @@ class attachable
/** /**
* @brief Represents a pointer to a value with its RTTI. * @brief Represents a pointer to a value with its RTTI.
*/ */
struct token struct token {
{
/** /**
* @brief Denotes the type of @c ptr. * @brief Denotes the type of @c ptr.
*/ */
...@@ -65,8 +63,7 @@ class attachable ...@@ -65,8 +63,7 @@ class attachable
*/ */
void const* ptr; void const* ptr;
inline token(std::type_info const& msubtype, void const* mptr) inline token(std::type_info const& msubtype, void const* mptr)
: subtype(msubtype), ptr(mptr) : subtype(msubtype), ptr(mptr) {
{
} }
}; };
......
...@@ -49,8 +49,7 @@ namespace cppa { ...@@ -49,8 +49,7 @@ namespace cppa {
/** /**
* @brief Describes the behavior of an actor. * @brief Describes the behavior of an actor.
*/ */
class behavior class behavior {
{
friend behavior operator,(partial_function&& lhs, behavior&& rhs); friend behavior operator,(partial_function&& lhs, behavior&& rhs);
...@@ -62,16 +61,14 @@ class behavior ...@@ -62,16 +61,14 @@ class behavior
behavior() = default; behavior() = default;
behavior(behavior&&) = default; behavior(behavior&&) = default;
inline behavior(partial_function&& fun) : m_fun(std::move(fun)) inline behavior(partial_function&& fun) : m_fun(std::move(fun)) {
{
} }
template<typename... Cases> template<typename... Cases>
behavior(match_expr<Cases...> const& me) : m_fun(me) { } behavior(match_expr<Cases...> const& me) : m_fun(me) { }
inline behavior(util::duration tout, std::function<void()>&& handler) inline behavior(util::duration tout, std::function<void()>&& handler)
: m_timeout(tout), m_timeout_handler(std::move(handler)) : m_timeout(tout), m_timeout_handler(std::move(handler)) {
{
} }
behavior& operator=(behavior&&) = default; behavior& operator=(behavior&&) = default;
...@@ -82,33 +79,27 @@ class behavior ...@@ -82,33 +79,27 @@ class behavior
// return *this; // return *this;
//} //}
inline void handle_timeout() const inline void handle_timeout() const {
{
m_timeout_handler(); m_timeout_handler();
} }
inline util::duration const& timeout() const inline util::duration const& timeout() const {
{
return m_timeout; return m_timeout;
} }
inline partial_function& get_partial_function() inline partial_function& get_partial_function() {
{
return m_fun; return m_fun;
} }
inline bool operator()(any_tuple& value) inline bool operator()(any_tuple& value) {
{
return m_fun(value); return m_fun(value);
} }
inline bool operator()(any_tuple const& value) inline bool operator()(any_tuple const& value) {
{
return m_fun(value); return m_fun(value);
} }
inline bool operator()(any_tuple&& value) inline bool operator()(any_tuple&& value) {
{
return m_fun(std::move(value)); return m_fun(std::move(value));
} }
...@@ -125,21 +116,18 @@ class behavior ...@@ -125,21 +116,18 @@ class behavior
template<typename... Lhs> template<typename... Lhs>
behavior operator,(match_expr<Lhs...> const& lhs, behavior operator,(match_expr<Lhs...> const& lhs,
behavior&& rhs) behavior&& rhs) {
{
rhs.get_partial_function() = lhs; rhs.get_partial_function() = lhs;
return std::move(rhs); return std::move(rhs);
} }
template<typename Arg0> template<typename Arg0>
behavior bhvr_collapse(Arg0&& arg) behavior bhvr_collapse(Arg0&& arg) {
{
return {std::forward<Arg0>(arg)}; return {std::forward<Arg0>(arg)};
} }
template<typename Arg0, typename Arg1, typename... Args> template<typename Arg0, typename Arg1, typename... Args>
behavior bhvr_collapse(Arg0&& arg0, Arg1&& arg1, Args&&... args) behavior bhvr_collapse(Arg0&& arg0, Arg1&& arg1, Args&&... args) {
{
return bhvr_collapse((std::forward<Arg0>(arg0), std::forward<Arg1>(arg1)), return bhvr_collapse((std::forward<Arg0>(arg0), std::forward<Arg1>(arg1)),
std::forward<Args>(args)...); std::forward<Args>(args)...);
} }
...@@ -149,8 +137,7 @@ typename std::enable_if< ...@@ -149,8 +137,7 @@ typename std::enable_if<
util::disjunction<std::is_same<behavior, Args>...>::value, util::disjunction<std::is_same<behavior, Args>...>::value,
behavior behavior
>::type >::type
match_expr_concat(Args&&... args) match_expr_concat(Args&&... args) {
{
return bhvr_collapse(std::forward<Args>(args)...); return bhvr_collapse(std::forward<Args>(args)...);
} }
...@@ -164,26 +151,22 @@ typename std::enable_if< ...@@ -164,26 +151,22 @@ typename std::enable_if<
>::value == false, >::value == false,
partial_function partial_function
>::type >::type
match_expr_concat(Args&&... args) match_expr_concat(Args&&... args) {
{
return mexpr_concat_convert(std::forward<Args>(args)...); return mexpr_concat_convert(std::forward<Args>(args)...);
} }
inline partial_function match_expr_concat(partial_function&& pfun) inline partial_function match_expr_concat(partial_function&& pfun) {
{
return std::move(pfun); return std::move(pfun);
} }
inline behavior match_expr_concat(behavior&& bhvr) inline behavior match_expr_concat(behavior&& bhvr) {
{
return std::move(bhvr); return std::move(bhvr);
} }
namespace detail { namespace detail {
template<typename... Ts> template<typename... Ts>
struct select_bhvr struct select_bhvr {
{
static constexpr bool timed = static constexpr bool timed =
util::disjunction<std::is_same<behavior, Ts>...>::value; util::disjunction<std::is_same<behavior, Ts>...>::value;
typedef typename util::if_else_c<timed, typedef typename util::if_else_c<timed,
......
...@@ -39,8 +39,7 @@ namespace cppa { ...@@ -39,8 +39,7 @@ namespace cppa {
* @brief Implements the deserializer interface with * @brief Implements the deserializer interface with
* a binary serialization protocol. * a binary serialization protocol.
*/ */
class binary_deserializer : public deserializer class binary_deserializer : public deserializer {
{
char const* pos; char const* pos;
char const* end; char const* end;
......
...@@ -42,8 +42,7 @@ namespace detail { class binary_writer; } ...@@ -42,8 +42,7 @@ namespace detail { class binary_writer; }
* @brief Implements the serializer interface with * @brief Implements the serializer interface with
* a binary serialization protocol. * a binary serialization protocol.
*/ */
class binary_serializer : public serializer class binary_serializer : public serializer {
{
friend class detail::binary_writer; friend class detail::binary_writer;
......
...@@ -47,8 +47,7 @@ class any_tuple; ...@@ -47,8 +47,7 @@ class any_tuple;
* This interface describes an entity that can receive messages * This interface describes an entity that can receive messages
* and is implemented by {@link actor} and {@link group}. * and is implemented by {@link actor} and {@link group}.
*/ */
class channel : public ref_counted class channel : public ref_counted {
{
friend class actor; friend class actor;
friend class group; friend class group;
......
...@@ -46,8 +46,7 @@ namespace cppa { ...@@ -46,8 +46,7 @@ namespace cppa {
* {@link ref_counted}. * {@link ref_counted}.
*/ */
template<typename T> template<typename T>
class cow_ptr class cow_ptr {
{
public: public:
...@@ -63,35 +62,29 @@ class cow_ptr ...@@ -63,35 +62,29 @@ class cow_ptr
template<typename Y> template<typename Y>
cow_ptr(cow_ptr<Y> const& other) : m_ptr(const_cast<Y*>(other.get())) { } cow_ptr(cow_ptr<Y> const& other) : m_ptr(const_cast<Y*>(other.get())) { }
inline void swap(cow_ptr& other) inline void swap(cow_ptr& other) {
{
m_ptr.swap(other.m_ptr); m_ptr.swap(other.m_ptr);
} }
cow_ptr& operator=(cow_ptr&& other) cow_ptr& operator=(cow_ptr&& other) {
{
swap(other); swap(other);
return *this; return *this;
} }
cow_ptr& operator=(cow_ptr const& other) cow_ptr& operator=(cow_ptr const& other) {
{
cow_ptr tmp{other}; cow_ptr tmp{other};
swap(tmp); swap(tmp);
return *this; return *this;
} }
template<typename Y> template<typename Y>
cow_ptr& operator=(cow_ptr<Y> const& other) cow_ptr& operator=(cow_ptr<Y> const& other) {
{
cow_ptr tmp{other}; cow_ptr tmp{other};
swap(tmp); swap(tmp);
return *this; return *this;
} }
void detach() void detach() { (void) detached_ptr();
{
(void) detached_ptr();
} }
inline void reset(T* value = nullptr) { m_ptr.reset(value); } inline void reset(T* value = nullptr) { m_ptr.reset(value); }
...@@ -114,11 +107,9 @@ class cow_ptr ...@@ -114,11 +107,9 @@ class cow_ptr
intrusive_ptr<T> m_ptr; intrusive_ptr<T> m_ptr;
T* detached_ptr() T* detached_ptr() {
{
T* ptr = m_ptr.get(); T* ptr = m_ptr.get();
if (!ptr->unique()) if (!ptr->unique()) {
{
//T* new_ptr = detail::copy_of(ptr, copy_of_token()); //T* new_ptr = detail::copy_of(ptr, copy_of_token());
T* new_ptr = ptr->copy(); T* new_ptr = ptr->copy();
cow_ptr tmp(new_ptr); cow_ptr tmp(new_ptr);
......
...@@ -63,8 +63,7 @@ class local_actor; ...@@ -63,8 +63,7 @@ class local_actor;
* @brief A fixed-length copy-on-write cow_tuple. * @brief A fixed-length copy-on-write cow_tuple.
*/ */
template<typename... ElementTypes> template<typename... ElementTypes>
class cow_tuple class cow_tuple {
{
static_assert(sizeof...(ElementTypes) > 0, "tuple is empty"); static_assert(sizeof...(ElementTypes) > 0, "tuple is empty");
...@@ -94,24 +93,21 @@ class cow_tuple ...@@ -94,24 +93,21 @@ class cow_tuple
/** /**
* @brief Initializes each element with its default constructor. * @brief Initializes each element with its default constructor.
*/ */
cow_tuple() : m_vals(new data_type) cow_tuple() : m_vals(new data_type) {
{
} }
/** /**
* @brief Initializes the cow_tuple with @p args. * @brief Initializes the cow_tuple with @p args.
* @param args Initialization values. * @param args Initialization values.
*/ */
cow_tuple(ElementTypes const&... args) : m_vals(new data_type(args...)) cow_tuple(ElementTypes const&... args) : m_vals(new data_type(args...)) {
{
} }
/** /**
* @brief Initializes the cow_tuple with @p args. * @brief Initializes the cow_tuple with @p args.
* @param args Initialization values. * @param args Initialization values.
*/ */
cow_tuple(ElementTypes&&... args) : m_vals(new data_type(std::move(args)...)) cow_tuple(ElementTypes&&... args) : m_vals(new data_type(std::move(args)...)) {
{
} }
cow_tuple(cow_tuple&&) = default; cow_tuple(cow_tuple&&) = default;
...@@ -119,19 +115,16 @@ class cow_tuple ...@@ -119,19 +115,16 @@ class cow_tuple
cow_tuple& operator=(cow_tuple&&) = default; cow_tuple& operator=(cow_tuple&&) = default;
cow_tuple& operator=(cow_tuple const&) = default; cow_tuple& operator=(cow_tuple const&) = default;
inline static cow_tuple from(cow_ptr_type ptr) inline static cow_tuple from(cow_ptr_type ptr) {
{
return {priv_ctor{}, std::move(ptr)}; return {priv_ctor{}, std::move(ptr)};
} }
inline static cow_tuple from(cow_ptr_type ptr, inline static cow_tuple from(cow_ptr_type ptr,
util::fixed_vector<size_t, num_elements> const& mv) util::fixed_vector<size_t, num_elements> const& mv) {
{
return {priv_ctor{}, decorated_type::create(std::move(ptr), mv)}; return {priv_ctor{}, decorated_type::create(std::move(ptr), mv)};
} }
inline static cow_tuple offset_subtuple(cow_ptr_type ptr, size_t offset) inline static cow_tuple offset_subtuple(cow_ptr_type ptr, size_t offset) {
{
CPPA_REQUIRE(offset > 0); CPPA_REQUIRE(offset > 0);
return {priv_ctor{}, decorated_type::create(std::move(ptr), offset)}; return {priv_ctor{}, decorated_type::create(std::move(ptr), offset)};
} }
...@@ -139,24 +132,21 @@ class cow_tuple ...@@ -139,24 +132,21 @@ class cow_tuple
/** /**
* @brief Gets the size of this cow_tuple. * @brief Gets the size of this cow_tuple.
*/ */
inline size_t size() const inline size_t size() const {
{
return sizeof...(ElementTypes); return sizeof...(ElementTypes);
} }
/** /**
* @brief Gets a const pointer to the element at position @p p. * @brief Gets a const pointer to the element at position @p p.
*/ */
inline void const* at(size_t p) const inline void const* at(size_t p) const {
{
return m_vals->at(p); return m_vals->at(p);
} }
/** /**
* @brief Gets a mutable pointer to the element at position @p p. * @brief Gets a mutable pointer to the element at position @p p.
*/ */
inline void* mutable_at(size_t p) inline void* mutable_at(size_t p) {
{
return m_vals->mutable_at(p); return m_vals->mutable_at(p);
} }
...@@ -164,13 +154,11 @@ class cow_tuple ...@@ -164,13 +154,11 @@ class cow_tuple
* @brief Gets {@link uniform_type_info uniform type information} * @brief Gets {@link uniform_type_info uniform type information}
* of the element at position @p p. * of the element at position @p p.
*/ */
inline uniform_type_info const* type_at(size_t p) const inline uniform_type_info const* type_at(size_t p) const {
{
return m_vals->type_at(p); return m_vals->type_at(p);
} }
inline cow_ptr<detail::abstract_tuple> const& vals() const inline cow_ptr<detail::abstract_tuple> const& vals() const {
{
return m_vals; return m_vals;
} }
...@@ -180,8 +168,7 @@ template<typename TypeList> ...@@ -180,8 +168,7 @@ template<typename TypeList>
struct cow_tuple_from_type_list; struct cow_tuple_from_type_list;
template<typename... Types> template<typename... Types>
struct cow_tuple_from_type_list< util::type_list<Types...> > struct cow_tuple_from_type_list< util::type_list<Types...> > {
{
typedef cow_tuple<Types...> type; typedef cow_tuple<Types...> type;
}; };
...@@ -223,23 +210,20 @@ cow_tuple<Args...> make_cow_tuple(Args&&... args); ...@@ -223,23 +210,20 @@ cow_tuple<Args...> make_cow_tuple(Args&&... args);
#else #else
template<size_t N, typename... Types> template<size_t N, typename... Types>
const typename util::at<N, Types...>::type& get(cow_tuple<Types...> const& tup) const typename util::at<N, Types...>::type& get(cow_tuple<Types...> const& tup) {
{
typedef typename util::at<N, Types...>::type result_type; typedef typename util::at<N, Types...>::type result_type;
return *reinterpret_cast<result_type const*>(tup.at(N)); return *reinterpret_cast<result_type const*>(tup.at(N));
} }
template<size_t N, typename... Types> template<size_t N, typename... Types>
typename util::at<N, Types...>::type& get_ref(cow_tuple<Types...>& tup) typename util::at<N, Types...>::type& get_ref(cow_tuple<Types...>& tup) {
{
typedef typename util::at<N, Types...>::type result_type; typedef typename util::at<N, Types...>::type result_type;
return *reinterpret_cast<result_type*>(tup.mutable_at(N)); return *reinterpret_cast<result_type*>(tup.mutable_at(N));
} }
template<typename... Args> template<typename... Args>
cow_tuple<typename detail::strip_and_convert<Args>::type...> cow_tuple<typename detail::strip_and_convert<Args>::type...>
make_cow_tuple(Args&&... args) make_cow_tuple(Args&&... args) {
{
return {std::forward<Args>(args)...}; return {std::forward<Args>(args)...};
} }
...@@ -254,8 +238,7 @@ make_cow_tuple(Args&&... args) ...@@ -254,8 +238,7 @@ make_cow_tuple(Args&&... args)
*/ */
template<typename... LhsTypes, typename... RhsTypes> template<typename... LhsTypes, typename... RhsTypes>
inline bool operator==(cow_tuple<LhsTypes...> const& lhs, inline bool operator==(cow_tuple<LhsTypes...> const& lhs,
cow_tuple<RhsTypes...> const& rhs) cow_tuple<RhsTypes...> const& rhs) {
{
return util::compare_tuples(lhs, rhs); return util::compare_tuples(lhs, rhs);
} }
...@@ -268,8 +251,7 @@ inline bool operator==(cow_tuple<LhsTypes...> const& lhs, ...@@ -268,8 +251,7 @@ inline bool operator==(cow_tuple<LhsTypes...> const& lhs,
*/ */
template<typename... LhsTypes, typename... RhsTypes> template<typename... LhsTypes, typename... RhsTypes>
inline bool operator!=(cow_tuple<LhsTypes...> const& lhs, inline bool operator!=(cow_tuple<LhsTypes...> const& lhs,
cow_tuple<RhsTypes...> const& rhs) cow_tuple<RhsTypes...> const& rhs) {
{
return !(lhs == rhs); return !(lhs == rhs);
} }
......
...@@ -473,8 +473,7 @@ void demonitor(actor_ptr& whom); ...@@ -473,8 +473,7 @@ void demonitor(actor_ptr& whom);
* @brief Spans a new context-switching actor. * @brief Spans a new context-switching actor.
* @returns A pointer to the spawned {@link actor Actor}. * @returns A pointer to the spawned {@link actor Actor}.
*/ */
inline actor_ptr spawn(scheduled_actor* what) inline actor_ptr spawn(scheduled_actor* what) {
{
return get_scheduler()->spawn(what); return get_scheduler()->spawn(what);
} }
...@@ -485,8 +484,7 @@ inline actor_ptr spawn(scheduled_actor* what) ...@@ -485,8 +484,7 @@ inline actor_ptr spawn(scheduled_actor* what)
* @returns A pointer to the spawned {@link actor Actor}. * @returns A pointer to the spawned {@link actor Actor}.
*/ */
template<scheduling_hint Hint> template<scheduling_hint Hint>
inline actor_ptr spawn(std::function<void()> what) inline actor_ptr spawn(std::function<void()> what) {
{
return get_scheduler()->spawn(std::move(what), Hint); return get_scheduler()->spawn(std::move(what), Hint);
} }
...@@ -495,81 +493,42 @@ inline actor_ptr spawn(std::function<void()> what) ...@@ -495,81 +493,42 @@ inline actor_ptr spawn(std::function<void()> what)
* @brief Spans a new event-based actor. * @brief Spans a new event-based actor.
* @returns A pointer to the spawned {@link actor Actor}. * @returns A pointer to the spawned {@link actor Actor}.
*/ */
inline actor_ptr spawn(std::function<void()> what) inline actor_ptr spawn(std::function<void()> what) {
{
return get_scheduler()->spawn(std::move(what), scheduled); return get_scheduler()->spawn(std::move(what), scheduled);
} }
template<typename T> template<typename T>
struct spawn_fwd_ struct spawn_fwd_ {
{
static inline T&& _(T&& arg) { return std::move(arg); } static inline T&& _(T&& arg) { return std::move(arg); }
static inline T& _(T& arg) { return arg; } static inline T& _(T& arg) { return arg; }
static inline T const& _(T const& arg) { return arg; } static inline T const& _(T const& arg) { return arg; }
}; };
template<> template<>
struct spawn_fwd_<self_type> struct spawn_fwd_<self_type> {
{
static inline actor_ptr _(self_type const&) { return self; } static inline actor_ptr _(self_type const&) { return self; }
}; };
template<typename F, typename Arg0, typename... Args> template<typename F, typename Arg0, typename... Args>
inline actor_ptr spawn(F&& what, Arg0&& arg0, Args&&... args) inline actor_ptr spawn(F&& what, Arg0&& arg0, Args&&... args) {
{
return spawn(std::bind(std::move(what), return spawn(std::bind(std::move(what),
spawn_fwd_<typename util::rm_ref<Arg0>::type>::_(arg0), spawn_fwd_<typename util::rm_ref<Arg0>::type>::_(arg0),
spawn_fwd_<typename util::rm_ref<Args>::type>::_(args)...)); spawn_fwd_<typename util::rm_ref<Args>::type>::_(args)...));
} }
template<scheduling_hint Hint, typename F, typename Arg0, typename... Args> template<scheduling_hint Hint, typename F, typename Arg0, typename... Args>
inline actor_ptr spawn(F&& what, Arg0&& arg0, Args&&... args) inline actor_ptr spawn(F&& what, Arg0&& arg0, Args&&... args) {
{
return spawn<Hint>(std::bind(std::move(what), return spawn<Hint>(std::bind(std::move(what),
spawn_fwd_<typename util::rm_ref<Arg0>::type>::_(arg0), spawn_fwd_<typename util::rm_ref<Arg0>::type>::_(arg0),
spawn_fwd_<typename util::rm_ref<Args>::type>::_(args)...)); spawn_fwd_<typename util::rm_ref<Args>::type>::_(args)...));
} }
/* template<typename... Args>
/ ** inline actor_ptr spawn_link(Args&&... args) {
* @ingroup ActorManagement auto aptr = spawn(std::forward<Args>(args)...);
* @brief Spawns a new actor that executes @p what with given arguments. self->link_to(aptr);
* @tparam Hint Hint to the scheduler for the best scheduling strategy. return aptr;
* @param what Function or functor that the spawned Actor should execute.
* @param args Arguments needed to invoke @p what.
* @returns A pointer to the spawned {@link actor actor}.
* /
template<scheduling_hint Hint, typename F, typename... Args>
auto //actor_ptr
spawn(F&& what, Args const&... args)
-> typename std::enable_if<
!std::is_convertible<typename util::rm_ref<F>::type, scheduled_actor*>::value
&& !std::is_convertible<typename util::rm_ref<F>::type, event_based_actor*>::value,
actor_ptr
>::type
{
typedef typename util::rm_ref<F>::type ftype;
std::integral_constant<bool, std::is_function<ftype>::value> is_fun;
auto ptr = detail::get_behavior(is_fun, std::forward<F>(what), args...);
return get_scheduler()->spawn(ptr, Hint);
}
/ **
* @ingroup ActorManagement
* @brief Alias for <tt>spawn<scheduled>(what, args...)</tt>.
* /
template<typename F, typename... Args>
auto // actor_ptr
spawn(F&& what, Args const&... args)
-> typename std::enable_if<
!std::is_convertible<typename util::rm_ref<F>::type, scheduled_actor*>::value
&& !std::is_convertible<typename util::rm_ref<F>::type, event_based_actor*>::value,
actor_ptr
>::type
{
return spawn<scheduled>(std::forward<F>(what), args...);
} }
*/
#ifdef CPPA_DOCUMENTATION #ifdef CPPA_DOCUMENTATION
...@@ -595,15 +554,13 @@ channel_ptr& operator<<(channel_ptr& whom, any_tuple const& what); ...@@ -595,15 +554,13 @@ channel_ptr& operator<<(channel_ptr& whom, any_tuple const& what);
#else #else
template<class C, typename Arg0, typename... Args> template<class C, typename Arg0, typename... Args>
void send(intrusive_ptr<C>& whom, Arg0 const& arg0, Args const&... args) void send(intrusive_ptr<C>& whom, Arg0 const& arg0, Args const&... args) {
{
static_assert(std::is_base_of<channel, C>::value, "C is not a channel"); static_assert(std::is_base_of<channel, C>::value, "C is not a channel");
if (whom) self->send_message(whom.get(), make_cow_tuple(arg0, args...)); if (whom) self->send_message(whom.get(), make_cow_tuple(arg0, args...));
} }
template<class C, typename Arg0, typename... Args> template<class C, typename Arg0, typename... Args>
void send(intrusive_ptr<C>&& whom, Arg0 const& arg0, Args const&... args) void send(intrusive_ptr<C>&& whom, Arg0 const& arg0, Args const&... args) {
{
static_assert(std::is_base_of<channel, C>::value, "C is not a channel"); static_assert(std::is_base_of<channel, C>::value, "C is not a channel");
intrusive_ptr<C> tmp(std::move(whom)); intrusive_ptr<C> tmp(std::move(whom));
send(tmp, arg0, args...); send(tmp, arg0, args...);
...@@ -611,8 +568,7 @@ void send(intrusive_ptr<C>&& whom, Arg0 const& arg0, Args const&... args) ...@@ -611,8 +568,7 @@ void send(intrusive_ptr<C>&& whom, Arg0 const& arg0, Args const&... args)
// matches "send(this, ...)" in event-based actors // matches "send(this, ...)" in event-based actors
template<typename Arg0, typename... Args> template<typename Arg0, typename... Args>
inline void send(local_actor* whom, Arg0 const& arg0, Args const&... args) inline void send(local_actor* whom, Arg0 const& arg0, Args const&... args) {
{
CPPA_REQUIRE(whom != nullptr); CPPA_REQUIRE(whom != nullptr);
whom->enqueue(whom, make_cow_tuple(arg0, args...)); whom->enqueue(whom, make_cow_tuple(arg0, args...));
} }
...@@ -620,8 +576,7 @@ inline void send(local_actor* whom, Arg0 const& arg0, Args const&... args) ...@@ -620,8 +576,7 @@ inline void send(local_actor* whom, Arg0 const& arg0, Args const&... args)
// matches send(self, ...); // matches send(self, ...);
template<typename Arg0, typename... Args> template<typename Arg0, typename... Args>
inline void send(self_type const&, Arg0 const& arg0, Args const&... args) inline void send(self_type const&, Arg0 const& arg0, Args const&... args) {
{
send(static_cast<local_actor*>(self), arg0, args...); send(static_cast<local_actor*>(self), arg0, args...);
} }
...@@ -630,8 +585,7 @@ typename std::enable_if< ...@@ -630,8 +585,7 @@ typename std::enable_if<
std::is_base_of<channel, C>::value, std::is_base_of<channel, C>::value,
intrusive_ptr<C>& intrusive_ptr<C>&
>::type >::type
operator<<(intrusive_ptr<C>& whom, any_tuple const& what) operator<<(intrusive_ptr<C>& whom, any_tuple const& what) {
{
if (whom) self->send_message(whom.get(), what); if (whom) self->send_message(whom.get(), what);
return whom; return whom;
} }
...@@ -641,8 +595,7 @@ typename std::enable_if< ...@@ -641,8 +595,7 @@ typename std::enable_if<
std::is_base_of<channel, C>::value, std::is_base_of<channel, C>::value,
intrusive_ptr<C> intrusive_ptr<C>
>::type >::type
operator<<(intrusive_ptr<C>&& whom, any_tuple const& what) operator<<(intrusive_ptr<C>&& whom, any_tuple const& what) {
{
intrusive_ptr<C> tmp(std::move(whom)); intrusive_ptr<C> tmp(std::move(whom));
tmp << what; tmp << what;
return std::move(tmp); return std::move(tmp);
...@@ -653,8 +606,7 @@ typename std::enable_if< ...@@ -653,8 +606,7 @@ typename std::enable_if<
std::is_base_of<channel, C>::value, std::is_base_of<channel, C>::value,
intrusive_ptr<C>& intrusive_ptr<C>&
>::type >::type
operator<<(intrusive_ptr<C>& whom, any_tuple&& what) operator<<(intrusive_ptr<C>& whom, any_tuple&& what) {
{
if (whom) self->send_message(whom.get(), std::move(what)); if (whom) self->send_message(whom.get(), std::move(what));
return whom; return whom;
} }
...@@ -664,8 +616,7 @@ typename std::enable_if< ...@@ -664,8 +616,7 @@ typename std::enable_if<
std::is_base_of<channel, C>::value, std::is_base_of<channel, C>::value,
intrusive_ptr<C> intrusive_ptr<C>
>::type >::type
operator<<(intrusive_ptr<C>&& whom, any_tuple&& what) operator<<(intrusive_ptr<C>&& whom, any_tuple&& what) {
{
intrusive_ptr<C> tmp(std::move(whom)); intrusive_ptr<C> tmp(std::move(whom));
tmp << std::move(what); tmp << std::move(what);
return std::move(tmp); return std::move(tmp);
...@@ -682,8 +633,7 @@ self_type const& operator<<(self_type const& s, any_tuple&& what); ...@@ -682,8 +633,7 @@ self_type const& operator<<(self_type const& s, any_tuple&& what);
* @brief Sends a message to the sender of the last received message. * @brief Sends a message to the sender of the last received message.
*/ */
template<typename Arg0, typename... Args> template<typename Arg0, typename... Args>
void reply(Arg0 const& arg0, Args const&... args) void reply(Arg0 const& arg0, Args const&... args) {
{
send(self->last_sender(), arg0, args...); send(self->last_sender(), arg0, args...);
} }
...@@ -695,8 +645,7 @@ void reply(Arg0 const& arg0, Args const&... args) ...@@ -695,8 +645,7 @@ void reply(Arg0 const& arg0, Args const&... args)
* @param data Any number of values for the message content. * @param data Any number of values for the message content.
*/ */
template<typename Duration, typename... Data> template<typename Duration, typename... Data>
void future_send(actor_ptr whom, Duration const& rel_time, Data const&... data) void future_send(actor_ptr whom, Duration const& rel_time, Data const&... data) {
{
get_scheduler()->future_send(whom, rel_time, data...); get_scheduler()->future_send(whom, rel_time, data...);
} }
...@@ -706,8 +655,7 @@ void future_send(actor_ptr whom, Duration const& rel_time, Data const&... data) ...@@ -706,8 +655,7 @@ void future_send(actor_ptr whom, Duration const& rel_time, Data const&... data)
* @see future_send() * @see future_send()
*/ */
template<typename Duration, typename... Data> template<typename Duration, typename... Data>
void delayed_reply(Duration const& rel_time, Data const... data) void delayed_reply(Duration const& rel_time, Data const... data) {
{
future_send(self->last_sender(), rel_time, data...); future_send(self->last_sender(), rel_time, data...);
} }
...@@ -717,8 +665,7 @@ void delayed_reply(Duration const& rel_time, Data const... data) ...@@ -717,8 +665,7 @@ void delayed_reply(Duration const& rel_time, Data const... data)
* @warning This function will cause a deadlock if * @warning This function will cause a deadlock if
* called from multiple actors. * called from multiple actors.
*/ */
inline void await_all_others_done() inline void await_all_others_done() {
{
detail::actor_count_wait_until((self.unchecked() == nullptr) ? 0 : 1); detail::actor_count_wait_until((self.unchecked() == nullptr) ? 0 : 1);
} }
......
...@@ -45,8 +45,7 @@ class object; ...@@ -45,8 +45,7 @@ class object;
* @ingroup TypeSystem * @ingroup TypeSystem
* @brief Technology-independent deserialization interface. * @brief Technology-independent deserialization interface.
*/ */
class deserializer class deserializer {
{
deserializer(deserializer const&) = delete; deserializer(deserializer const&) = delete;
deserializer& operator=(deserializer const&) = delete; deserializer& operator=(deserializer const&) = delete;
......
...@@ -50,8 +50,7 @@ ...@@ -50,8 +50,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
// A spawned, scheduled Actor. // A spawned, scheduled Actor.
class abstract_scheduled_actor : public abstract_actor<scheduled_actor> class abstract_scheduled_actor : public abstract_actor<scheduled_actor> {
{
typedef abstract_actor<scheduled_actor> super; typedef abstract_actor<scheduled_actor> super;
...@@ -59,28 +58,22 @@ class abstract_scheduled_actor : public abstract_actor<scheduled_actor> ...@@ -59,28 +58,22 @@ class abstract_scheduled_actor : public abstract_actor<scheduled_actor>
std::atomic<int> m_state; std::atomic<int> m_state;
filter_result filter_msg(any_tuple const& msg) filter_result filter_msg(any_tuple const& msg) {
{
auto& arr = detail::static_types_array<atom_value, std::uint32_t>::arr; auto& arr = detail::static_types_array<atom_value, std::uint32_t>::arr;
if ( msg.size() == 2 if ( msg.size() == 2
&& msg.type_at(0) == arr[0] && msg.type_at(0) == arr[0]
&& msg.type_at(1) == arr[1]) && msg.type_at(1) == arr[1]) {
{
auto v0 = *reinterpret_cast<const atom_value*>(msg.at(0)); auto v0 = *reinterpret_cast<const atom_value*>(msg.at(0));
auto v1 = *reinterpret_cast<const std::uint32_t*>(msg.at(1)); auto v1 = *reinterpret_cast<const std::uint32_t*>(msg.at(1));
if (v0 == atom("EXIT")) if (v0 == atom("EXIT")) {
{ if (this->m_trap_exit == false) {
if (this->m_trap_exit == false) if (v1 != exit_reason::normal) {
{
if (v1 != exit_reason::normal)
{
quit(v1); quit(v1);
} }
return normal_exit_signal; return normal_exit_signal;
} }
} }
else if (v0 == atom(":Timeout")) else if (v0 == atom(":Timeout")) {
{
return (v1 == m_active_timeout_id) ? timeout_message return (v1 == m_active_timeout_id) ? timeout_message
: expired_timeout_message; : expired_timeout_message;
} }
...@@ -88,24 +81,19 @@ class abstract_scheduled_actor : public abstract_actor<scheduled_actor> ...@@ -88,24 +81,19 @@ class abstract_scheduled_actor : public abstract_actor<scheduled_actor>
return ordinary_message; return ordinary_message;
} }
bool has_pending_timeout() bool has_pending_timeout() {
{
return m_has_pending_timeout_request; return m_has_pending_timeout_request;
} }
void request_timeout(util::duration const& d) void request_timeout(util::duration const& d) {
{ if (d.valid()) {
if (d.valid())
{
get_scheduler()->future_send(this, d, atom(":Timeout"), ++m_active_timeout_id); get_scheduler()->future_send(this, d, atom(":Timeout"), ++m_active_timeout_id);
m_has_pending_timeout_request = true; m_has_pending_timeout_request = true;
} }
} }
void reset_timeout() void reset_timeout() {
{ if (m_has_pending_timeout_request) {
if (m_has_pending_timeout_request)
{
++m_active_timeout_id; ++m_active_timeout_id;
m_has_pending_timeout_request = false; m_has_pending_timeout_request = false;
} }
...@@ -125,33 +113,26 @@ class abstract_scheduled_actor : public abstract_actor<scheduled_actor> ...@@ -125,33 +113,26 @@ class abstract_scheduled_actor : public abstract_actor<scheduled_actor>
abstract_scheduled_actor(int state = done) abstract_scheduled_actor(int state = done)
: super(true), m_state(state) : super(true), m_state(state)
, m_has_pending_timeout_request(false) , m_has_pending_timeout_request(false)
, m_active_timeout_id(0) , m_active_timeout_id(0) {
{
} }
bool pending_enqueue(actor* sender, any_tuple msg) bool pending_enqueue(actor* sender, any_tuple msg) {
{
return enqueue_node(super::fetch_node(sender, std::move(msg)), pending); return enqueue_node(super::fetch_node(sender, std::move(msg)), pending);
} }
void quit(std::uint32_t reason) void quit(std::uint32_t reason) {
{
this->cleanup(reason); this->cleanup(reason);
throw actor_exited(reason); throw actor_exited(reason);
} }
void enqueue(actor* sender, any_tuple msg) void enqueue(actor* sender, any_tuple msg) {
{
enqueue_node(super::fetch_node(sender, std::move(msg))); enqueue_node(super::fetch_node(sender, std::move(msg)));
} }
int compare_exchange_state(int expected, int new_value) int compare_exchange_state(int expected, int new_value) {
{
int e = expected; int e = expected;
do do {
{ if (m_state.compare_exchange_weak(e, new_value)) {
if (m_state.compare_exchange_weak(e, new_value))
{
return new_value; return new_value;
} }
} }
...@@ -162,33 +143,24 @@ class abstract_scheduled_actor : public abstract_actor<scheduled_actor> ...@@ -162,33 +143,24 @@ class abstract_scheduled_actor : public abstract_actor<scheduled_actor>
private: private:
bool enqueue_node(typename super::mailbox_element* node, bool enqueue_node(typename super::mailbox_element* node,
int target_state = ready) int target_state = ready) {
{
CPPA_REQUIRE(node->marked == false); CPPA_REQUIRE(node->marked == false);
if (this->m_mailbox._push_back(node)) if (this->m_mailbox._push_back(node)) {
{ for (;;) {
for (;;)
{
int state = m_state.load(); int state = m_state.load();
switch (state) switch (state) {
{ case blocked: {
case blocked: if (m_state.compare_exchange_weak(state, target_state)) {
{
if (m_state.compare_exchange_weak(state, target_state))
{
CPPA_REQUIRE(this->m_scheduler != nullptr); CPPA_REQUIRE(this->m_scheduler != nullptr);
if (target_state == ready) if (target_state == ready) {
{
this->m_scheduler->enqueue(this); this->m_scheduler->enqueue(this);
} }
return true; return true;
} }
break; break;
} }
case about_to_block: case about_to_block: {
{ if (m_state.compare_exchange_weak(state, ready)) {
if (m_state.compare_exchange_weak(state, ready))
{
return false; return false;
} }
break; break;
......
...@@ -44,14 +44,12 @@ ...@@ -44,14 +44,12 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
enum tuple_impl_info enum tuple_impl_info {
{
statically_typed, statically_typed,
dynamically_typed dynamically_typed
}; };
class abstract_tuple : public ref_counted class abstract_tuple : public ref_counted {
{
tuple_impl_info m_impl_type; tuple_impl_info m_impl_type;
...@@ -97,31 +95,26 @@ class abstract_tuple : public ref_counted ...@@ -97,31 +95,26 @@ class abstract_tuple : public ref_counted
}; };
struct full_eq_type struct full_eq_type {
{
constexpr full_eq_type() { } constexpr full_eq_type() { }
template<class Tuple> template<class Tuple>
inline bool operator()(tuple_iterator<Tuple> const& lhs, inline bool operator()(tuple_iterator<Tuple> const& lhs,
tuple_iterator<Tuple> const& rhs) const tuple_iterator<Tuple> const& rhs) const {
{
return lhs.type() == rhs.type() return lhs.type() == rhs.type()
&& lhs.type()->equals(lhs.value(), rhs.value()); && lhs.type()->equals(lhs.value(), rhs.value());
} }
}; };
struct types_only_eq_type struct types_only_eq_type {
{
constexpr types_only_eq_type() { } constexpr types_only_eq_type() { }
template<class Tuple> template<class Tuple>
inline bool operator()(tuple_iterator<Tuple> const& lhs, inline bool operator()(tuple_iterator<Tuple> const& lhs,
uniform_type_info const* rhs ) const uniform_type_info const* rhs ) const {
{
return lhs.type() == rhs; return lhs.type() == rhs;
} }
template<class Tuple> template<class Tuple>
inline bool operator()(uniform_type_info const* lhs, inline bool operator()(uniform_type_info const* lhs,
tuple_iterator<Tuple> const& rhs) const tuple_iterator<Tuple> const& rhs) const {
{
return lhs == rhs.type(); return lhs == rhs.type();
} }
}; };
......
...@@ -45,8 +45,7 @@ ...@@ -45,8 +45,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
class actor_proxy_cache class actor_proxy_cache {
{
public: public:
...@@ -59,19 +58,15 @@ class actor_proxy_cache ...@@ -59,19 +58,15 @@ class actor_proxy_cache
template<typename Fun> template<typename Fun>
void erase_all(process_information::node_id_type const& nid, void erase_all(process_information::node_id_type const& nid,
std::uint32_t process_id, std::uint32_t process_id,
Fun fun) Fun fun) {
{
key_tuple lb{nid, process_id, std::numeric_limits<actor_id>::min()}; key_tuple lb{nid, process_id, std::numeric_limits<actor_id>::min()};
key_tuple ub{nid, process_id, std::numeric_limits<actor_id>::max()}; key_tuple ub{nid, process_id, std::numeric_limits<actor_id>::max()}; {
{
lock_guard<util::shared_spinlock> guard{m_lock}; lock_guard<util::shared_spinlock> guard{m_lock};
auto e = m_entries.end(); auto e = m_entries.end();
auto first = m_entries.lower_bound(lb); auto first = m_entries.lower_bound(lb);
if (first != e) if (first != e) {
{
auto last = m_entries.upper_bound(ub); auto last = m_entries.upper_bound(ub);
for (auto i = first; i != last; ++i) for (auto i = first; i != last; ++i) {
{
fun(i->second); fun(i->second);
} }
m_entries.erase(first, last); m_entries.erase(first, last);
...@@ -86,8 +81,7 @@ class actor_proxy_cache ...@@ -86,8 +81,7 @@ class actor_proxy_cache
actor_id> // (remote) actor id actor_id> // (remote) actor id
key_tuple; key_tuple;
struct key_tuple_less struct key_tuple_less {
{
bool operator()(key_tuple const& lhs, key_tuple const& rhs) const; bool operator()(key_tuple const& lhs, key_tuple const& rhs) const;
}; };
......
...@@ -42,8 +42,7 @@ ...@@ -42,8 +42,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
class actor_registry class actor_registry {
{
public: public:
......
...@@ -40,8 +40,7 @@ ...@@ -40,8 +40,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
class addressed_message class addressed_message {
{
public: public:
...@@ -53,38 +52,31 @@ class addressed_message ...@@ -53,38 +52,31 @@ class addressed_message
addressed_message& operator=(addressed_message&&) = default; addressed_message& operator=(addressed_message&&) = default;
addressed_message& operator=(addressed_message const&) = default; addressed_message& operator=(addressed_message const&) = default;
inline actor_ptr& sender() inline actor_ptr& sender() {
{
return m_sender; return m_sender;
} }
inline actor_ptr const& sender() const inline actor_ptr const& sender() const {
{
return m_sender; return m_sender;
} }
inline channel_ptr& receiver() inline channel_ptr& receiver() {
{
return m_receiver; return m_receiver;
} }
inline channel_ptr const& receiver() const inline channel_ptr const& receiver() const {
{
return m_receiver; return m_receiver;
} }
inline any_tuple& content() inline any_tuple& content() {
{
return m_content; return m_content;
} }
inline any_tuple const& content() const inline any_tuple const& content() const {
{
return m_content; return m_content;
} }
inline bool empty() const inline bool empty() const {
{
return m_content.empty(); return m_content.empty();
} }
...@@ -98,8 +90,7 @@ class addressed_message ...@@ -98,8 +90,7 @@ class addressed_message
bool operator==(addressed_message const& lhs, addressed_message const& rhs); bool operator==(addressed_message const& lhs, addressed_message const& rhs);
inline bool operator!=(addressed_message const& lhs, addressed_message const& rhs) inline bool operator!=(addressed_message const& lhs, addressed_message const& rhs) {
{
return !(lhs == rhs); return !(lhs == rhs);
} }
......
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
namespace cppa { namespace detail { namespace { namespace cppa { namespace detail { namespace {
// encodes ASCII characters to 6bit encoding // encodes ASCII characters to 6bit encoding
constexpr char encoding_table[] = constexpr char encoding_table[] = {
{
/* ..0 ..1 ..2 ..3 ..4 ..5 ..6 ..7 ..8 ..9 ..A ..B ..C ..D ..E ..F */ /* ..0 ..1 ..2 ..3 ..4 ..5 ..6 ..7 ..8 ..9 ..A ..B ..C ..D ..E ..F */
/* 0.. */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0.. */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
/* 1.. */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1.. */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
...@@ -52,13 +51,11 @@ constexpr char decoding_table[] = " 0123456789" ...@@ -52,13 +51,11 @@ constexpr char decoding_table[] = " 0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ_" "ABCDEFGHIJKLMNOPQRSTUVWXYZ_"
"abcdefghijklmnopqrstuvwxyz"; "abcdefghijklmnopqrstuvwxyz";
constexpr std::uint64_t next_interim(std::uint64_t current, size_t char_code) constexpr std::uint64_t next_interim(std::uint64_t current, size_t char_code) {
{
return (current << 6) | encoding_table[(char_code <= 0x7F) ? char_code : 0]; return (current << 6) | encoding_table[(char_code <= 0x7F) ? char_code : 0];
} }
constexpr std::uint64_t atom_val(char const* cstr, std::uint64_t interim = 0) constexpr std::uint64_t atom_val(char const* cstr, std::uint64_t interim = 0) {
{
return (*cstr == '\0') ? interim return (*cstr == '\0') ? interim
: atom_val(cstr + 1, : atom_val(cstr + 1,
next_interim(interim, next_interim(interim,
......
...@@ -37,50 +37,42 @@ ...@@ -37,50 +37,42 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
template<typename T> template<typename T>
struct boxed struct boxed {
{
typedef util::wrapped<T> type; typedef util::wrapped<T> type;
}; };
template<typename T> template<typename T>
struct boxed< util::wrapped<T> > struct boxed< util::wrapped<T> > {
{
typedef util::wrapped<T> type; typedef util::wrapped<T> type;
}; };
template<> template<>
struct boxed<anything> struct boxed<anything> {
{
typedef anything type; typedef anything type;
}; };
template<typename T> template<typename T>
struct is_boxed struct is_boxed {
{
static constexpr bool value = false; static constexpr bool value = false;
}; };
template<typename T> template<typename T>
struct is_boxed< util::wrapped<T> > struct is_boxed< util::wrapped<T> > {
{
static constexpr bool value = true; static constexpr bool value = true;
}; };
template<typename T> template<typename T>
struct is_boxed<util::wrapped<T>()> struct is_boxed<util::wrapped<T>()> {
{
static constexpr bool value = true; static constexpr bool value = true;
}; };
template<typename T> template<typename T>
struct is_boxed<util::wrapped<T>(&)()> struct is_boxed<util::wrapped<T>(&)()> {
{
static constexpr bool value = true; static constexpr bool value = true;
}; };
template<typename T> template<typename T>
struct is_boxed<util::wrapped<T>(*)()> struct is_boxed<util::wrapped<T>(*)()> {
{
static constexpr bool value = true; static constexpr bool value = true;
}; };
......
...@@ -41,8 +41,7 @@ ...@@ -41,8 +41,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
template<size_t ChunkSize, size_t MaxBufferSize, typename DataType = char> template<size_t ChunkSize, size_t MaxBufferSize, typename DataType = char>
class buffer class buffer {
{
DataType* m_data; DataType* m_data;
size_t m_written; size_t m_written;
...@@ -50,33 +49,25 @@ class buffer ...@@ -50,33 +49,25 @@ class buffer
size_t m_final_size; size_t m_final_size;
template<typename F> template<typename F>
bool append_impl(F&& fun, bool throw_on_error) bool append_impl(F&& fun, bool throw_on_error) {
{
auto recv_result = fun(); auto recv_result = fun();
if (recv_result == 0) if (recv_result == 0) {
{
// connection closed // connection closed
if (throw_on_error) if (throw_on_error) {
{
std::ios_base::failure("cannot read from a closed pipe/socket"); std::ios_base::failure("cannot read from a closed pipe/socket");
} }
return false; return false;
} }
else if (recv_result < 0) else if (recv_result < 0) {
{ switch (errno) {
switch (errno) case EAGAIN: {
{
case EAGAIN:
{
// rdflags or sfd is set to non-blocking, // rdflags or sfd is set to non-blocking,
// this is not treated as error // this is not treated as error
return true; return true;
} }
default: default: {
{
// a "real" error occured; // a "real" error occured;
if (throw_on_error) if (throw_on_error) {
{
char* cstr = strerror(errno); char* cstr = strerror(errno);
std::string errmsg = cstr; std::string errmsg = cstr;
free(cstr); free(cstr);
...@@ -92,45 +83,36 @@ class buffer ...@@ -92,45 +83,36 @@ class buffer
public: public:
buffer() : m_data(nullptr), m_written(0), m_allocated(0), m_final_size(0) buffer() : m_data(nullptr), m_written(0), m_allocated(0), m_final_size(0) {
{
} }
buffer(buffer&& other) buffer(buffer&& other)
: m_data(other.m_data), m_written(other.m_written) : m_data(other.m_data), m_written(other.m_written)
, m_allocated(other.m_allocated), m_final_size(other.m_final_size) , m_allocated(other.m_allocated), m_final_size(other.m_final_size) {
{
other.m_data = nullptr; other.m_data = nullptr;
other.m_written = other.m_allocated = other.m_final_size = 0; other.m_written = other.m_allocated = other.m_final_size = 0;
} }
~buffer() ~buffer() {
{
delete[] m_data; delete[] m_data;
} }
void clear() void clear() {
{
m_written = 0; m_written = 0;
} }
void reset(size_t new_final_size = 0) void reset(size_t new_final_size = 0) {
{
m_written = 0; m_written = 0;
m_final_size = new_final_size; m_final_size = new_final_size;
if (new_final_size > m_allocated) if (new_final_size > m_allocated) {
{ if (new_final_size > MaxBufferSize) {
if (new_final_size > MaxBufferSize)
{
throw std::ios_base::failure("maximum buffer size exceeded"); throw std::ios_base::failure("maximum buffer size exceeded");
} }
auto remainder = (new_final_size % ChunkSize); auto remainder = (new_final_size % ChunkSize);
if (remainder == 0) if (remainder == 0) {
{
m_allocated = new_final_size; m_allocated = new_final_size;
} }
else else {
{
m_allocated = (new_final_size - remainder) + ChunkSize; m_allocated = (new_final_size - remainder) + ChunkSize;
} }
delete[] m_data; delete[] m_data;
...@@ -138,51 +120,41 @@ class buffer ...@@ -138,51 +120,41 @@ class buffer
} }
} }
bool ready() bool ready() {
{
return m_written == m_final_size; return m_written == m_final_size;
} }
// pointer to the current write position // pointer to the current write position
DataType* wr_ptr() DataType* wr_ptr() {
{
return m_data + m_written; return m_data + m_written;
} }
size_t size() size_t size() {
{
return m_written; return m_written;
} }
size_t final_size() size_t final_size() {
{
return m_final_size; return m_final_size;
} }
size_t remaining() size_t remaining() {
{
return m_final_size - m_written; return m_final_size - m_written;
} }
void inc_written(size_t value) void inc_written(size_t value) {
{
m_written += value; m_written += value;
} }
DataType* data() DataType* data() {
{
return m_data; return m_data;
} }
inline bool full() inline bool full() {
{
return remaining() == 0; return remaining() == 0;
} }
bool append_from_file_descriptor(int fd, bool throw_on_error = false) bool append_from_file_descriptor(int fd, bool throw_on_error = false) {
{ auto fun = [=]() -> int {
auto fun = [=]() -> int
{
return ::read(fd, this->wr_ptr(), this->remaining()); return ::read(fd, this->wr_ptr(), this->remaining());
}; };
return append_impl(fun, throw_on_error); return append_impl(fun, throw_on_error);
...@@ -190,10 +162,8 @@ class buffer ...@@ -190,10 +162,8 @@ class buffer
bool append_from(native_socket_type sfd, bool append_from(native_socket_type sfd,
int rdflags = 0, int rdflags = 0,
bool throw_on_error = false) bool throw_on_error = false) {
{ auto fun = [=]() -> int {
auto fun = [=]() -> int
{
return ::recv(sfd, this->wr_ptr(), this->remaining(), rdflags); return ::recv(sfd, this->wr_ptr(), this->remaining(), rdflags);
}; };
return append_impl(fun, throw_on_error); return append_impl(fun, throw_on_error);
......
...@@ -38,8 +38,7 @@ namespace cppa { class message; } ...@@ -38,8 +38,7 @@ namespace cppa { class message; }
namespace cppa { namespace detail { namespace cppa { namespace detail {
// public part of the actor interface // public part of the actor interface
struct channel : ref_counted struct channel : ref_counted {
{
virtual void enqueue_msg(message const& msg) = 0; virtual void enqueue_msg(message const& msg) = 0;
}; };
......
...@@ -41,8 +41,7 @@ ...@@ -41,8 +41,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
template<class Container> template<class Container>
class container_tuple_view : public abstract_tuple class container_tuple_view : public abstract_tuple {
{
typedef abstract_tuple super; typedef abstract_tuple super;
...@@ -51,40 +50,34 @@ class container_tuple_view : public abstract_tuple ...@@ -51,40 +50,34 @@ class container_tuple_view : public abstract_tuple
typedef typename Container::value_type value_type; typedef typename Container::value_type value_type;
container_tuple_view(Container* c, bool take_ownership = false) container_tuple_view(Container* c, bool take_ownership = false)
: super(tuple_impl_info::dynamically_typed), m_ptr(c) : super(tuple_impl_info::dynamically_typed), m_ptr(c) {
{
CPPA_REQUIRE(c != nullptr); CPPA_REQUIRE(c != nullptr);
if (!take_ownership) m_ptr.get_deleter().disable(); if (!take_ownership) m_ptr.get_deleter().disable();
} }
size_t size() const size_t size() const {
{
return m_ptr->size(); return m_ptr->size();
} }
abstract_tuple* copy() const abstract_tuple* copy() const {
{
return new container_tuple_view{new Container(*m_ptr), true}; return new container_tuple_view{new Container(*m_ptr), true};
} }
void const* at(size_t pos) const void const* at(size_t pos) const {
{
CPPA_REQUIRE(pos < size()); CPPA_REQUIRE(pos < size());
auto i = m_ptr->begin(); auto i = m_ptr->begin();
std::advance(i, pos); std::advance(i, pos);
return &(*i); return &(*i);
} }
void* mutable_at(size_t pos) void* mutable_at(size_t pos) {
{
CPPA_REQUIRE(pos < size()); CPPA_REQUIRE(pos < size());
auto i = m_ptr->begin(); auto i = m_ptr->begin();
std::advance(i, pos); std::advance(i, pos);
return &(*i); return &(*i);
} }
uniform_type_info const* type_at(size_t) const uniform_type_info const* type_at(size_t) const {
{
return static_types_array<value_type>::arr[0]; return static_types_array<value_type>::arr[0];
} }
......
...@@ -58,8 +58,7 @@ namespace cppa { namespace detail { ...@@ -58,8 +58,7 @@ namespace cppa { namespace detail {
*/ */
class converted_thread_context class converted_thread_context
: public nestable_receive_actor<converted_thread_context, : public nestable_receive_actor<converted_thread_context,
abstract_actor<local_actor> > abstract_actor<local_actor> > {
{
typedef nestable_receive_actor<converted_thread_context, typedef nestable_receive_actor<converted_thread_context,
abstract_actor<local_actor> > abstract_actor<local_actor> >
......
...@@ -50,8 +50,7 @@ ...@@ -50,8 +50,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
template<typename... ElementTypes> template<typename... ElementTypes>
class decorated_tuple : public abstract_tuple class decorated_tuple : public abstract_tuple {
{
typedef abstract_tuple super; typedef abstract_tuple super;
...@@ -65,47 +64,39 @@ class decorated_tuple : public abstract_tuple ...@@ -65,47 +64,39 @@ class decorated_tuple : public abstract_tuple
typedef cow_ptr<abstract_tuple> cow_pointer_type; typedef cow_ptr<abstract_tuple> cow_pointer_type;
static inline cow_pointer_type create(cow_pointer_type d, static inline cow_pointer_type create(cow_pointer_type d,
vector_type const& v) vector_type const& v) {
{
return cow_pointer_type{new decorated_tuple(std::move(d), v)}; return cow_pointer_type{new decorated_tuple(std::move(d), v)};
} }
// creates a subtuple form @p d with an offset // creates a subtuple form @p d with an offset
static inline cow_pointer_type create(cow_pointer_type d, size_t offset) static inline cow_pointer_type create(cow_pointer_type d, size_t offset) {
{
return cow_pointer_type{new decorated_tuple(std::move(d), offset)}; return cow_pointer_type{new decorated_tuple(std::move(d), offset)};
} }
virtual void* mutable_at(size_t pos) virtual void* mutable_at(size_t pos) {
{
CPPA_REQUIRE(pos < size()); CPPA_REQUIRE(pos < size());
return m_decorated->mutable_at(m_mapping[pos]); return m_decorated->mutable_at(m_mapping[pos]);
} }
virtual size_t size() const virtual size_t size() const {
{
return sizeof...(ElementTypes); return sizeof...(ElementTypes);
} }
virtual decorated_tuple* copy() const virtual decorated_tuple* copy() const {
{
return new decorated_tuple(*this); return new decorated_tuple(*this);
} }
virtual void const* at(size_t pos) const virtual void const* at(size_t pos) const {
{
CPPA_REQUIRE(pos < size()); CPPA_REQUIRE(pos < size());
return m_decorated->at(m_mapping[pos]); return m_decorated->at(m_mapping[pos]);
} }
virtual uniform_type_info const* type_at(size_t pos) const virtual uniform_type_info const* type_at(size_t pos) const {
{
CPPA_REQUIRE(pos < size()); CPPA_REQUIRE(pos < size());
return m_decorated->type_at(m_mapping[pos]); return m_decorated->type_at(m_mapping[pos]);
} }
std::type_info const* type_token() const std::type_info const* type_token() const {
{
return static_type_list<ElementTypes...>::list; return static_type_list<ElementTypes...>::list;
} }
...@@ -116,8 +107,7 @@ class decorated_tuple : public abstract_tuple ...@@ -116,8 +107,7 @@ class decorated_tuple : public abstract_tuple
decorated_tuple(cow_pointer_type d, vector_type const& v) decorated_tuple(cow_pointer_type d, vector_type const& v)
: super(tuple_impl_info::statically_typed) : super(tuple_impl_info::statically_typed)
, m_decorated(std::move(d)), m_mapping(v) , m_decorated(std::move(d)), m_mapping(v) {
{
# ifdef CPPA_DEBUG # ifdef CPPA_DEBUG
cow_pointer_type const& ptr = m_decorated; // prevent detaching cow_pointer_type const& ptr = m_decorated; // prevent detaching
# endif # endif
...@@ -127,8 +117,7 @@ class decorated_tuple : public abstract_tuple ...@@ -127,8 +117,7 @@ class decorated_tuple : public abstract_tuple
} }
decorated_tuple(cow_pointer_type d, size_t offset) decorated_tuple(cow_pointer_type d, size_t offset)
: super(tuple_impl_info::statically_typed), m_decorated(std::move(d)) : super(tuple_impl_info::statically_typed), m_decorated(std::move(d)) {
{
# ifdef CPPA_DEBUG # ifdef CPPA_DEBUG
cow_pointer_type const& ptr = m_decorated; // prevent detaching cow_pointer_type const& ptr = m_decorated; // prevent detaching
# endif # endif
...@@ -149,8 +138,7 @@ template<typename TypeList> ...@@ -149,8 +138,7 @@ template<typename TypeList>
struct decorated_cow_tuple_from_type_list; struct decorated_cow_tuple_from_type_list;
template<typename... Types> template<typename... Types>
struct decorated_cow_tuple_from_type_list< util::type_list<Types...> > struct decorated_cow_tuple_from_type_list< util::type_list<Types...> > {
{
typedef decorated_tuple<Types...> type; typedef decorated_tuple<Types...> type;
}; };
......
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
template<typename T> template<typename T>
class disablable_delete class disablable_delete {
{
bool m_enabled; bool m_enabled;
...@@ -45,8 +44,7 @@ class disablable_delete ...@@ -45,8 +44,7 @@ class disablable_delete
inline void disable() { m_enabled = false; } inline void disable() { m_enabled = false; }
inline void operator()(T* ptr) inline void operator()(T* ptr) {
{
if (m_enabled) delete ptr; if (m_enabled) delete ptr;
} }
......
...@@ -35,8 +35,7 @@ ...@@ -35,8 +35,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
struct empty_tuple : abstract_tuple struct empty_tuple : abstract_tuple {
{
using abstract_tuple::const_iterator; using abstract_tuple::const_iterator;
......
...@@ -33,8 +33,7 @@ ...@@ -33,8 +33,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
enum filter_result enum filter_result {
{
normal_exit_signal, normal_exit_signal,
expired_timeout_message, expired_timeout_message,
timeout_message, timeout_message,
......
...@@ -43,8 +43,7 @@ namespace cppa { namespace detail { ...@@ -43,8 +43,7 @@ namespace cppa { namespace detail {
// default: <true, false, F> // default: <true, false, F>
template<bool IsFunctionPtr, bool HasArguments, typename F, typename... Args> template<bool IsFunctionPtr, bool HasArguments, typename F, typename... Args>
class ftor_behavior : public scheduled_actor class ftor_behavior : public scheduled_actor {
{
F m_fun; F m_fun;
...@@ -57,8 +56,7 @@ class ftor_behavior : public scheduled_actor ...@@ -57,8 +56,7 @@ class ftor_behavior : public scheduled_actor
}; };
template<typename F, typename... Args> template<typename F, typename... Args>
class ftor_behavior<true, true, F, Args...> : public scheduled_actor class ftor_behavior<true, true, F, Args...> : public scheduled_actor {
{
static_assert(sizeof...(Args) > 0, "sizeof...(Args) == 0"); static_assert(sizeof...(Args) > 0, "sizeof...(Args) == 0");
...@@ -80,8 +78,7 @@ class ftor_behavior<true, true, F, Args...> : public scheduled_actor ...@@ -80,8 +78,7 @@ class ftor_behavior<true, true, F, Args...> : public scheduled_actor
}; };
template<typename F> template<typename F>
class ftor_behavior<false, false, F> : public scheduled_actor class ftor_behavior<false, false, F> : public scheduled_actor {
{
F m_fun; F m_fun;
...@@ -96,8 +93,7 @@ class ftor_behavior<false, false, F> : public scheduled_actor ...@@ -96,8 +93,7 @@ class ftor_behavior<false, false, F> : public scheduled_actor
}; };
template<typename F, typename... Args> template<typename F, typename... Args>
class ftor_behavior<false, true, F, Args...> : public scheduled_actor class ftor_behavior<false, true, F, Args...> : public scheduled_actor {
{
static_assert(sizeof...(Args) > 0, "sizeof...(Args) == 0"); static_assert(sizeof...(Args) > 0, "sizeof...(Args) == 0");
...@@ -112,13 +108,11 @@ class ftor_behavior<false, true, F, Args...> : public scheduled_actor ...@@ -112,13 +108,11 @@ class ftor_behavior<false, true, F, Args...> : public scheduled_actor
public: public:
ftor_behavior(F const& f, Args const&... args) : m_fun(f), m_args(args...) ftor_behavior(F const& f, Args const&... args) : m_fun(f), m_args(args...) {
{
} }
ftor_behavior(F&& f,Args const&... args) : m_fun(std::move(f)) ftor_behavior(F&& f,Args const&... args) : m_fun(std::move(f))
, m_args(args...) , m_args(args...) {
{
} }
virtual void act() { util::apply_tuple(m_fun, m_args); } virtual void act() { util::apply_tuple(m_fun, m_args); }
...@@ -126,8 +120,7 @@ class ftor_behavior<false, true, F, Args...> : public scheduled_actor ...@@ -126,8 +120,7 @@ class ftor_behavior<false, true, F, Args...> : public scheduled_actor
}; };
template<typename R> template<typename R>
scheduled_actor* get_behavior(std::integral_constant<bool,true>, R (*fptr)()) scheduled_actor* get_behavior(std::integral_constant<bool,true>, R (*fptr)()) {
{
static_assert(std::is_convertible<R, scheduled_actor*>::value == false, static_assert(std::is_convertible<R, scheduled_actor*>::value == false,
"Spawning a function returning an actor_behavior? " "Spawning a function returning an actor_behavior? "
"Are you sure that you do not want to spawn the behavior " "Are you sure that you do not want to spawn the behavior "
...@@ -136,8 +129,7 @@ scheduled_actor* get_behavior(std::integral_constant<bool,true>, R (*fptr)()) ...@@ -136,8 +129,7 @@ scheduled_actor* get_behavior(std::integral_constant<bool,true>, R (*fptr)())
} }
template<typename F> template<typename F>
scheduled_actor* get_behavior(std::integral_constant<bool,false>, F&& ftor) scheduled_actor* get_behavior(std::integral_constant<bool,false>, F&& ftor) {
{
static_assert(std::is_convertible<decltype(ftor()), scheduled_actor*>::value == false, static_assert(std::is_convertible<decltype(ftor()), scheduled_actor*>::value == false,
"Spawning a functor returning an actor_behavior? " "Spawning a functor returning an actor_behavior? "
"Are you sure that you do not want to spawn the behavior " "Are you sure that you do not want to spawn the behavior "
...@@ -150,8 +142,7 @@ template<typename F, typename Arg0, typename... Args> ...@@ -150,8 +142,7 @@ template<typename F, typename Arg0, typename... Args>
scheduled_actor* get_behavior(std::integral_constant<bool,true>, scheduled_actor* get_behavior(std::integral_constant<bool,true>,
F fptr, F fptr,
Arg0 const& arg0, Arg0 const& arg0,
Args const&... args) Args const&... args) {
{
static_assert(std::is_convertible<decltype(fptr(arg0, args...)), scheduled_actor*>::value == false, static_assert(std::is_convertible<decltype(fptr(arg0, args...)), scheduled_actor*>::value == false,
"Spawning a function returning an actor_behavior? " "Spawning a function returning an actor_behavior? "
"Are you sure that you do not want to spawn the behavior " "Are you sure that you do not want to spawn the behavior "
...@@ -164,8 +155,7 @@ template<typename F, typename Arg0, typename... Args> ...@@ -164,8 +155,7 @@ template<typename F, typename Arg0, typename... Args>
scheduled_actor* get_behavior(std::integral_constant<bool,false>, scheduled_actor* get_behavior(std::integral_constant<bool,false>,
F ftor, F ftor,
Arg0 const& arg0, Arg0 const& arg0,
Args const&... args) Args const&... args) {
{
static_assert(std::is_convertible<decltype(ftor(arg0, args...)), scheduled_actor*>::value == false, static_assert(std::is_convertible<decltype(ftor(arg0, args...)), scheduled_actor*>::value == false,
"Spawning a functor returning an actor_behavior? " "Spawning a functor returning an actor_behavior? "
"Are you sure that you do not want to spawn the behavior " "Are you sure that you do not want to spawn the behavior "
......
...@@ -39,8 +39,7 @@ ...@@ -39,8 +39,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
class group_manager class group_manager {
{
public: public:
......
...@@ -46,8 +46,7 @@ namespace cppa { class local_actor; } ...@@ -46,8 +46,7 @@ namespace cppa { class local_actor; }
namespace cppa { namespace detail { namespace cppa { namespace detail {
template<typename T> template<typename T>
struct implicit_conversions struct implicit_conversions {
{
typedef typename util::replace_type<T, std::string, typedef typename util::replace_type<T, std::string,
std::is_same<T, char const*>, std::is_same<T, char const*>,
std::is_same<T, char*>, std::is_same<T, char*>,
...@@ -76,8 +75,7 @@ struct implicit_conversions ...@@ -76,8 +75,7 @@ struct implicit_conversions
}; };
template<typename T> template<typename T>
struct strip_and_convert struct strip_and_convert {
{
typedef typename implicit_conversions<typename util::rm_ref<T>::type>::type typedef typename implicit_conversions<typename util::rm_ref<T>::type>::type
type; type;
}; };
......
...@@ -48,8 +48,7 @@ ...@@ -48,8 +48,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
class invokable class invokable {
{
invokable(invokable const&) = delete; invokable(invokable const&) = delete;
invokable& operator=(invokable const&) = delete; invokable& operator=(invokable const&) = delete;
...@@ -73,72 +72,59 @@ class invokable ...@@ -73,72 +72,59 @@ class invokable
}; };
enum mapping_policy enum mapping_policy {
{
do_not_map, do_not_map,
map_to_bool, map_to_bool,
map_to_option map_to_option
}; };
template<mapping_policy, class Pattern> // do_not_map template<mapping_policy, class Pattern> // do_not_map
struct pattern_policy struct pattern_policy {
{
Pattern m_pattern; Pattern m_pattern;
template<typename... Args> template<typename... Args>
pattern_policy(Args&&... args) : m_pattern(std::forward<Args>(args)...) { } pattern_policy(Args&&... args) : m_pattern(std::forward<Args>(args)...) { }
bool types_match(any_tuple const& value) const bool types_match(any_tuple const& value) const {
{
return matches_types(value, m_pattern); return matches_types(value, m_pattern);
} }
bool could_invoke(any_tuple const& value) const bool could_invoke(any_tuple const& value) const {
{
return matches(value, m_pattern); return matches(value, m_pattern);
} }
template<typename Fun> template<typename Fun>
bool call(Fun const& fun, any_tuple& value) const bool call(Fun const& fun, any_tuple& value) const {
{
fun(value); fun(value);
return true; return true;
} }
template<typename Fun> template<typename Fun>
bool call_unsafe(Fun const& fun, any_tuple& value) const bool call_unsafe(Fun const& fun, any_tuple& value) const {
{
fun(value); fun(value);
return true; return true;
} }
}; };
template<class Pattern> template<class Pattern>
struct pattern_policy<map_to_option, Pattern> struct pattern_policy<map_to_option, Pattern> {
{
Pattern m_pattern; Pattern m_pattern;
template<typename... Args> template<typename... Args>
pattern_policy(Args&&... args) : m_pattern(std::forward<Args>(args)...) { } pattern_policy(Args&&... args) : m_pattern(std::forward<Args>(args)...) { }
bool types_match(any_tuple const& value) const bool types_match(any_tuple const& value) const {
{
return matches_types(value, m_pattern); return matches_types(value, m_pattern);
} }
bool could_invoke(any_tuple const& value) const bool could_invoke(any_tuple const& value) const {
{
return matches(value, m_pattern); return matches(value, m_pattern);
} }
template<typename Fun> template<typename Fun>
bool call(Fun const& fun, any_tuple& value) const bool call(Fun const& fun, any_tuple& value) const {
{
auto result = moving_tuple_cast(value, m_pattern); auto result = moving_tuple_cast(value, m_pattern);
if (result) if (result) {
{
util::apply_tuple(fun, *result); util::apply_tuple(fun, *result);
return true; return true;
} }
return false; return false;
} }
template<typename Fun> template<typename Fun>
bool call_unsafe(Fun const& fun, any_tuple& value) const bool call_unsafe(Fun const& fun, any_tuple& value) const {
{
auto result = unsafe_tuple_cast(value, m_pattern); auto result = unsafe_tuple_cast(value, m_pattern);
if (result) if (result) {
{
util::apply_tuple(fun, *result); util::apply_tuple(fun, *result);
return true; return true;
} }
...@@ -147,34 +133,27 @@ struct pattern_policy<map_to_option, Pattern> ...@@ -147,34 +133,27 @@ struct pattern_policy<map_to_option, Pattern>
}; };
template<class Pattern> template<class Pattern>
struct pattern_policy<map_to_bool, Pattern> struct pattern_policy<map_to_bool, Pattern> {
{
Pattern m_pattern; Pattern m_pattern;
template<typename... Args> template<typename... Args>
pattern_policy(Args&&... args) : m_pattern(std::forward<Args>(args)...) { } pattern_policy(Args&&... args) : m_pattern(std::forward<Args>(args)...) { }
bool types_match(any_tuple const& value) const bool types_match(any_tuple const& value) const {
{
return matches_types(value, m_pattern); return matches_types(value, m_pattern);
} }
bool could_invoke(any_tuple const& value) const bool could_invoke(any_tuple const& value) const {
{
return matches(value, m_pattern); return matches(value, m_pattern);
} }
template<typename Fun> template<typename Fun>
bool call(Fun const& fun, any_tuple& value) const bool call(Fun const& fun, any_tuple& value) const {
{ if (could_invoke(value)) {
if (could_invoke(value))
{
fun(); fun();
return true; return true;
} }
return false; return false;
} }
template<typename Fun> template<typename Fun>
bool call_unsafe(Fun const& fun, any_tuple& value) const bool call_unsafe(Fun const& fun, any_tuple& value) const {
{ if (could_invoke(value)) {
if (could_invoke(value))
{
fun(); fun();
return true; return true;
} }
...@@ -182,33 +161,27 @@ struct pattern_policy<map_to_bool, Pattern> ...@@ -182,33 +161,27 @@ struct pattern_policy<map_to_bool, Pattern>
} }
}; };
struct dummy_policy struct dummy_policy {
{ inline bool types_match(any_tuple const&) const {
inline bool types_match(any_tuple const&) const
{
return true; return true;
} }
inline bool could_invoke(any_tuple const&) const inline bool could_invoke(any_tuple const&) const {
{
return true; return true;
} }
template<typename Fun> template<typename Fun>
inline bool call(Fun const& fun, any_tuple&) const inline bool call(Fun const& fun, any_tuple&) const {
{
fun(); fun();
return true; return true;
} }
template<typename Fun> template<typename Fun>
inline bool call_unsafe(Fun const& fun, any_tuple&) const inline bool call_unsafe(Fun const& fun, any_tuple&) const {
{
fun(); fun();
return true; return true;
} }
}; };
template<typename Fun, class Policy> template<typename Fun, class Policy>
struct invokable_impl : public invokable struct invokable_impl : public invokable {
{
Fun m_fun; Fun m_fun;
Policy m_policy; Policy m_policy;
...@@ -216,35 +189,29 @@ struct invokable_impl : public invokable ...@@ -216,35 +189,29 @@ struct invokable_impl : public invokable
template<typename Arg0, typename... Args> template<typename Arg0, typename... Args>
invokable_impl(Arg0&& arg0, Args&&... args) invokable_impl(Arg0&& arg0, Args&&... args)
: m_fun(std::forward<Arg0>(arg0)) : m_fun(std::forward<Arg0>(arg0))
, m_policy(std::forward<Args>(args)...) , m_policy(std::forward<Args>(args)...) {
{
} }
bool invoke(any_tuple& value) const bool invoke(any_tuple& value) const {
{
return m_policy.call(m_fun, value); return m_policy.call(m_fun, value);
} }
bool unsafe_invoke(any_tuple& value) const bool unsafe_invoke(any_tuple& value) const {
{
return m_policy.call_unsafe(m_fun, value); return m_policy.call_unsafe(m_fun, value);
} }
bool types_match(any_tuple const& value) const bool types_match(any_tuple const& value) const {
{
return m_policy.types_match(value); return m_policy.types_match(value);
} }
bool could_invoke(any_tuple const& value) const bool could_invoke(any_tuple const& value) const {
{
return m_policy.could_invoke(value); return m_policy.could_invoke(value);
} }
}; };
template<class ArgTypes> template<class ArgTypes>
constexpr mapping_policy get_mapping_policy() constexpr mapping_policy get_mapping_policy() {
{
return (ArgTypes::size == 0) return (ArgTypes::size == 0)
? map_to_bool ? map_to_bool
: (( std::is_same<typename ArgTypes::head, any_tuple>::value : (( std::is_same<typename ArgTypes::head, any_tuple>::value
...@@ -257,22 +224,19 @@ template<class Container> ...@@ -257,22 +224,19 @@ template<class Container>
struct filtered; struct filtered;
template<typename... Ts> template<typename... Ts>
struct filtered<util::type_list<Ts...> > struct filtered<util::type_list<Ts...> > {
{
typedef typename util::tl_filter_not<util::type_list<Ts...>, is_anything>::type typedef typename util::tl_filter_not<util::type_list<Ts...>, is_anything>::type
types; types;
}; };
template<typename... Ts> template<typename... Ts>
struct filtered<pattern<Ts...> > struct filtered<pattern<Ts...> > {
{
typedef typename filtered<util::type_list<Ts...>>::types types; typedef typename filtered<util::type_list<Ts...>>::types types;
}; };
template<typename Fun, class Pattern> template<typename Fun, class Pattern>
struct select_invokable_impl struct select_invokable_impl {
{
typedef typename util::get_arg_types<Fun>::types qualified_arg_types; typedef typename util::get_arg_types<Fun>::types qualified_arg_types;
typedef typename util::tl_map<qualified_arg_types, util::rm_ref>::type typedef typename util::tl_map<qualified_arg_types, util::rm_ref>::type
arg_types; arg_types;
...@@ -281,8 +245,7 @@ struct select_invokable_impl ...@@ -281,8 +245,7 @@ struct select_invokable_impl
}; };
template<typename Fun> template<typename Fun>
struct select_invokable_impl<Fun, pattern<anything> > struct select_invokable_impl<Fun, pattern<anything> > {
{
typedef typename util::get_arg_types<Fun>::types qualified_arg_types; typedef typename util::get_arg_types<Fun>::types qualified_arg_types;
typedef typename util::tl_map<qualified_arg_types, util::rm_ref>::type typedef typename util::tl_map<qualified_arg_types, util::rm_ref>::type
arg_types; arg_types;
...@@ -296,11 +259,9 @@ struct select_invokable_impl<Fun, pattern<anything> > ...@@ -296,11 +259,9 @@ struct select_invokable_impl<Fun, pattern<anything> >
template<class Pattern, typename Fun> template<class Pattern, typename Fun>
std::unique_ptr<invokable> get_invokable_impl(Fun&& fun, std::unique_ptr<invokable> get_invokable_impl(Fun&& fun,
std::unique_ptr<value_matcher>&& vm) std::unique_ptr<value_matcher>&& vm) {
{
typedef std::unique_ptr<invokable> result; typedef std::unique_ptr<invokable> result;
if (vm) if (vm) {
{
typedef typename select_invokable_impl<Fun, Pattern>::type impl1; typedef typename select_invokable_impl<Fun, Pattern>::type impl1;
return result{new impl1{std::forward<Fun>(fun), std::move(vm)}}; return result{new impl1{std::forward<Fun>(fun), std::move(vm)}};
} }
...@@ -310,8 +271,7 @@ std::unique_ptr<invokable> get_invokable_impl(Fun&& fun, ...@@ -310,8 +271,7 @@ std::unique_ptr<invokable> get_invokable_impl(Fun&& fun,
} }
template<class Pattern, typename Fun> template<class Pattern, typename Fun>
std::unique_ptr<invokable> get_invokable_impl(Fun&& fun) std::unique_ptr<invokable> get_invokable_impl(Fun&& fun) {
{
typedef typename Pattern::types pattern_types; typedef typename Pattern::types pattern_types;
typedef typename select_invokable_impl<Fun, pattern_types>::type impl; typedef typename select_invokable_impl<Fun, pattern_types>::type impl;
return std::unique_ptr<invokable>{new impl(std::forward<Fun>(fun))}; return std::unique_ptr<invokable>{new impl(std::forward<Fun>(fun))};
......
...@@ -37,25 +37,20 @@ ...@@ -37,25 +37,20 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
template<typename List, bool HasPrimitiveValues> template<typename List, bool HasPrimitiveValues>
struct list_member_util struct list_member_util {
{
typedef typename List::value_type value_type; typedef typename List::value_type value_type;
static constexpr primitive_type vptype = type_to_ptype<value_type>::ptype; static constexpr primitive_type vptype = type_to_ptype<value_type>::ptype;
void operator()(List const& list, serializer* s) const void operator()(List const& list, serializer* s) const {
{
s->begin_sequence(list.size()); s->begin_sequence(list.size());
for (auto i = list.begin(); i != list.end(); ++i) for (auto i = list.begin(); i != list.end(); ++i) {
{
s->write_value(*i); s->write_value(*i);
} }
s->end_sequence(); s->end_sequence();
} }
void operator()(List& list, deserializer* d) const void operator()(List& list, deserializer* d) const {
{
list.clear(); list.clear();
auto size = d->begin_sequence(); auto size = d->begin_sequence();
for (decltype(size) i = 0; i < size; ++i) for (decltype(size) i = 0; i < size; ++i) {
{
list.push_back(get<value_type>(d->read_value(vptype))); list.push_back(get<value_type>(d->read_value(vptype)));
} }
d->end_sequence(); d->end_sequence();
...@@ -63,33 +58,27 @@ struct list_member_util ...@@ -63,33 +58,27 @@ struct list_member_util
}; };
template<typename List> template<typename List>
struct list_member_util<List, false> struct list_member_util<List, false> {
{
typedef typename List::value_type value_type; typedef typename List::value_type value_type;
uniform_type_info const* m_value_type; uniform_type_info const* m_value_type;
list_member_util() : m_value_type(uniform_typeid<value_type>()) list_member_util() : m_value_type(uniform_typeid<value_type>()) {
{
} }
void operator()(List const& list, serializer* s) const void operator()(List const& list, serializer* s) const {
{
s->begin_sequence(list.size()); s->begin_sequence(list.size());
for (auto i = list.begin(); i != list.end(); ++i) for (auto i = list.begin(); i != list.end(); ++i) {
{
m_value_type->serialize(&(*i), s); m_value_type->serialize(&(*i), s);
} }
s->end_sequence(); s->end_sequence();
} }
void operator()(List& list, deserializer* d) const void operator()(List& list, deserializer* d) const {
{
list.clear(); list.clear();
value_type tmp; value_type tmp;
auto size = d->begin_sequence(); auto size = d->begin_sequence();
for (decltype(size) i = 0; i < size; ++i) for (decltype(size) i = 0; i < size; ++i) {
{
m_value_type->deserialize(&tmp, d); m_value_type->deserialize(&tmp, d);
list.push_back(tmp); list.push_back(tmp);
} }
...@@ -98,22 +87,19 @@ struct list_member_util<List, false> ...@@ -98,22 +87,19 @@ struct list_member_util<List, false>
}; };
template<typename List> template<typename List>
class list_member : public util::abstract_uniform_type_info<List> class list_member : public util::abstract_uniform_type_info<List> {
{
typedef typename List::value_type value_type; typedef typename List::value_type value_type;
list_member_util<List, util::is_primitive<value_type>::value> m_helper; list_member_util<List, util::is_primitive<value_type>::value> m_helper;
public: public:
void serialize(void const* obj, serializer* s) const void serialize(void const* obj, serializer* s) const {
{
auto& list = *reinterpret_cast<List const*>(obj); auto& list = *reinterpret_cast<List const*>(obj);
m_helper(list, s); m_helper(list, s);
} }
void deserialize(void* obj, deserializer* d) const void deserialize(void* obj, deserializer* d) const {
{
auto& list = *reinterpret_cast<List*>(obj); auto& list = *reinterpret_cast<List*>(obj);
m_helper(list, d); m_helper(list, d);
} }
......
...@@ -49,18 +49,15 @@ struct map_member_util; ...@@ -49,18 +49,15 @@ struct map_member_util;
// std::set with primitive value // std::set with primitive value
template<typename T> template<typename T>
struct map_member_util<T, false, true> struct map_member_util<T, false, true> {
{
primitive_member<T> impl; primitive_member<T> impl;
void serialize_value(T const& what, serializer* s) const void serialize_value(T const& what, serializer* s) const {
{
impl.serialize(&what, s); impl.serialize(&what, s);
} }
template<typename M> template<typename M>
void deserialize_and_insert(M& map, deserializer* d) const void deserialize_and_insert(M& map, deserializer* d) const {
{
T value; T value;
impl.deserialize(&value, d); impl.deserialize(&value, d);
map.insert(std::move(value)); map.insert(std::move(value));
...@@ -69,22 +66,18 @@ struct map_member_util<T, false, true> ...@@ -69,22 +66,18 @@ struct map_member_util<T, false, true>
// std::set with non-primitive value // std::set with non-primitive value
template<typename T> template<typename T>
struct map_member_util<T, false, false> struct map_member_util<T, false, false> {
{
uniform_type_info const* m_type; uniform_type_info const* m_type;
map_member_util() : m_type(uniform_typeid<T>()) map_member_util() : m_type(uniform_typeid<T>()) {
{
} }
void serialize_value(T const& what, serializer* s) const void serialize_value(T const& what, serializer* s) const {
{
m_type->serialize(&what, s); m_type->serialize(&what, s);
} }
template<typename M> template<typename M>
void deserialize_and_insert(M& map, deserializer* d) const void deserialize_and_insert(M& map, deserializer* d) const {
{
T value; T value;
m_type->deserialize(&value, d); m_type->deserialize(&value, d);
map.insert(std::move(value)); map.insert(std::move(value));
...@@ -93,8 +86,7 @@ struct map_member_util<T, false, false> ...@@ -93,8 +86,7 @@ struct map_member_util<T, false, false>
// std::map // std::map
template<typename T> template<typename T>
struct map_member_util<T, true, false> struct map_member_util<T, true, false> {
{
// std::map defines its first half of value_type as const // std::map defines its first half of value_type as const
typedef typename std::remove_const<typename T::first_type>::type first_type; typedef typename std::remove_const<typename T::first_type>::type first_type;
...@@ -103,16 +95,14 @@ struct map_member_util<T, true, false> ...@@ -103,16 +95,14 @@ struct map_member_util<T, true, false>
pair_member<first_type, second_type> impl; pair_member<first_type, second_type> impl;
void serialize_value(T const& what, serializer* s) const void serialize_value(T const& what, serializer* s) const {
{
// impl needs a pair without const modifier // impl needs a pair without const modifier
std::pair<first_type, second_type> p(what.first, what.second); std::pair<first_type, second_type> p(what.first, what.second);
impl.serialize(&p, s); impl.serialize(&p, s);
} }
template<typename M> template<typename M>
void deserialize_and_insert(M& map, deserializer* d) const void deserialize_and_insert(M& map, deserializer* d) const {
{
std::pair<first_type, second_type> p; std::pair<first_type, second_type> p;
impl.deserialize(&p, d); impl.deserialize(&p, d);
std::pair<const first_type, second_type> v(std::move(p.first), std::pair<const first_type, second_type> v(std::move(p.first),
...@@ -123,8 +113,7 @@ struct map_member_util<T, true, false> ...@@ -123,8 +113,7 @@ struct map_member_util<T, true, false>
}; };
template<typename Map> template<typename Map>
class map_member : public util::abstract_uniform_type_info<Map> class map_member : public util::abstract_uniform_type_info<Map> {
{
typedef typename Map::key_type key_type; typedef typename Map::key_type key_type;
typedef typename Map::value_type value_type; typedef typename Map::value_type value_type;
...@@ -135,24 +124,20 @@ class map_member : public util::abstract_uniform_type_info<Map> ...@@ -135,24 +124,20 @@ class map_member : public util::abstract_uniform_type_info<Map>
public: public:
void serialize(void const* obj, serializer* s) const void serialize(void const* obj, serializer* s) const {
{
auto& mp = *reinterpret_cast<Map const*>(obj); auto& mp = *reinterpret_cast<Map const*>(obj);
s->begin_sequence(mp.size()); s->begin_sequence(mp.size());
for (auto const& val : mp) for (auto const& val : mp) {
{
m_helper.serialize_value(val, s); m_helper.serialize_value(val, s);
} }
s->end_sequence(); s->end_sequence();
} }
void deserialize(void* obj, deserializer* d) const void deserialize(void* obj, deserializer* d) const {
{
auto& mp = *reinterpret_cast<Map*>(obj); auto& mp = *reinterpret_cast<Map*>(obj);
mp.clear(); mp.clear();
size_t mp_size = d->begin_sequence(); size_t mp_size = d->begin_sequence();
for (size_t i = 0; i < mp_size; ++i) for (size_t i = 0; i < mp_size; ++i) {
{
m_helper.deserialize_and_insert(mp, d); m_helper.deserialize_and_insert(mp, d);
} }
d->end_sequence(); d->end_sequence();
......
This diff is collapsed.
...@@ -39,8 +39,7 @@ ...@@ -39,8 +39,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
class mock_scheduler : public scheduler class mock_scheduler : public scheduler {
{
public: public:
......
This diff is collapsed.
...@@ -35,8 +35,7 @@ ...@@ -35,8 +35,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
class network_manager class network_manager {
{
public: public:
......
...@@ -39,8 +39,7 @@ ...@@ -39,8 +39,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
class object_array : public abstract_tuple class object_array : public abstract_tuple {
{
typedef abstract_tuple super; typedef abstract_tuple super;
......
...@@ -43,8 +43,7 @@ utype const& uniform_type_info(); ...@@ -43,8 +43,7 @@ utype const& uniform_type_info();
namespace cppa { namespace detail { namespace cppa { namespace detail {
template<typename T> template<typename T>
struct obj_impl : object struct obj_impl : object {
{
T m_value; T m_value;
obj_impl() : m_value() { } obj_impl() : m_value() { }
obj_impl(T const& v) : m_value(v) { } obj_impl(T const& v) : m_value(v) { }
...@@ -52,12 +51,10 @@ struct obj_impl : object ...@@ -52,12 +51,10 @@ struct obj_impl : object
virtual utype const& type() const { return uniform_type_info<T>(); } virtual utype const& type() const { return uniform_type_info<T>(); }
virtual void* mutable_value() { return &m_value; } virtual void* mutable_value() { return &m_value; }
virtual void const* value() const { return &m_value; } virtual void const* value() const { return &m_value; }
virtual void serialize(serializer& s) const virtual void serialize(serializer& s) const {
{
s << m_value; s << m_value;
} }
virtual void deserialize(deserializer& d) virtual void deserialize(deserializer& d) {
{
d >> m_value; d >> m_value;
} }
}; };
......
...@@ -42,8 +42,7 @@ ...@@ -42,8 +42,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
template<typename T1, typename T2> template<typename T1, typename T2>
class pair_member : public util::abstract_uniform_type_info<std::pair<T1,T2>> class pair_member : public util::abstract_uniform_type_info<std::pair<T1,T2>> {
{
static constexpr primitive_type ptype1 = type_to_ptype<T1>::ptype; static constexpr primitive_type ptype1 = type_to_ptype<T1>::ptype;
static constexpr primitive_type ptype2 = type_to_ptype<T2>::ptype; static constexpr primitive_type ptype2 = type_to_ptype<T2>::ptype;
...@@ -55,15 +54,13 @@ class pair_member : public util::abstract_uniform_type_info<std::pair<T1,T2>> ...@@ -55,15 +54,13 @@ class pair_member : public util::abstract_uniform_type_info<std::pair<T1,T2>>
public: public:
void serialize(void const* obj, serializer* s) const void serialize(void const* obj, serializer* s) const {
{
auto& p = *reinterpret_cast<pair_type const*>(obj); auto& p = *reinterpret_cast<pair_type const*>(obj);
primitive_variant values[2] = { p.first, p.second }; primitive_variant values[2] = { p.first, p.second };
s->write_tuple(2, values); s->write_tuple(2, values);
} }
void deserialize(void* obj, deserializer* d) const void deserialize(void* obj, deserializer* d) const {
{
primitive_type ptypes[2] = { ptype1, ptype2 }; primitive_type ptypes[2] = { ptype1, ptype2 };
primitive_variant values[2]; primitive_variant values[2];
d->read_tuple(2, ptypes, values); d->read_tuple(2, ptypes, values);
......
...@@ -39,8 +39,7 @@ ...@@ -39,8 +39,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
struct po_message struct po_message {
{
atom_value flag; atom_value flag;
native_socket_type fd; native_socket_type fd;
actor_id aid; actor_id aid;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -62,8 +62,7 @@ struct ptype_to_type : ...@@ -62,8 +62,7 @@ struct ptype_to_type :
util::if_else_c<PT == pt_u16string, std::u16string, util::if_else_c<PT == pt_u16string, std::u16string,
util::if_else_c<PT == pt_u32string, std::u32string, util::if_else_c<PT == pt_u32string, std::u32string,
// default case // default case
void > > > > > > > > > > > > > > void > > > > > > > > > > > > > > {
{
}; };
} } // namespace cppa::detail } } // namespace cppa::detail
......
This diff is collapsed.
This diff is collapsed.
...@@ -34,8 +34,7 @@ ...@@ -34,8 +34,7 @@
namespace cppa { namespace detail { namespace cppa { namespace detail {
template<typename T> template<typename T>
class ref_counted_impl class ref_counted_impl {
{
T m_rc; T m_rc;
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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