aboutsummaryrefslogtreecommitdiff
path: root/test/test_queue.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_queue.cpp')
-rw-r--r--test/test_queue.cpp23
1 files changed, 17 insertions, 6 deletions
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<size_t> collected(0);
- salticidae::MPSCQueueEventDriven<int> q(ec, [&collected](int x) {
- printf("%d\n", x);
- collected.fetch_add(1);
+ using queue_t = salticidae::MPSCQueueEventDriven<int>;
+ 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<std::thread> 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<int> 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;
}