From dd09443b0b3c0b5d1a8c034644d1065dd25bf5a9 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 11 Nov 2018 23:02:59 -0500 Subject: start debugging multiloops design --- test/bench_network.cpp | 2 +- test/test_queue.cpp | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'test') diff --git a/test/bench_network.cpp b/test/bench_network.cpp index 1185c0d..b1f1a0f 100644 --- a/test/bench_network.cpp +++ b/test/bench_network.cpp @@ -97,7 +97,7 @@ struct MyNet: public MsgNetworkByteOp { struct Conn: public MsgNetworkByteOp::Conn { MyNet *get_net() { return static_cast(get_pool()); } - salticidae::RcObj self() { + salticidae::ArcObj self() { return salticidae::static_pointer_cast( MsgNetworkByteOp::Conn::self()); } diff --git a/test/test_queue.cpp b/test/test_queue.cpp index bed88c4..a2444d3 100644 --- a/test/test_queue.cpp +++ b/test/test_queue.cpp @@ -4,13 +4,22 @@ #include "salticidae/event.h" -void test_mpsc(int nproducers = 16, int nops = 100000) { +void test_mpsc(int nproducers = 16, int nops = 100000, size_t burst_size = 128) { size_t total = nproducers * nops; salticidae::EventContext ec; std::atomic collected(0); - salticidae::MPSCQueueEventDriven q(ec, [&collected](int x) { - printf("%d\n", x); - collected.fetch_add(1); + using queue_t = salticidae::MPSCQueueEventDriven; + queue_t q; + q.reg_handler(ec, [&collected, burst_size](queue_t &q) { + size_t cnt = burst_size; + int x; + while (q.try_dequeue(x)) + { + printf("%d\n", x); + collected.fetch_add(1); + if (!--cnt) return true; + } + return false; }); std::vector producers; std::thread consumer([&collected, total, &ec]() { @@ -39,6 +48,7 @@ void test_mpsc(int nproducers = 16, int nops = 100000) { fprintf(stderr, "consumers terminate\n"); } +/* void test_mpmc(int nproducers = 16, int nconsumers = 4, int nops = 100000) { size_t total = nproducers * nops; salticidae::MPMCQueueEventDriven q; @@ -84,9 +94,10 @@ void test_mpmc(int nproducers = 16, int nconsumers = 4, int nops = 100000) { for (auto &t: consumers) t.join(); fprintf(stderr, "consumers terminate\n"); } +*/ int main() { - //test_mpsc(); - test_mpmc(); + test_mpsc(); + //test_mpmc(); return 0; } -- cgit v1.2.3-70-g09d2