aboutsummaryrefslogtreecommitdiff
path: root/test/test_queue.cpp
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-04-05 23:25:50 -0400
committerDeterminant <[email protected]>2019-04-05 23:25:50 -0400
commitdf3007d2a04877ef2f707183014266d2086d1740 (patch)
tree3fc5ea4f8552d9701b07dc42e7bcaff507b895e8 /test/test_queue.cpp
parentb7802b3b06511f067719cb845dfd03a223f0e18f (diff)
WIP: new lock-free queue impl
Diffstat (limited to 'test/test_queue.cpp')
-rw-r--r--test/test_queue.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/test/test_queue.cpp b/test/test_queue.cpp
index c565db3..5c56585 100644
--- a/test/test_queue.cpp
+++ b/test/test_queue.cpp
@@ -14,6 +14,7 @@ void test_mpsc(int nproducers, int nops, size_t burst_size) {
std::atomic<size_t> collected(0);
using queue_t = salticidae::MPSCQueueEventDriven<int>;
queue_t q;
+ q.set_capacity(65536);
q.reg_handler(ec, [&collected, burst_size](queue_t &q) {
size_t cnt = burst_size;
int x;
@@ -34,6 +35,7 @@ void test_mpsc(int nproducers, int nops, size_t burst_size) {
timer.add(1);
ec.dispatch();
});
+
for (int i = 0; i < nproducers; i++)
{
producers.emplace(producers.end(), std::thread([&q, nops, i, nproducers]() {
@@ -41,7 +43,8 @@ void test_mpsc(int nproducers, int nops, size_t burst_size) {
for (int j = 0; j < nops; j++)
{
//usleep(rand() / double(RAND_MAX) * 100);
- q.enqueue(x);
+ while (!q.try_enqueue(x))
+ std::this_thread::yield();
x += nproducers;
}
}));
@@ -52,7 +55,7 @@ void test_mpsc(int nproducers, int nops, size_t burst_size) {
SALTICIDAE_LOG_INFO("consumers terminate");
}
-void test_mpmc(int nproducers, int nconsumers, int nops, size_t burst_size) {
+/*void test_mpmc(int nproducers, int nconsumers, int nops, size_t burst_size) {
size_t total = nproducers * nops;
using queue_t = salticidae::MPMCQueueEventDriven<int>;
queue_t q;
@@ -95,7 +98,7 @@ void test_mpmc(int nproducers, int nconsumers, int nops, size_t burst_size) {
for (int j = 0; j < nops; j++)
{
//usleep(rand() / double(RAND_MAX) * 100);
- q.enqueue(x);
+ q.try_enqueue(x);
x += nproducers;
}
}));
@@ -105,6 +108,7 @@ void test_mpmc(int nproducers, int nconsumers, int nops, size_t burst_size) {
for (auto &t: consumers) t.join();
SALTICIDAE_LOG_INFO("consumers terminate");
}
+*/
int main(int argc, char **argv) {
Config config;
@@ -136,8 +140,8 @@ int main(int argc, char **argv) {
else
{
SALTICIDAE_LOG_INFO("testing an MPMC queue...");
- test_mpmc(opt_nproducers->get(), opt_nconsumers->get(),
- opt_nops->get(), opt_burst_size->get());
+ //test_mpmc(opt_nproducers->get(), opt_nconsumers->get(),
+ // opt_nops->get(), opt_burst_size->get());
}
return 0;
}