RWLockLoopTest Class Reference

#include <rwlock_tester.h>

Inheritance diagram for RWLockLoopTest:

RWLockLoopTestImpl< RWL >

List of all members.

Public Types

enum  RWLockLoopTestMode { RWLockLoopTestRWMode = 0, RWLockLoopTestWRMode = 1 }

Public Member Functions

 RWLockLoopTest (SyncOStream &so, int loops=kPerformanceLoopsNumber)
virtual ~RWLockLoopTest ()
volatile void run (int loops, int rwratio=1)
volatile void run_rw (int loops, int rwratio=1)
volatile void run_wr (int loops, int rwratio=1)
volatile void run_r (int loops, int dummy=1)
volatile void run_w (int loops, int dummy=1)
virtual volatile void run_mixed (int loops, int rwratio=1)=0
virtual volatile MILLISECONDS read_test_loop (int loops)=0
virtual volatile MILLISECONDS write_test_loop (int loops)=0
virtual void enter_read (void)=0
virtual void leave_read (void)=0
virtual void enter_write (void)=0
virtual void leave_write (void)=0
void cslock (void)
void csunlock (void)
virtual const char * name () const =0
MILLISECONDS get_read_thread_time (void) const
MILLISECONDS get_write_thread_time (void) const
MILLISECONDS get_total_read_thread_time (void) const
MILLISECONDS get_total_write_thread_time (void) const
MILLISECONDS get_total_test_time (void) const
void mark_test_start ()
void mark_test_end ()
void clear_thread_times (void)
void clear_total_thread_time (void)
void print_thread_times (void)
void print_mixed_total (void)

Protected Attributes

SyncOStreamout
MILLISECONDS read_thread_time
MILLISECONDS write_thread_time
MILLISECONDS total_read_thread_time
MILLISECONDS total_write_thread_time
MILLISECONDS total_test_time
SystemLock sys_lock
volatile int run_count


Detailed Description

Definition at line 64 of file rwlock_tester.h.


Member Enumeration Documentation

Enumerator:
RWLockLoopTestRWMode 
RWLockLoopTestWRMode 

Definition at line 67 of file rwlock_tester.h.

00068         {
00069                 RWLockLoopTestRWMode = 0,
00070                 RWLockLoopTestWRMode = 1
00071         };


Constructor & Destructor Documentation

RWLockLoopTest::RWLockLoopTest ( SyncOStream so,
int  loops = kPerformanceLoopsNumber 
) [inline]

Definition at line 73 of file rwlock_tester.h.

virtual RWLockLoopTest::~RWLockLoopTest (  )  [inline, virtual]

Definition at line 77 of file rwlock_tester.h.

00077 {}


Member Function Documentation

volatile void RWLockLoopTest::run ( int  loops,
int  rwratio = 1 
)

Definition at line 58 of file rwlock_tester.cc.

References atomic_inc_return(), run_count, run_rw(), and run_wr().

00059 {
00060         if(atomic_inc_return(&run_count) & 1)   
00061                 run_rw(loops, rwratio);
00062         else                    
00063                 run_wr(loops, rwratio);
00064 }

volatile void RWLockLoopTest::run_rw ( int  loops,
int  rwratio = 1 
)

Definition at line 66 of file rwlock_tester.cc.

References cslock(), csunlock(), read_test_loop(), read_thread_time, total_read_thread_time, total_write_thread_time, write_test_loop(), and write_thread_time.

Referenced by run().

00067 {
00068         MILLISECONDS rthread_time = read_test_loop(loops*rwratio);
00069         MILLISECONDS wthread_time = write_test_loop(loops);
00070 
00071         cslock();
00072         read_thread_time += rthread_time;
00073         write_thread_time += wthread_time;
00074         total_read_thread_time += rthread_time;
00075         total_write_thread_time += wthread_time;
00076         csunlock();
00077 }

volatile void RWLockLoopTest::run_wr ( int  loops,
int  rwratio = 1 
)

Definition at line 79 of file rwlock_tester.cc.

References cslock(), csunlock(), read_test_loop(), read_thread_time, total_read_thread_time, total_write_thread_time, write_test_loop(), and write_thread_time.

Referenced by run().

00080 {
00081         MILLISECONDS wthread_time = write_test_loop(loops*rwratio);
00082         MILLISECONDS rthread_time = read_test_loop(loops);
00083 
00084         cslock();
00085         read_thread_time += rthread_time;
00086         write_thread_time += wthread_time;
00087         total_read_thread_time += rthread_time;
00088         total_write_thread_time += wthread_time;
00089         csunlock();
00090 }

