home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / PowerPlant / LProgressIndicator & Friends / Threads App Source / CProducerThread.cp < prev    next >
Encoding:
Text File  |  1996-04-11  |  1.6 KB  |  65 lines  |  [TEXT/CWIE]

  1. // =================================================================================
  2. //    CProducerThread.cp                     ©1996 Metrowerks Inc. All rights reserved.
  3. // =================================================================================
  4.  
  5. #include <LLink.h>
  6. #include <LSharedQueue.h>
  7.  
  8. #include "LThermometerPane.h"
  9.  
  10. #include "CProducerThread.h"
  11.  
  12.  
  13. // ---------------------------------------------------------------------------------
  14. //        • CProducerThread
  15. // ---------------------------------------------------------------------------------
  16.  
  17. CProducerThread::CProducerThread(
  18.     LSharedQueue    *inQueue,
  19.     LThermometerPane    *inProgressPane )
  20.         : LThread( false ), mQueue( inQueue ), mProgressPane( inProgressPane )
  21. {
  22. }
  23.  
  24.  
  25. // ---------------------------------------------------------------------------------
  26. //        • ~CProducerThread
  27. // ---------------------------------------------------------------------------------
  28.  
  29. CProducerThread::~CProducerThread()
  30. {
  31. }
  32.  
  33.  
  34. // ---------------------------------------------------------------------------------
  35. //        • Run
  36. // ---------------------------------------------------------------------------------
  37.  
  38. void *
  39. CProducerThread::Run( void )
  40. {
  41.     Int32    theMinValue;
  42.     Int32    theValue;
  43.     
  44.     // Get the progress bar min value.
  45.     theMinValue = mProgressPane->GetMinValue();
  46.  
  47.     // Produce as long as the progress bar isn't empty.
  48.     while ( (theValue = mProgressPane->GetCurrentValue()) > theMinValue ) {
  49.     
  50.         // Put data in the shared queue.
  51.         mQueue->NextPut( new LLink );
  52.  
  53.         // Decrement the progress bar value.
  54.         mProgressPane->SetCurrentValue( theValue - 1 );
  55.         
  56.         // Yield so that other threads may get time.
  57.         Yield();
  58.     
  59.     }
  60.  
  61.     Suspend();
  62.     
  63.     return nil;
  64. }
  65.