X-Git-Url: http://plrg.eecs.uci.edu/git/?p=libcds.git;a=blobdiff_plain;f=test%2Fstress%2Fmisc%2Fspinlock_driver.cpp;h=b1b0e95cbe65771a35e854d127abf43c43126419;hp=a8d4923f0b6a3426a24ee53faa2330d1985298df;hb=197419a18f00be2e7478e07ab03025856cd5bf34;hpb=df58fae11f80f03ca5b50c800f2978b1ff08efea diff --git a/test/stress/misc/spinlock_driver.cpp b/test/stress/misc/spinlock_driver.cpp index a8d4923f..b1b0e95c 100644 --- a/test/stress/misc/spinlock_driver.cpp +++ b/test/stress/misc/spinlock_driver.cpp @@ -1,64 +1,77 @@ +#include "common.h" #include #include #include #include +#include #include #include +#include #include using namespace std; namespace { +typedef cds_others::TicketLock TicketLock; typedef cds::sync::spin SpinLock; typedef cds::sync::reentrant_spin32 Reentrant32; typedef cds::sync::reentrant_spin64 Reentrant64; +static size_t s_nSpinLockThreadCount = 6; +static size_t s_nSpinLockPassCount = 2500000000; +static size_t s_nTicketLockPassCount = 4000000; -#define TASK(lock_type, lock_ptr) \ - static void Thread ## lock_type() { \ - for (int i = 0; i < 100000; i++) { \ - for (int j = 0; j < 30000; j++) { \ - lock_ptr->lock(); \ - x = i + j; \ - lock_ptr->unlock(); \ - } \ - } \ +#define TASK(lock_type, lock_ptr, pass_cnt) \ + static void Thread##lock_type() { \ + for (int i = 0; i < pass_cnt; i++) { \ + for (int j = 0; j < pass_cnt; j++) { \ + lock_ptr->lock(); \ + x = i + j; \ + lock_ptr->unlock(); \ + } \ + } \ } -#define LOCK_TEST(lock_type, lock_ptr) \ - TEST_F(SpinLockTest, lock_type) { \ - lock_ptr = new lock_type(); \ - std::thread threads[kThreads]; \ - for (int i = 0; i < kThreads; i++) { \ - threads[i] = std::thread(Thread ## lock_type); \ - } \ - for (int i = 0; i < kThreads; i++) { \ - threads[i].join(); \ - } \ -} +#define LOCK_TEST(lock_type, lock_ptr) \ + TEST_F(SpinLockTest, lock_type) { \ + lock_ptr = new lock_type(); \ + std::thread *threads = new std::thread[s_nSpinLockThreadCount]; \ + for (int i = 0; i < s_nSpinLockThreadCount; i++) { \ + threads[i] = std::thread(Thread##lock_type); \ + } \ + for (int i = 0; i < s_nSpinLockThreadCount; i++) { \ + threads[i].join(); \ + } \ + } class SpinLockTest : public cds_test::stress_fixture { protected: static int x; - static SpinLock* spin_mutex; - static Reentrant32* reentrant_mutex32; - static Reentrant64* reentrant_mutex64; + static TicketLock *ticket_mutex; + static SpinLock *spin_mutex; + static Reentrant32 *reentrant_mutex32; + static Reentrant64 *reentrant_mutex64; - static const int kThreads = 6; - - static void SetUpTestCase() {} + static void SetUpTestCase() { + cds_test::config const &cfg = get_config("Misc"); + GetConfig(SpinLockThreadCount); + GetConfig(SpinLockPassCount); + GetConfig(TicketLockPassCount); + } - TASK(SpinLock, spin_mutex) - TASK(Reentrant32, reentrant_mutex32) - TASK(Reentrant64, reentrant_mutex64) + TASK(TicketLock, ticket_mutex, s_nTicketLockPassCount) + TASK(SpinLock, spin_mutex, s_nSpinLockPassCount) + TASK(Reentrant32, reentrant_mutex32, s_nSpinLockPassCount) + TASK(Reentrant64, reentrant_mutex64, s_nSpinLockPassCount) }; int SpinLockTest::x; -const int SpinLockTest::kThreads; -SpinLock* SpinLockTest::spin_mutex; -Reentrant32* SpinLockTest::reentrant_mutex32; -Reentrant64* SpinLockTest::reentrant_mutex64; +TicketLock *SpinLockTest::ticket_mutex; +SpinLock *SpinLockTest::spin_mutex; +Reentrant32 *SpinLockTest::reentrant_mutex32; +Reentrant64 *SpinLockTest::reentrant_mutex64; +LOCK_TEST(TicketLock, ticket_mutex) LOCK_TEST(SpinLock, spin_mutex) LOCK_TEST(Reentrant32, reentrant_mutex32) LOCK_TEST(Reentrant64, reentrant_mutex64)