#include <cds/gc/dhp.h>
#include <cds/gc/hp.h>
#include <cds/sync/spinlock.h>
-#include <cds/sync/ticket_lock.h>
+#include <cds/misc/ticket_lock.h>
#include <cds_test/stress_test.h>
#include <iostream>
#include <iostream>
+#include <memory>
#include <thread>
using namespace std;
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_nSpinLockThreadCount = 4;
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 (int i = 0; i < pass_cnt; i++) { \
+ for (size_t i = 0; i < pass_cnt; i++) { \
lock_ptr->lock(); \
x++; \
lock_ptr->unlock(); \
TEST_F(SpinLockTest, lock_type) { \
lock_ptr = new lock_type(); \
x = 0; \
+ std::unique_ptr<std::thread[]>(new std::thread[s_nSpinLockThreadCount]); \
std::thread *threads = new std::thread[s_nSpinLockThreadCount]; \
- for (int i = 0; i < s_nSpinLockThreadCount; i++) { \
+ for (size_t i = 0; i < s_nSpinLockThreadCount; i++) { \
threads[i] = std::thread(Thread##lock_type); \
} \
- for (int i = 0; i < s_nSpinLockThreadCount; i++) { \
+ for (size_t i = 0; i < s_nSpinLockThreadCount; i++) { \
threads[i].join(); \
} \
if (x != s_nSpinLockThreadCount * pass_cnt) { \
cout << "Incorrect " << #lock_type << "\n"; \
+ cout << "x=" << x << "\nThreadCount=" << s_nSpinLockThreadCount \
+ << "\nPassCount=" << pass_cnt \
+ << "\t&&\tSupposed times=" << s_nSpinLockThreadCount * pass_cnt \
+ << "\n"; \
} \
}
class SpinLockTest : public cds_test::stress_fixture {
protected:
- static int x;
+ static size_t x;
static TicketLock *ticket_mutex;
static SpinLock *spin_mutex;
static Reentrant32 *reentrant_mutex32;
TASK(Reentrant64, reentrant_mutex64, s_nSpinLockPassCount)
};
-int SpinLockTest::x;
+size_t SpinLockTest::x;
TicketLock *SpinLockTest::ticket_mutex;
SpinLock *SpinLockTest::spin_mutex;
Reentrant32 *SpinLockTest::reentrant_mutex32;