Fixes RigtorpMPMC test case
[libcds.git] / benchmark-drivers / fcqueue_driver.cpp
1 #include <cds/gc/dhp.h>
2 #include <cds/gc/hp.h>
3 #include <cds/init.h>
4 #include <cds/intrusive/fcqueue.h>
5 #include <iostream>
6 #include <list>
7 #include <string>
8
9 using namespace std;
10
11 namespace ci = cds::intrusive;
12 typedef cds::gc::HP hp_gc;
13
14 struct Foo : boost::intrusive::list_base_hook<> {
15   Foo(int x) : x(x) {}
16   int x;
17 };
18
19 // At least, declare the queue type
20 typedef ci::FCQueue<Foo> MyQueue;
21
22 int main() {
23   cds::Initialize();
24
25   {
26     // Initialize Hazard Pointer singleton
27     cds::gc::HP hpGC(128, 8, 128);
28     // If main thread uses lock-free containers
29     // the main thread should be attached to libcds infrastructure
30     cds::threading::Manager::attachThread();
31
32     MyQueue q;
33     Foo *f = new Foo(1);
34     Foo *res = nullptr;
35     q.enqueue(*f);
36     res = q.dequeue();
37     if (res) {
38       cout << "Dequeued " << res->x << "\n";
39     } else {
40       cout << "Dequeued none\n\n";
41     }
42   }
43
44   cds::Terminate();
45   return 0;
46 }