Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

Consumer Class Reference

#include <PCBuffer.hpp>

Inheritance diagram for Consumer::

Basic_PThread List of all members.

Public Methods

 Consumer (int n=1)
virtual void run ()

Private Attributes

int name
size_t slotno
_uint64 started
double elapsed
double total

Static Private Attributes

int item = 0

Constructor & Destructor Documentation

Consumer::Consumer int    n = 1
 

Definition at line 128 of file PCBuffer.cpp.

00129    : Basic_PThread(), name( n ), slotno( 0 ),
00130      started( 0 ), elapsed( 0.0 ), total( 0.0 ) { }


Member Function Documentation

void Consumer::run   [virtual]
 

Reimplemented from Basic_PThread.

Definition at line 132 of file PCBuffer.cpp.

00133    {
00134      printf( "\nConsumer %u started. ", name );
00135      fixprio( 8 );
00136      sched_yield();
00137 
00138      while( item < STEPS )
00139      {
00140        message.P();                // Is there a message ?
00141 
00142        if ( item > STEPS ) break;  // Program's done
00143 
00144        receiver.P();               // Receiver take control
00145 
00146        started = timer.getCycles();
00147 
00148        ++item;
00149 
00150        char msg = boundedBuffer.dequeue(); // Consumed
00151 
00152        register size_t where = item % BBSIZE;
00153 
00154        printf( 
00155          "\nConsumer %u took message %2u from slot %2u in step %2u. ",
00156          name, msg, where, item
00157        );
00158        fflush( stdout );
00159 
00160        elapsed  = timer.getElapsed( started ); 
00161        total   += elapsed;
00162 
00163        elapsed *= 1000;
00164        printf( "\nConsumer %u took %4.2f ms. ", name, elapsed );
00165        fflush( stdout );
00166 
00167        slot[ where ]->V();  // Free the slot
00168        receiver.V();        // Release control
00169        sched_yield();
00170 
00171      } // End of infinite loop
00172 
00173      QBColor( 12 ); 
00174      printf( "\nConsumer %u terminates. Total time spent %6.2f ms. \n", name, total*1000 );
00175      QBColor();
00176      fflush( stdout );
00177 
00178      if ( item == STEPS ) {
00179        ++item; 
00180        message.V();  // Ask the other one to quit, if last step
00181      }
00182 
00183      ++done;
00184    }


Member Data Documentation

double Consumer::elapsed [private]
 

Definition at line 60 of file PCBuffer.hpp.

int Consumer::item = 0 [static, private]
 

Definition at line 68 of file PCBuffer.hpp.

int Consumer::name [private]
 

Definition at line 56 of file PCBuffer.hpp.

size_t Consumer::slotno [private]
 

Definition at line 58 of file PCBuffer.hpp.

_uint64 Consumer::started [private]
 

Definition at line 59 of file PCBuffer.hpp.

double Consumer::total [private]
 

Definition at line 61 of file PCBuffer.hpp.


The documentation for this class was generated from the following files:
Generated on Sun Oct 14 18:48:30 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001