3 #include <cds/gc/dhp.h>
5 #include <cds/sync/spinlock.h>
6 #include <cds/sync/ticket_lock.h>
7 #include <cds_test/stress_test.h>
16 typedef cds_others::TicketLock TicketLock;
17 typedef cds::sync::spin SpinLock;
18 typedef cds::sync::reentrant_spin32 Reentrant32;
19 typedef cds::sync::reentrant_spin64 Reentrant64;
20 static size_t s_nSpinLockThreadCount = 6;
21 static size_t s_nSpinLockPassCount = 2500000000;
22 static size_t s_nTicketLockPassCount = 4000000;
24 #define TASK(lock_type, lock_ptr, pass_cnt) \
25 static void Thread##lock_type() { \
26 for (int i = 0; i < pass_cnt; i++) { \
33 #define LOCK_TEST(lock_type, lock_ptr, pass_cnt) \
34 TEST_F(SpinLockTest, lock_type) { \
35 lock_ptr = new lock_type(); \
37 std::thread *threads = new std::thread[s_nSpinLockThreadCount]; \
38 for (int i = 0; i < s_nSpinLockThreadCount; i++) { \
39 threads[i] = std::thread(Thread##lock_type); \
41 for (int i = 0; i < s_nSpinLockThreadCount; i++) { \
44 if (x != s_nSpinLockThreadCount * pass_cnt) { \
45 cout << "Incorrect " << #lock_type << "\n"; \
49 class SpinLockTest : public cds_test::stress_fixture {
52 static TicketLock *ticket_mutex;
53 static SpinLock *spin_mutex;
54 static Reentrant32 *reentrant_mutex32;
55 static Reentrant64 *reentrant_mutex64;
57 static void SetUpTestCase() {
58 cds_test::config const &cfg = get_config("Misc");
59 GetConfig(SpinLockThreadCount);
60 GetConfig(SpinLockPassCount);
61 GetConfig(TicketLockPassCount);
64 TASK(TicketLock, ticket_mutex, s_nTicketLockPassCount)
65 TASK(SpinLock, spin_mutex, s_nSpinLockPassCount)
66 TASK(Reentrant32, reentrant_mutex32, s_nSpinLockPassCount)
67 TASK(Reentrant64, reentrant_mutex64, s_nSpinLockPassCount)
71 TicketLock *SpinLockTest::ticket_mutex;
72 SpinLock *SpinLockTest::spin_mutex;
73 Reentrant32 *SpinLockTest::reentrant_mutex32;
74 Reentrant64 *SpinLockTest::reentrant_mutex64;
76 LOCK_TEST(TicketLock, ticket_mutex, s_nTicketLockPassCount)
77 LOCK_TEST(SpinLock, spin_mutex, s_nSpinLockPassCount)
78 LOCK_TEST(Reentrant32, reentrant_mutex32, s_nSpinLockPassCount)
79 LOCK_TEST(Reentrant64, reentrant_mutex64, s_nSpinLockPassCount)