Gets iterable map pass count input from config file
[libcds.git] / benchmark-drivers / basketqueue_driver.cpp
1 #include <cds/gc/dhp.h>
2 #include <cds/gc/hp.h>
3 #include <cds/init.h>
4 #include <cds/intrusive/basket_queue.h>
5 #include <iostream>
6 #include <string>
7
8 using namespace std;
9
10 namespace ci = cds::intrusive;
11 typedef cds::gc::HP hp_gc;
12
13 struct Foo : public ci::basket_queue::node<hp_gc> {
14   Foo(int x) : x(x) {}
15   int x;
16 };
17
18 // Declare traits for the queue
19 struct MyTraits : public cds::intrusive::basket_queue::traits {
20   typedef cds::intrusive::basket_queue::stat<> stat;
21   typedef cds::atomicity::item_counter item_counter;
22 };
23
24 // At least, declare the queue type
25 typedef ci::BasketQueue<hp_gc, Foo, MyTraits> MyQueue;
26
27 int main() {
28   cds::Initialize();
29
30   {
31     // Initialize Hazard Pointer singleton
32     cds::gc::HP hpGC(128, 8, 128);
33     // If main thread uses lock-free containers
34     // the main thread should be attached to libcds infrastructure
35     cds::threading::Manager::attachThread();
36
37     MyQueue q;
38     Foo *f = new Foo(1);
39     Foo *res = nullptr;
40     q.enqueue(*f);
41     res = q.dequeue();
42     if (res) {
43       cout << "Dequeued " << res->x << "\n";
44     } else {
45       cout << "Dequeued none\n";
46     }
47   }
48
49   cds::Terminate();
50   return 0;
51 }