3 #include <cds/gc/dhp.h>
5 #include <cds/misc/rwlock.h>
6 #include <cds_test/stress_test.h>
15 static size_t s_nRWLockThreadCount = 6;
16 static size_t s_nRWLockPassCount = 200000;
18 typedef cds_others::RWLock RWLock;
19 class RWLockTest : public cds_test::stress_fixture {
24 static void SetUpTestCase() {
25 cds_test::config const &cfg = get_config("SequentialMisc");
26 GetConfig(RWLockThreadCount);
27 GetConfig(RWLockPassCount);
30 static void ReaderWriterThread(RWLock *rwlock, int write_percentage) {
31 for (size_t i = 0; i < s_nRWLockPassCount; i++) {
32 if (rand(100) < write_percentage) {
33 if (rwlock->read_can_lock()) {
34 if (!rwlock->read_trylock()) {
38 rwlock->read_unlock();
42 rwlock->read_unlock();
45 if (rwlock->write_can_lock()) {
46 if (!rwlock->write_trylock()) {
50 rwlock->write_unlock();
54 rwlock->write_unlock();
62 size_t RWLockTest::sum;
64 TEST_F(RWLockTest, ReadWriteLock) {
65 std::unique_ptr<RWLock> rwlock(new RWLock());
66 for (int write_percentage = 5; write_percentage < 40; write_percentage += 5) {
67 ReaderWriterThread(rwlock.get(), write_percentage);