3 #include <cds/gc/dhp.h>
5 #include <cds/misc/seqlock.h>
6 #include <cds_test/stress_test.h>
15 typedef cds_others::SeqLock SeqLock;
17 static size_t s_nSeqLockReaderWriterThreadCount = 4;
18 static size_t s_nSeqLockPassCount = 2000000;
20 class SeqLockTest : public cds_test::stress_fixture {
23 static SeqLock *seqlock;
25 static void SetUpTestCase() {
26 cds_test::config const &cfg = get_config("Misc");
27 GetConfig(SeqLockReaderWriterThreadCount);
28 GetConfig(SeqLockPassCount);
31 static void ReaderWriterThread(int write_percentage) {
32 for (size_t i = 0; i < s_nSeqLockPassCount; i++) {
33 if (rand(100) < write_percentage) {
34 sum += seqlock->read();
36 seqlock->write(rand(10));
42 size_t SeqLockTest::sum;
43 SeqLock *SeqLockTest::seqlock;
45 TEST_F(SeqLockTest, BasicReadWriter) {
46 seqlock = new SeqLock();
47 for (int write_percentage = 5; write_percentage < 50; write_percentage += 5) {
48 std::unique_ptr<std::thread[]> threads(
49 new std::thread[s_nSeqLockReaderWriterThreadCount]);
50 for (size_t i = 0; i < s_nSeqLockReaderWriterThreadCount; i++) {
51 threads[i] = std::thread(ReaderWriterThread, write_percentage);
53 for (size_t i = 0; i < s_nSeqLockReaderWriterThreadCount; i++) {