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 {
23 static RWLock *rwlock;
25 static void SetUpTestCase() {
26 cds_test::config const &cfg = get_config("SequentialMisc");
27 GetConfig(RWLockThreadCount);
28 GetConfig(RWLockPassCount);
31 static void ReaderWriterThread(int write_percentage) {
32 for (size_t i = 0; i < s_nRWLockPassCount; i++) {
33 if (rand(100) < write_percentage) {
34 if (rwlock->read_can_lock()) {
35 if (!rwlock->read_trylock()) {
39 rwlock->read_unlock();
43 rwlock->read_unlock();
46 if (rwlock->write_can_lock()) {
47 if (!rwlock->write_trylock()) {
51 rwlock->write_unlock();
55 rwlock->write_unlock();
63 size_t RWLockTest::sum;
64 RWLock *RWLockTest::rwlock;
66 TEST_F(RWLockTest, ReadWriteLock) {
67 rwlock = new RWLock();
68 for (int write_percentage = 5; write_percentage < 40; write_percentage += 5) {
69 ReaderWriterThread(write_percentage);