2 #include <cds/gc/dhp.h>
4 #include <cds/sync/seqlock.h>
5 #include <cds_test/stress_test.h>
13 typedef cds_others::SeqLock SeqLock;
15 class SeqLockTest : public cds_test::stress_fixture {
18 static SeqLock *seqlock;
19 static const int kReaderThreads = 0;
20 static const int kWriterThreads = 0;
21 static const int kReaderWriterThreads = 6;
22 static const int kWriterPercentage = 15;
23 static const int kPassCount = 15000;
25 static void SetUpTestCase() {}
27 static void ReaderThread() {}
29 static void WriterThread() {}
31 static void ReaderWriterThread() {
32 for (int i = 0; i < kPassCount; i++) {
33 for (int j = 0; j < kPassCount; j++) {
34 if (rand(100) < kWriterPercentage) {
35 sum += seqlock->read();
37 seqlock->write(rand(10));
45 SeqLock *SeqLockTest::seqlock;
46 const int SeqLockTest::kReaderThreads;
47 const int SeqLockTest::kWriterThreads;
48 const int SeqLockTest::kReaderWriterThreads;
50 TEST_F(SeqLockTest, BasicReadWriter) {
51 seqlock = new SeqLock();
52 int num_threads = kReaderThreads + kWriterThreads + kReaderWriterThreads;
53 std::thread *threads = new std::thread[num_threads];
54 for (int i = 0; i < kReaderThreads; i++) {
55 threads[i] = std::thread(ReaderThread);
57 for (int i = kReaderThreads; i < (kReaderThreads + kWriterThreads); i++) {
58 threads[i] = std::thread(WriterThread);
60 for (int i = (kReaderThreads + kWriterThreads); i < num_threads; i++) {
61 threads[i] = std::thread(ReaderWriterThread);
64 for (int i = 0; i < num_threads; i++) {