2 #include <cds/gc/dhp.h>
4 #include <cds/sync/spinlock.h>
5 #include <cds_test/stress_test.h>
13 typedef cds::sync::spin SpinLock;
14 typedef cds::sync::reentrant_spin32 Reentrant32;
15 typedef cds::sync::reentrant_spin64 Reentrant64;
17 #define TASK(lock_type, lock_ptr) \
18 static void Thread ## lock_type() { \
19 for (int i = 0; i < 100000; i++) { \
20 for (int j = 0; j < 30000; j++) { \
28 #define LOCK_TEST(lock_type, lock_ptr) \
29 TEST_F(SpinLockTest, lock_type) { \
30 lock_ptr = new lock_type(); \
31 std::thread threads[kThreads]; \
32 for (int i = 0; i < kThreads; i++) { \
33 threads[i] = std::thread(Thread ## lock_type); \
35 for (int i = 0; i < kThreads; i++) { \
40 class SpinLockTest : public cds_test::stress_fixture {
43 static SpinLock* spin_mutex;
44 static Reentrant32* reentrant_mutex32;
45 static Reentrant64* reentrant_mutex64;
47 static const int kThreads = 6;
49 static void SetUpTestCase() {}
51 TASK(SpinLock, spin_mutex)
52 TASK(Reentrant32, reentrant_mutex32)
53 TASK(Reentrant64, reentrant_mutex64)
57 const int SpinLockTest::kThreads;
58 SpinLock* SpinLockTest::spin_mutex;
59 Reentrant32* SpinLockTest::reentrant_mutex32;
60 Reentrant64* SpinLockTest::reentrant_mutex64;
62 LOCK_TEST(SpinLock, spin_mutex)
63 LOCK_TEST(Reentrant32, reentrant_mutex32)
64 LOCK_TEST(Reentrant64, reentrant_mutex64)