RWLockLoopTestImpl< RWL > Class Template Reference

#include <rwlock_tester.h>

Inheritance diagram for RWLockLoopTestImpl< RWL >:

RWLockLoopTest

List of all members.

Public Member Functions

 RWLockLoopTestImpl (SyncOStream &so, int loops=kPerformanceLoopsNumber, bool vfy=true)
volatile MILLISECONDS read_test_loop (int loops)
volatile MILLISECONDS write_test_loop (int loops)
volatile void run_mixed (int loops, int rwratio=1)
virtual void enter_read (void)
virtual void leave_read (void)
virtual void enter_write (void)
virtual void leave_write (void)
const char * name () const

Private Attributes

RWL lock
volatile int current_readers
volatile int current_writers
const bool verify


Detailed Description

template<class RWL>
class RWLockLoopTestImpl< RWL >

Definition at line 128 of file rwlock_tester.h.


Constructor & Destructor Documentation

template<class RWL>
RWLockLoopTestImpl< RWL >::RWLockLoopTestImpl ( SyncOStream so,
int  loops = kPerformanceLoopsNumber,
bool  vfy = true 
) [inline]

Definition at line 131 of file rwlock_tester.h.

00131                                                                                               : 
00132                 RWLockLoopTest(so, loops), current_readers(0), current_writers(0), verify(vfy) {}


Member Function Documentation

template<class RWL>
volatile MILLISECONDS RWLockLoopTestImpl< RWL >::read_test_loop ( int  loops  )  [inline, virtual]

Implements RWLockLoopTest.

Definition at line 271 of file rwlock_tester.h.

References atomic_dec(), atomic_inc(), CLOCKS_IN_MILLISEC, RWLockLoopTestImpl< RWL >::current_readers, RWLockLoopTestImpl< RWL >::current_writers, kLoopYields, SyncOStream::lock(), RWLockLoopTestImpl< RWL >::lock, RWLockLoopTestImpl< RWL >::name(), RWLockLoopTest::out, thread_yield(), SyncOStream::unlock(), and RWLockLoopTestImpl< RWL >::verify.

00272 {
00273     int yield_point = loops / kLoopYields;
00274         CLOCK_T start = CLOCK_T(clock());
00275         for(int i=0; i<loops; i++)
00276         {
00277                 lock.enter_read();
00278 
00279         int tmp = current_writers;
00280 
00281         atomic_inc(&current_readers);
00282 
00283        if((i % yield_point) == 0) thread_yield();
00284         
00285 //        SystemSleep(SLEEP_MSEC);
00286         
00287         if(verify && tmp != 0)
00288                 {
00289                         out.lock();
00290                         out << "\n\nRW lock " << name() << " current_writers != 0 : " << tmp << "\n";
00291                         out.unlock();
00292                         exit(-1);
00293                 }
00294         
00295                 atomic_dec(&current_readers);
00296 
00297         lock.leave_read();
00298         }
00299         CLOCK_T finish = CLOCK_T(clock());
00300     if(finish < start)
00301     {
00302         cerr << "!!! clock round up: start=" << start << "; end=" << finish << "; loops=" << loops << endl;
00303         assert(!"clock round up");
00304     }
00305         return (finish - start)/CLOCKS_IN_MILLISEC;
00306 }

template<class RWL>
volatile MILLISECONDS RWLockLoopTestImpl< RWL >::write_test_loop ( int  loops  )  [inline, virtual]

Implements RWLockLoopTest.

Definition at line 308 of file rwlock_tester.h.

References atomic_dec(), atomic_inc(), CLOCKS_IN_MILLISEC, RWLockLoopTestImpl< RWL >::current_readers, RWLockLoopTestImpl< RWL >::current_writers, kLoopYields, SyncOStream::lock(), RWLockLoopTestImpl< RWL >::lock, RWLockLoopTestImpl< RWL >::name(), RWLockLoopTest::out, thread_yield(), SyncOStream::unlock(), and RWLockLoopTestImpl< RWL >::verify.

00309 {
00310     int yield_point = loops / kLoopYields;
00311         CLOCK_T start = CLOCK_T(clock());
00312         for(int i=0; i<loops; i++)
00313         {
00314                 lock.enter_write();
00315 
00316         int tmp = current_readers;
00317 
00318         if((i % yield_point) == 0) thread_yield();
00319         
00320         if(verify && tmp != 0)
00321                 {
00322                         out.lock();
00323                         out << "\n\nRW lock " << name() << " current_readers != 0 : " << tmp << "\n";
00324                         out.unlock();
00325                         exit(-12);
00326                 }
00327 
00328         atomic_inc(&current_writers);
00329         
00330 
00331 //        SystemSleep(SLEEP_MSEC);
00332         
00333                 if(verify && current_writers != 1)
00334                 {
00335                         out.lock();
00336                         out << "\n\nRW lock " << name() << " current_writers != 1 : " << current_writers << "\n";
00337                         out.unlock();
00338                         exit(-2);
00339                 }
00340 
00341         atomic_dec(&current_writers);
00342         
00343                 lock.leave_write();
00344         }
00345         CLOCK_T finish = CLOCK_T(clock());
00346     if(finish < start)
00347     {
00348         cerr << "!!! clock round up: start=" << start << "; end=" << finish << "; loops=" << loops << endl;
00349         assert(!"clock round up");
00350     }
00351         return (finish - start)/CLOCKS_IN_MILLISEC;
00352 }

