target_link_libraries(${PACKAGE_NAME} ${CDS_TEST_LIBRARIES} ${CDSSTRESS_FRAMEWORK_LIBRARY})
add_executable(mytest test.cpp ../main.cpp)
+#add_executable(mytest test.cpp )
target_link_libraries(mytest ${CDS_TEST_LIBRARIES} ${CDSSTRESS_FRAMEWORK_LIBRARY})
add_test(NAME ${PACKAGE_NAME} COMMAND ${PACKAGE_NAME} WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
class ChaseLevDequeTest : public cds_test::stress_fixture {
protected:
- static Deque *deque;
static atomic_int terminate_stealer;
static ullong *sums;
static ullong *succ_counts;
GetConfig(DequeStealerThreadCount);
GetConfig(DequeMainPassCount);
}
-
- static void StealerThread(int index) {
- while (!terminate_stealer.load(memory_order_relaxed)) {
- int res = deque->steal();
- if (res != EMPTY && res != ABORT) {
- sums[index] += res;
- succ_counts[index]++;
- }
- }
- }
-
- static void MainThread(int index, int push_percentage) {
- for (ullong i = 0; i < s_nDequeMainPassCount; i++) {
- if ((::rand() % 100) < push_percentage) {
- int item = ::rand() % 100;
- deque->push(item);
- push_sum += item;
- push_count++;
- } else {
- int res = deque->take();
- if (res != EMPTY) {
- sums[index] += res;
- succ_counts[index]++;
- }
- }
- }
- while (true) {
- int res = deque->take();
- if (res != EMPTY) {
- sums[index] += res;
- succ_counts[index]++;
- } else {
- break;
- }
- }
- }
};
atomic_int ChaseLevDequeTest::terminate_stealer;
ullong *ChaseLevDequeTest::succ_counts;
ullong ChaseLevDequeTest::push_count;
ullong ChaseLevDequeTest::push_sum;
-Deque *ChaseLevDequeTest::deque;
TEST_F(ChaseLevDequeTest, ChaseLevDeque_push_take) {
std::unique_ptr<Deque> deque(new Deque());
class MCSLockTest : public cds_test::stress_fixture {
protected:
static ullong x;
- static cds_others::mcs_mutex *my_mutex;
static void SetUpTestCase() {
cds_test::config const &cfg = get_config("SequentialMisc");
GetConfig(MCSLockPassCount);
GetConfig(MCSLockThreadCount);
}
-
- static void Thread() {
- cds_others::mcs_mutex::guard g(my_mutex);
- my_mutex->unlock(&g);
- for (ullong i = 0; i < s_nMCSLockPassCount; i++) {
- my_mutex->lock(&g);
- x++;
- my_mutex->unlock(&g);
- }
- my_mutex->lock(&g);
- }
};
ullong MCSLockTest::x;
-cds_others::mcs_mutex *MCSLockTest::my_mutex;
TEST_F(MCSLockTest, MCSLock) {
- my_mutex = new cds_others::mcs_mutex();
- cds_others::mcs_mutex::guard g(my_mutex);
+ std::unique_ptr<cds_others::mcs_mutex> my_mutex(new cds_others::mcs_mutex());
+ cds_others::mcs_mutex::guard g(my_mutex.get());
my_mutex->unlock(&g);
for (size_t i = 0; i < s_nMCSLockPassCount; i++) {
my_mutex->lock(&g);
}
void test() {
- rigtorp::MPMCQueue<size_t> q(s_nRigtorpMPMCQueueCapacity);
+ std::unique_ptr<rigtorp::MPMCQueue<size_t>> q(
+ new rigtorp::MPMCQueue<size_t>(s_nRigtorpMPMCQueueCapacity));
size_t nNo = 0;
size_t pop_sum = 0;
size_t curr_push_count = std::min(s_nRigtorpMPMCQueuePassCount - nNo,
s_nRigtorpMPMCQueueEnqueueStride);
for (size_t i = 0; i < curr_push_count; i++) {
- q.push(nNo);
+ q->push(nNo);
++nNo;
}
for (size_t i = 0; i < curr_push_count; i++) {
size_t res;
- q.pop(res);
+ q->pop(res);
pop_sum += res;
}
}
protected:
static size_t sum;
static size_t x;
- static RWLock *rwlock;
static void SetUpTestCase() {
cds_test::config const &cfg = get_config("SequentialMisc");
GetConfig(RWLockPassCount);
}
- static void ReaderWriterThread(int write_percentage) {
+ static void ReaderWriterThread(RWLock *rwlock, int write_percentage) {
for (size_t i = 0; i < s_nRWLockPassCount; i++) {
if (rand(100) < write_percentage) {
if (rwlock->read_can_lock()) {
size_t RWLockTest::x;
size_t RWLockTest::sum;
-RWLock *RWLockTest::rwlock;
TEST_F(RWLockTest, ReadWriteLock) {
- rwlock = new RWLock();
+ std::unique_ptr<RWLock> rwlock(new RWLock());
for (int write_percentage = 5; write_percentage < 40; write_percentage += 5) {
- ReaderWriterThread(write_percentage);
+ ReaderWriterThread(rwlock.get(), write_percentage);
}
}
class SeqLockTest : public cds_test::stress_fixture {
protected:
static size_t sum;
- static SeqLock *seqlock;
static void SetUpTestCase() {
cds_test::config const &cfg = get_config("SequentialMisc");
GetConfig(SeqLockPassCount);
}
- static void ReaderWriterThread(int write_percentage) {
+ static void ReaderWriterThread(SeqLock *seqlock, int write_percentage) {
for (size_t i = 0; i < s_nSeqLockPassCount; i++) {
if (rand(100) < write_percentage) {
sum += seqlock->read();
};
size_t SeqLockTest::sum;
-SeqLock *SeqLockTest::seqlock;
TEST_F(SeqLockTest, SeqLock) {
- seqlock = new SeqLock();
+ std::unique_ptr<SeqLock> seqlock(new SeqLock());
for (int write_percentage = 5; write_percentage < 50; write_percentage += 5) {
- ReaderWriterThread(write_percentage);
+ ReaderWriterThread(seqlock.get(), write_percentage);
}
}
static size_t s_nTicketLockPassCount = 4000000;
#define TASK(lock_type, lock_ptr, pass_cnt) \
- static void Thread##lock_type() { \
+ static void Thread##lock_type(lock_type *lock_ptr) { \
for (size_t i = 0; i < pass_cnt; i++) { \
lock_ptr->lock(); \
x++; \
#define LOCK_TEST(lock_type, lock_ptr, pass_cnt) \
TEST_F(SpinLockTest, lock_type) { \
- lock_ptr = new lock_type(); \
+ std::unique_ptr<lock_type> lock_ptr(new lock_type()); \
x = 0; \
- Thread##lock_type(); \
+ Thread##lock_type(lock_ptr.get()); \
}
class SpinLockTest : public cds_test::stress_fixture {
*/
#include "../misc/common.h"
+#include "../stack/stack_type.h"
#include <cds/sync/spinlock.h>
+#include <cds/misc/RigtorpSPSCQueue.h>
namespace {
};
+atomics::atomic<int> x;
+atomics::atomic<int> y;
+typedef cds::sync::spin SpinLock;
+SpinLock l;
+
+struct value_type {
+ size_t num;
+};
+
+typedef stack::Types<value_type>::Treiber_HP stack_type;
+stack_type stack;
+rigtorp::SPSCQueue<size_t> q(10);
+
TEST_F(sequential_test, TEST) {
- typedef cds::sync::spin SpinLock;
- SpinLock l;
- l.lock();
- std::cout << "TEST\n";
- l.unlock();
+// l.lock();
+// l.unlock();
+// y.store(1, atomics::memory_order_relaxed);
+// value_type v = {1};
+// stack.push(v);
+// stack.pop(v);
+
+ q.push(1);
}
} // namespace