+#include "common.h"
+#include <atomic>
+#include <cds/gc/dhp.h>
+#include <cds/gc/hp.h>
+#include <cds/sync/spinlock.h>
+#include <cds/sync/ticket_lock.h>
+#include <cds_test/stress_test.h>
+#include <iostream>
+#include <iostream>
+#include <memory>
+#include <thread>
+
+using namespace std;
+
+namespace {
+
+typedef cds_others::TicketLock TicketLock;
+typedef cds::sync::spin SpinLock;
+typedef cds::sync::reentrant_spin32 Reentrant32;
+typedef cds::sync::reentrant_spin64 Reentrant64;
+static size_t s_nSpinLockThreadCount = 6;
+static size_t s_nSpinLockPassCount = 2500000000;
+static size_t s_nTicketLockPassCount = 4000000;
+
+#define TASK(lock_type, lock_ptr, pass_cnt) \
+ static void Thread##lock_type() { \
+ for (size_t i = 0; i < pass_cnt; i++) { \
+ lock_ptr->lock(); \
+ x++; \
+ lock_ptr->unlock(); \
+ } \
+ }
+
+#define LOCK_TEST(lock_type, lock_ptr, pass_cnt) \
+ TEST_F(SpinLockTest, lock_type) { \
+ lock_ptr = new lock_type(); \
+ x = 0; \
+ Thread##lock_type(); \
+ }
+
+class SpinLockTest : public cds_test::stress_fixture {
+protected:
+ static size_t x;
+ static TicketLock *ticket_mutex;
+ static SpinLock *spin_mutex;
+ static Reentrant32 *reentrant_mutex32;
+ static Reentrant64 *reentrant_mutex64;
+
+ static void SetUpTestCase() {
+ cds_test::config const &cfg = get_config("SequentialMisc");
+ GetConfig(SpinLockThreadCount);
+ GetConfig(SpinLockPassCount);
+ GetConfig(TicketLockPassCount);
+ }
+
+ TASK(TicketLock, ticket_mutex, s_nTicketLockPassCount)
+ TASK(SpinLock, spin_mutex, s_nSpinLockPassCount)
+ TASK(Reentrant32, reentrant_mutex32, s_nSpinLockPassCount)
+ TASK(Reentrant64, reentrant_mutex64, s_nSpinLockPassCount)
+};
+
+size_t SpinLockTest::x;
+TicketLock *SpinLockTest::ticket_mutex;
+SpinLock *SpinLockTest::spin_mutex;
+Reentrant32 *SpinLockTest::reentrant_mutex32;
+Reentrant64 *SpinLockTest::reentrant_mutex64;
+
+LOCK_TEST(TicketLock, ticket_mutex, s_nTicketLockPassCount)
+LOCK_TEST(SpinLock, spin_mutex, s_nSpinLockPassCount)
+LOCK_TEST(Reentrant32, reentrant_mutex32, s_nSpinLockPassCount)
+LOCK_TEST(Reentrant64, reentrant_mutex64, s_nSpinLockPassCount)
+
+} // namespace