template<class RWL>
volatile void RWLockLoopTestImpl< RWL >::run_mixed ( int  loops,
int  rwratio = 1 
) [inline, virtual]

Implements RWLockLoopTest.

Definition at line 354 of file rwlock_tester.h.

References atomic_dec(), atomic_inc(), CLOCKS_IN_MILLISEC, RWLockLoopTest::cslock(), RWLockLoopTest::csunlock(), RWLockLoopTestImpl< RWL >::current_readers, RWLockLoopTestImpl< RWL >::current_writers, kLoopYields, SyncOStream::lock(), RWLockLoopTestImpl< RWL >::lock, RWLockLoopTestImpl< RWL >::name(), RWLockLoopTest::out, RWLockLoopTest::read_thread_time, thread_yield(), RWLockLoopTest::total_read_thread_time, SyncOStream::unlock(), and RWLockLoopTestImpl< RWL >::verify.

00355 {
00356         MILLISECONDS thread_time;
00357     int yield_point = loops / kLoopYields;
00358         CLOCK_T start = CLOCK_T(clock());
00359         for(int i=0; i<loops; i++)
00360         {
00361                 for(int j=0; j<rwratio; j++)
00362                 {
00363                         lock.enter_read();
00364             
00365                         int tmp = current_writers;
00366                         atomic_inc(&current_readers);
00367                         if(verify && tmp != 0)
00368                         {
00369                                 out.lock();
00370                                 out << "\n\nRW lock " << name() << " current_writers != 0 : " << tmp << "\n";
00371                                 out.unlock();
00372                                 exit(-1);
00373                         }
00374   //          SystemSleep(SLEEP_MSEC);
00375   //          thread_yield();
00376                         atomic_dec(&current_readers);
00377             
00378                         lock.leave_read();
00379                 }
00380                 lock.enter_write();
00381                 int tmp = current_readers;
00382                 if(verify && tmp != 0)
00383                 {
00384                         out.lock();
00385                         out << "\n\nRW lock " << name() << " current_readers != 0 : " << tmp << "\n";
00386                         out.unlock();
00387                         exit(-12);
00388                 }
00389                 atomic_inc(&current_writers);
00390                 if(verify && current_writers != 1)
00391                 {
00392                         out.lock();
00393                         out << "\n\nRW lock " << name() << " current_writers != 1 : " << current_writers << "\n";
00394                         out.unlock();
00395                         exit(-2);
00396                 }
00397 
00398         if((i % yield_point) == 0) thread_yield();
00399 
00400 //        SystemSleep(SLEEP_MSEC);
00401                 atomic_dec(&current_writers);
00402                 lock.leave_write();
00403         }
00404         CLOCK_T finish = CLOCK_T(clock());
00405 
00406     if(finish < start)
00407     {
00408         cerr << "!!! clock round up: start=" << start << "; end=" << finish << "; loops=" << loops << endl;
00409         assert(!"clock round up");
00410     }
00411     
00412         thread_time = (finish - start)/CLOCKS_IN_MILLISEC;
00413 
00414         cslock();
00415         read_thread_time += thread_time;
00416         total_read_thread_time += thread_time;
00417         csunlock();
00418 }

template<class RWL>
virtual void RWLockLoopTestImpl< RWL >::enter_read ( void   )  [inline, virtual]

Implements RWLockLoopTest.

Definition at line 139 of file rwlock_tester.h.

References RWLockLoopTestImpl< RWL >::lock.

00139 {lock.enter_read();}

template<class RWL>
virtual void RWLockLoopTestImpl< RWL >::leave_read ( void   )  [inline, virtual]

Implements RWLockLoopTest.

Definition at line 140 of file rwlock_tester.h.

References RWLockLoopTestImpl< RWL >::lock.

00140 {lock.leave_read();}

template<class RWL>
virtual void RWLockLoopTestImpl< RWL >::enter_write ( void   )  [inline, virtual]

Implements RWLockLoopTest.

Definition at line 141 of file rwlock_tester.h.

References RWLockLoopTestImpl< RWL >::lock.

00141 {lock.enter_write();}

template<class RWL>
virtual void RWLockLoopTestImpl< RWL >::leave_write ( void   )  [inline, virtual]

Implements RWLockLoopTest.

Definition at line 142 of file rwlock_tester.h.

References RWLockLoopTestImpl< RWL >::lock.

00142 {lock.leave_write();}

template<class RWL>
const char* RWLockLoopTestImpl< RWL >::name (  )  const [inline, virtual]


Member Data Documentation

template<class RWL>
RWL RWLockLoopTestImpl< RWL >::lock [private]

template<class RWL>
volatile int RWLockLoopTestImpl< RWL >::current_readers [private]

template<class RWL>
volatile int RWLockLoopTestImpl< RWL >::current_writers [private]

template<class RWL>
const bool RWLockLoopTestImpl< RWL >::verify [private]


The documentation for this class was generated from the following file:

Generated on Wed Mar 19 14:59:59 2008 for rwlock by  doxygen 1.5.5