home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-11 | 1.9 KB | 73 lines | [TEXT/CWIE] |
- // =================================================================================
- // CConsumerThread.cp ©1996 Metrowerks Inc. All rights reserved.
- // =================================================================================
-
- #include <LLink.h>
- #include <LSharedQueue.h>
-
- #include "LThermometerPane.h"
-
- #include "CConsumerThread.h"
-
-
- // ---------------------------------------------------------------------------------
- // • CConsumerThread
- // ---------------------------------------------------------------------------------
-
- CConsumerThread::CConsumerThread(
- LSharedQueue *inQueue,
- LThermometerPane *inProgressPane )
- : LThread( false ), mQueue( inQueue ), mProgressPane( inProgressPane )
- {
- }
-
-
- // ---------------------------------------------------------------------------------
- // • ~CConsumerThread
- // ---------------------------------------------------------------------------------
-
- CConsumerThread::~CConsumerThread()
- {
- }
-
-
- // ---------------------------------------------------------------------------------
- // • Run
- // ---------------------------------------------------------------------------------
-
- void *
- CConsumerThread::Run( void )
- {
- Int32 theMaxValue;
- Int32 theValue;
-
- // Get the progress bar max value.
- theMaxValue = mProgressPane->GetMaxValue();
-
- // Consume as long as the progress bar isn't full.
- while ( (theValue = mProgressPane->GetCurrentValue()) < theMaxValue ) {
-
- // Get data from the shared queue.
- LLink *theData = mQueue->Next();
-
- // Just delete it.
- delete theData;
-
- // Increment the progress bar value.
- mProgressPane->SetCurrentValue( theValue + 1 );
-
- // Go to sleep for a while. This makes the consumer
- // a little slower than the producer so we can see
- // date in the shared queue. Try experimenting with
- // this value.
- // Note: there's no need to yield since sleeping
- // will allow other threads to get time.
- Sleep( 50 );
-
- }
-
- Suspend();
-
- return nil;
- }
-