volatile void RWLockLoopTest::run_r ( int  loops,
int  dummy = 1 
)

Definition at line 92 of file rwlock_tester.cc.

References cslock(), csunlock(), read_test_loop(), read_thread_time, and total_read_thread_time.

Referenced by main().

00093 {
00094         MILLISECONDS rthread_time = read_test_loop(loops);
00095 
00096         cslock();
00097         read_thread_time += rthread_time;
00098         total_read_thread_time += rthread_time;
00099         csunlock();
00100 }

volatile void RWLockLoopTest::run_w ( int  loops,
int  dummy = 1 
)

Definition at line 102 of file rwlock_tester.cc.

References cslock(), csunlock(), total_write_thread_time, write_test_loop(), and write_thread_time.

Referenced by main().

00103 {
00104         MILLISECONDS wthread_time = write_test_loop(loops);
00105 
00106         cslock();
00107         write_thread_time += wthread_time;
00108         total_write_thread_time += wthread_time;
00109         csunlock();
00110 }

virtual volatile void RWLockLoopTest::run_mixed ( int  loops,
int  rwratio = 1 
) [pure virtual]

Implemented in RWLockLoopTestImpl< RWL >.

Referenced by main(), and RWLockTester::run_test().

virtual volatile MILLISECONDS RWLockLoopTest::read_test_loop ( int  loops  )  [pure virtual]

virtual volatile MILLISECONDS RWLockLoopTest::write_test_loop ( int  loops  )  [pure virtual]

virtual void RWLockLoopTest::enter_read ( void   )  [pure virtual]

Implemented in RWLockLoopTestImpl< RWL >.

Referenced by RWLockTester::validate().

virtual void RWLockLoopTest::leave_read ( void   )  [pure virtual]

Implemented in RWLockLoopTestImpl< RWL >.

Referenced by RWLockTester::validate().

virtual void RWLockLoopTest::enter_write ( void   )  [pure virtual]

Implemented in RWLockLoopTestImpl< RWL >.

Referenced by RWLockTester::validate().

virtual void RWLockLoopTest::leave_write ( void   )  [pure virtual]

Implemented in RWLockLoopTestImpl< RWL >.

Referenced by RWLockTester::validate().

void RWLockLoopTest::cslock ( void   )  [inline]

Definition at line 96 of file rwlock_tester.h.

References SystemLock::lock(), and sys_lock.

Referenced by RWLockLoopTestImpl< RWL >::run_mixed(), run_r(), run_rw(), run_w(), and run_wr().

00096 { sys_lock.lock(); }

void RWLockLoopTest::csunlock ( void   )  [inline]

Definition at line 97 of file rwlock_tester.h.

References sys_lock, and SystemLock::unlock().

Referenced by RWLockLoopTestImpl< RWL >::run_mixed(), run_r(), run_rw(), run_w(), and run_wr().

00097 { sys_lock.unlock(); }

virtual const char* RWLockLoopTest::name (  )  const [pure virtual]

MILLISECONDS RWLockLoopTest::get_read_thread_time ( void   )  const [inline]

Definition at line 100 of file rwlock_tester.h.

References read_thread_time.

Referenced by print_mixed_total(), and print_thread_times().

00100 { return read_thread_time; }

MILLISECONDS RWLockLoopTest::get_write_thread_time ( void   )  const [inline]

Definition at line 101 of file rwlock_tester.h.

References write_thread_time.

Referenced by print_thread_times().

00101 { return write_thread_time; }

MILLISECONDS RWLockLoopTest::get_total_read_thread_time ( void   )  const [inline]

Definition at line 102 of file rwlock_tester.h.

References total_read_thread_time.

Referenced by RWLockTester::print_summary().

00102 { return total_read_thread_time; }

MILLISECONDS RWLockLoopTest::get_total_write_thread_time ( void   )  const [inline]

Definition at line 103 of file rwlock_tester.h.

References total_write_thread_time.

Referenced by RWLockTester::print_summary().

00103 { return total_write_thread_time; }

MILLISECONDS RWLockLoopTest::get_total_test_time ( void   )  const [inline]

Definition at line 104 of file rwlock_tester.h.

References total_test_time.

Referenced by print_mixed_total(), and print_thread_times().

00104 { return total_test_time; }

