home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-19 | 3.1 KB | 105 lines | [TEXT/CWIE] |
- // =================================================================================
- // CThreadWindow.cp ©1996 Metrowerks Inc. All rights reserved.
- // =================================================================================
-
- #include <LLink.h>
- #include <LSharedQueue.h>
- #include <LStream.h>
-
- #include "ThreadsConstants.h"
- #include "CConsumerThread.h"
- #include "CProducerThread.h"
- #include "LThermometerPane.h"
- #include "CVisualSharedQueue.h"
-
- #include "CThreadWindow.h"
-
-
- // ---------------------------------------------------------------------------------
- // • CreateThreadWindowStream [static]
- // ---------------------------------------------------------------------------------
-
- CThreadWindow *
- CThreadWindow::CreateThreadWindowStream(
- LStream *inStream )
- {
- return new CThreadWindow( inStream );
- }
-
-
- // ---------------------------------------------------------------------------------
- // • CThreadWindow(LStream*)
- // ---------------------------------------------------------------------------------
-
- CThreadWindow::CThreadWindow(
- LStream *inStream )
- : LWindow( inStream ), mSharedQueue( nil ),
- mProducerThread( nil ), mConsumerThread( nil )
- {
- }
-
-
- // ---------------------------------------------------------------------------------
- // • ~CThreadWindow
- // ---------------------------------------------------------------------------------
-
- CThreadWindow::~CThreadWindow()
- {
- // Delete the producer thread.
- // if ( mProducerThread != nil ) mProducerThread->DeleteThread();
-
- // Delete the consumer thread.
- // if ( mConsumerThread != nil ) mConsumerThread->DeleteThread();
-
- if ( mSharedQueue != nil ) {
-
- // Delete remaining items in the queue. Use NextGet instead
- // of Next to avoid the semaphore behavior of the shared queue.
- // Note: another way to do this is with an LQueueIterator proc.
- LLink *theLink;
- while ( (theLink = mSharedQueue->NextGet()) != nil ) delete theLink;
-
- // Delete the queue.
- delete mSharedQueue;
-
- }
- }
-
-
- // ---------------------------------------------------------------------------------
- // • FinishCreateSelf
- // ---------------------------------------------------------------------------------
-
- void
- CThreadWindow::FinishCreateSelf()
- {
- // Get the queue's progress pane.
- LThermometerPane *theProgressPane;
- theProgressPane = (LThermometerPane *) FindPaneByID( kSharedQueueProgressPane );
- Assert_( theProgressPane != nil );
-
- // Create the shared queue.
- mSharedQueue = new CVisualSharedQueue( theProgressPane );
- ThrowIfNil_( mSharedQueue );
-
- // Get the producer's progress pane.
- theProgressPane = (LThermometerPane *) FindPaneByID( kProducerProgressPane );
- Assert_( theProgressPane != nil );
-
- // Create the producer thread.
- mProducerThread = new CProducerThread( mSharedQueue, theProgressPane );
- ThrowIfNil_( mProducerThread );
-
- // Get the consumer's progress pane.
- theProgressPane = (LThermometerPane *) FindPaneByID( kConsumerProgressPane );
- Assert_( theProgressPane != nil );
-
- // Create the consumer thread.
- mConsumerThread = new CConsumerThread( mSharedQueue, theProgressPane );
- ThrowIfNil_( mConsumerThread );
-
- // Start the threads.
- mProducerThread->Resume();
- mConsumerThread->Resume();
- }
-