Cross compile works
[libcds.git] / benchmark-drivers / optimisticqueue_driver.cpp
diff --git a/benchmark-drivers/optimisticqueue_driver.cpp b/benchmark-drivers/optimisticqueue_driver.cpp
new file mode 100644 (file)
index 0000000..311d05d
--- /dev/null
@@ -0,0 +1,51 @@
+#include <cds/gc/dhp.h>
+#include <cds/gc/hp.h>
+#include <cds/init.h>
+#include <cds/intrusive/optimistic_queue.h>
+#include <iostream>
+#include <string>
+
+using namespace std;
+
+namespace ci = cds::intrusive;
+typedef cds::gc::HP hp_gc;
+
+struct Foo : public ci::optimistic_queue::node<hp_gc> {
+  Foo(int x) : x(x) {}
+  int x;
+};
+
+// Declare traits for the queue
+struct MyTraits : public cds::intrusive::optimistic_queue::traits {
+  typedef cds::intrusive::optimistic_queue::stat<> stat;
+  typedef cds::atomicity::item_counter item_counter;
+};
+
+// At least, declare the queue type
+typedef ci::OptimisticQueue<hp_gc, Foo, MyTraits> MyQueue;
+
+int main() {
+  cds::Initialize();
+
+  {
+    // Initialize Hazard Pointer singleton
+    cds::gc::HP hpGC(128, 8, 128);
+    // If main thread uses lock-free containers
+    // the main thread should be attached to libcds infrastructure
+    cds::threading::Manager::attachThread();
+
+    MyQueue q;
+    Foo *f = new Foo(1);
+    Foo *res = nullptr;
+    q.enqueue(*f);
+    res = q.dequeue();
+    if (res) {
+      cout << "Dequeued " << res->x << "\n";
+    } else {
+      cout << "Dequeued none\n";
+    }
+  }
+
+  cds::Terminate();
+  return 0;
+}