void RWLockLoopTest::mark_test_start (  ) 

Definition at line 19 of file rwlock_tester.cc.

References total_test_time.

Referenced by RWLockTester::run_test().

00020 {
00021 #ifndef WIN32
00022     struct timeval tv;
00023     struct timezone tz;
00024     memset((void*)&tz, 0, sizeof(tz));
00025     gettimeofday(&tv, &tz);
00026     total_test_time = (MILLISECONDS)tv.tv_sec * 1000 + (MILLISECONDS)tv.tv_usec / 1000;
00027 //      total_test_time = (MILLISECONDS)clock(); 
00028 #else
00029         total_test_time = (MILLISECONDS)GetTickCount();
00030 #endif
00031 }

void RWLockLoopTest::mark_test_end (  ) 

Definition at line 33 of file rwlock_tester.cc.

References total_test_time.

Referenced by RWLockTester::run_test().

00034 {
00035 //    MILLISECONDS end = clock();
00036 //    
00037 //    if(end < total_test_time)
00038 //    {
00039 //        cerr << "!!! clock round up: start=" <<  total_test_time << "; end=" << end << endl;
00040 //        assert(!"clock round up");
00041 //    }
00042 
00043 //    cout << "**** start clocks: " << total_test_time << "; End: " << end << endl;
00044 //      total_test_time = (end - total_test_time)/CLOCKS_IN_MILLISEC;
00045 //    cout << "total_test_time: " << total_test_time << endl;
00046 //    cout << "CLOCKS_IN_MILLISEC: " << CLOCKS_IN_MILLISEC << endl;
00047 #ifndef WIN32
00048     struct timeval tv;
00049     struct timezone tz;
00050     memset((void*)&tz, 0, sizeof(tz));    
00051     gettimeofday(&tv, &tz);
00052     total_test_time = (MILLISECONDS)tv.tv_sec * 1000 + (MILLISECONDS)tv.tv_usec / 1000 - total_test_time;   
00053 #else
00054         total_test_time = (MILLISECONDS)GetTickCount() - total_test_time;
00055 #endif
00056 }

void RWLockLoopTest::clear_thread_times ( void   )  [inline]

Definition at line 109 of file rwlock_tester.h.

References read_thread_time, run_count, and write_thread_time.

Referenced by RWLockTester::run_test().

void RWLockLoopTest::clear_total_thread_time ( void   )  [inline]

void RWLockLoopTest::print_thread_times ( void   ) 

Definition at line 112 of file rwlock_tester.cc.

References get_read_thread_time(), get_total_test_time(), get_write_thread_time(), SyncOStream::lock(), out, and SyncOStream::unlock().

Referenced by RWLockTester::run_test().

00113 {
00114         out.lock();
00115         out << "\tRead thread time=" 
00116                 << (unsigned long)get_read_thread_time() << " milliseconds."
00117                 << "\n\tWrite thread time=" 
00118                 << (unsigned long)get_write_thread_time() << " milliseconds."
00119                 << "\n\tTotal thread time=" 
00120                 << (unsigned long)(get_write_thread_time() + get_read_thread_time()) << " milliseconds."
00121                 << "\n\tTotal test time=" 
00122                 << (unsigned long)get_total_test_time() << " milliseconds.\n\n";
00123         out.unlock();
00124 }

void RWLockLoopTest::print_mixed_total ( void   ) 

Definition at line 125 of file rwlock_tester.cc.

References get_read_thread_time(), get_total_test_time(), SyncOStream::lock(), out, and SyncOStream::unlock().

Referenced by RWLockTester::run_test().

00126 {
00127         out.lock();
00128         out << "\tTest thread time=" 
00129                 << (unsigned long)get_read_thread_time() << " milliseconds."
00130                 << "\n\tTotal test time=" 
00131                 << (unsigned long)get_total_test_time() << " milliseconds.\n\n";
00132         out.unlock();
00133 }


Member Data Documentation

Definition at line 118 of file rwlock_tester.h.

Referenced by clear_thread_times(), get_write_thread_time(), run_rw(), run_w(), and run_wr().

Definition at line 121 of file rwlock_tester.h.

Referenced by get_total_test_time(), mark_test_end(), and mark_test_start().

Definition at line 122 of file rwlock_tester.h.

Referenced by cslock(), and csunlock().

volatile int RWLockLoopTest::run_count [protected]

Definition at line 123 of file rwlock_tester.h.

Referenced by clear_thread_times(), and run().


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

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