// $Revision: 1.9 $ // Copyright (C) 1995 Taligent, Inc. All rights reserved. #if 0 --------------------------------------------------------------------------- > Class: | TBoundThreadProgram > Taxonomy Category: | ConcurrentGraphics | LocalUtilities > Interface Category: | Sample. > Inherits From: | None. > Inherited By: | TPeriodicThread | TUniverseThread > Purpose: | This call provides the facility to create a thread whose state does not get discarded even after the thread itself terminates. > Instantiation: | Allocate on the heap or the stack. > Deriving Classes: | TPeriodicThread, TUniverseThread. > Concurrency: | Multithread safe. > Resource Use: | No special requirements. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TBoundThreadProgram::TBoundThreadProgram ; | TBoundThreadProgram () > Interface Category: | Sample. > Purpose: | Default constructor. > Calling Context: | Called by derived class. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | None. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TBoundThreadProgram::Start ; | virtual void Start () > Interface Category: | Sample. > Purpose: | Begins execution of program. Before execution begins, BoundPrepare is called. Then the thread is started and BoundRun is called from within the new thread. > Calling Context: | Called by clients. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | If the program is already running, it is terminated (a call is made to Terminate) before it is restarted. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TBoundThreadProgram::Terminate ; | virtual void Terminate () > Interface Category: | Sample. > Purpose: | Requests an orderly termination of the program. Terminate calls BoundExit in order to accomplish this. Terminate does not return until after the thread has been successfully terminated. > Calling Context: | Called by clients and by Start if thread is already running when Start is called. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | If Terminate throws an exception, the thread might not have terminated. The exact policy is determined by derived classes. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TBoundThreadProgram::BoundPrepare ; | virtual void BoundPrepare () > Interface Category: | Sample. > Purpose: | Allows derived class to do initialization (or re-initialization) before the program is started. By default, this member function does nothing. > Calling Context: | Called by Start before program execution begins. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | Because BoundPrepare is called before the program thread is created, BoundPrepare runs in the calling thread's context. The calling thread does not regain control until BoundPrepare returns. As a result, BoundPrepare should do the minimum amount of work necessary to initialize the program so as not to overburden the calling thread. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TBoundThreadProgram::BoundExit ; | virtual void BoundExit () > Interface Category: | Sample. > Purpose: | Derived classes should override and perform whatever actions are needed to terminate the program. This could be as simple as setting a flag to indicate that the main program should exit. > Calling Context: | Called by Terminate. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | If BoundExit does not set up proper termination conditions, the Terminate member function (which calls BoundExit) will never return, effectively locking up the caller of Terminate. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TBoundThreadProgram::BoundRun ; | virtual void BoundRun () > Interface Category: | Sample. > Purpose: | BoundRun is the main body of the program. The program's thread is deleted when BoundRun exits (returns to its caller). > Calling Context: | Called by new thread. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | Generally, exceptions should not be allowed to pass out of the BoundRun member function, because there are no handlers for them. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TBoundThreadProgram::~ TBoundThreadProgram ; | virtual ~ TBoundThreadProgram () > Interface Category: | Sample. > Purpose: | Destructor. > Calling Context: | Called to destroy an object. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | None. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Class: | TPeriodicThread > Taxonomy Category: | ConcurrentGraphics | LocalUtilities > Interface Category: | Sample. > Inherits From: | TBoundThreadProgram > Inherited By: | TMoverThread | TRefreshThread > Purpose: | TPeriodicThread provides a TBoundThreadProgram which loops and calls an internal member function to do processing after a specified delay. Periodic threads can be paused and resumed without loosing track of time delayed. > Instantiation: | Allocate on the heap or the stack. > Deriving Classes: | TMoverThread, TRefreshThread. > Concurrency: | Multithread safe. > Resource Use: | No special requirements. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPeriodicThread::TPeriodicThread ; | TPeriodicThread () > Interface Category: | Sample. > Purpose: | Default constructor. > Calling Context: | Called by derived classes. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | None. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPeriodicThread::Pause ; | virtual void Pause () > Interface Category: | Sample. > Purpose: | Stops thread processing until Resume is called. > Calling Context: | Called by clients. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | Even while paused, a TPeriodicThread's timer continues to run. Resume should be called as soon as possible so processing can continue. Each call to pause _must_ be matched by a call to Resume. A paused TPeriodicThread will not terminate until its Resume member function is called. Use the TPeriodicThreadEntry class to ensure a paused thread is always resumed. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPeriodicThread::Resume ; | virtual void Resume () > Interface Category: | Sample. > Purpose: | Allow a paused thread to continue processing. > Calling Context: | Called by clients. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | There should only be one call to Resume for each call to Pause. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPeriodicThread::CheckInterval ; | virtual void CheckInterval () > Interface Category: | Sample. > Purpose: | Informs the thread that the length of the current interval may have changed. > Calling Context: | Called by derived classes. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | None. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPeriodicThread::BoundPrepare ; | virtual void BoundPrepare () > Interface Category: | Sample. > Purpose: | Sets flag indicating program has started. > Calling Context: | Called by base class. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | None. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPeriodicThread::BoundRun ; | virtual void BoundRun () > Interface Category: | Sample. > Purpose: | Calls HandleIntervalPassed at most once per delay interval. > Calling Context: | Called by base class. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | None. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPeriodicThread::BoundExit ; | virtual void BoundExit () > Interface Category: | Sample. > Purpose: | Performs an orderly exit from the thread. If the thread is currently doing processing, processing is allowed to complete before the thread terminates. > Calling Context: | Called by base class. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | If the thread is currently paused, this member function will not return until the thread is resumed. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPeriodicThread::GetDelayInterval ; | virtual void GetDelayInterval (TTime & interval) const > Interface Category: | Sample. > Purpose: | Derived classes return the length of the next delay interval. Derived classes _do_ _not_ have to take processing time into account. > Calling Context: | Called by BoundRun. > Parameters: = TTime & interval -If the length of the delay interval has changed, derived classes should assign the length of the next interval to the interval parameter. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | None. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPeriodicThread::HandleIntervalPassed ; | virtual void HandleIntervalPassed (const TTime & interval) > Interface Category: | Sample. > Purpose: | Overridden by derived classes to perform periodic processing. > Calling Context: | Called by BoundRun. > Parameters: = const TTime & interval -The amount of time that has passed since the last time HandleIntervalPassed was called. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | The length of time that has passed is guaranteed to be at least the length specified by GetDelayInterval. The actual length of time will vary due to system load and calls to the Pause member function. derived classes should base their processing off the interval parameter rather than keeping track of time themselves. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPeriodicThread::~ TPeriodicThread ; | virtual ~ TPeriodicThread () > Interface Category: | Sample. > Purpose: | Destructor. > Calling Context: | Called to destroy an object. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | A periodic thread should _always_ be terminated before it is destructed. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Class: | TPeriodicThreadEntry > Taxonomy Category: | ConcurrentGraphics | LocalUtilities > Interface Category: | Sample. > Inherits From: | None. > Inherited By: | None. > Purpose: | Provides an exception-safe way to pause a TPeriodicThread. The thread always resumes, even if an exception goes ripping through the routine that paused it. > Instantiation: | Always allocate on the stack. > Deriving Classes: | None. > Concurrency: | Multithread safe. > Resource Use: | The paused TPeriodicThread must exist when the destructor is run. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPeriodicThreadEntry::TPeriodicThreadEntry ; | TPeriodicThreadEntry (TPeriodicThread * thread) > Interface Category: | Sample. > Purpose: | Pauses the thread. > Calling Context: | Called at construction time. > Parameters: = TPeriodicThread * thread -Thread to pause. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | A TPeriodicThreadEntry should always be named, so its scope is determined properly. For example: | TPeriodicThreadEntry _entry_(someThread); | A declaration such as: | TPeriodicThreadEntry(someThread); //the entry is not named | may be legally optimized away because the compiler and the thread will not be properly paused. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPeriodicThreadEntry::~ TPeriodicThreadEntry ; | virtual ~ TPeriodicThreadEntry () > Interface Category: | Sample. > Purpose: | Destructor. Resumes the thread. > Calling Context: | Called to destroy an object. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | The paused TPeriodicThread must exist when the destructor is run. If the program is allocated locally on the stack, the TPeriodicThreadEntry should be in a subscope. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Class: | TPrimPCQueue > Taxonomy Category: | ConcurrentGraphics | LocalUtilities > Interface Category: | Sample. > Inherits From: | None. > Inherited By: | TPCQueue > Purpose: | Provides a typeless implementation for a multithread safe queue (FIFO). > Instantiation: | Allocate on the heap or the stack. > Deriving Classes: | TPCQueue. > Concurrency: | Multithread safe. > Resource Use: | No special requirements. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPrimPCQueue::TPrimPCQueue ; | TPrimPCQueue (unsigned long maxSize =LONG_MAX) > Interface Category: | Sample. > Purpose: | Constructs a queue that will hold no more than the specified maximum number of elements. > Calling Context: | Called by derived classes. > Parameters: = unsigned long maxSize =LONG_MAX -Maximum number of elements that can be in the queue at any given time. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | None. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPrimPCQueue::Count ; | unsigned long Count () const > Interface Category: | Sample. > Purpose: | Returns number of elements currently in the queue. > Calling Context: | Called internally and by clients. > Parameters: = Takes no parameters. > Return Value: | Number of elements currently in the queue. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | If a thread other than the calling thread adds or removes elements from the queue, the count may not be accurate. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPrimPCQueue::Close ; | void Close () > Interface Category: | Sample. > Purpose: | Close the queue so items may no longer be inserted into the queue. > Calling Context: | Called by clients and destructor. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | None. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPrimPCQueue::Reopen ; | void Reopen () > Interface Category: | Sample. > Purpose: | Reopens a queue previously closed by Close so items can again be inserted into the queue. > Calling Context: | Called by clients. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | None. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPrimPCQueue::RemoveAll ; | void RemoveAll () > Interface Category: | Sample. > Purpose: | Removes all items currently in the queue. > Calling Context: | Called by clients and destructor. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | None. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPrimPCQueue::DeleteAll ; | void DeleteAll () > Interface Category: | Sample. > Purpose: | Deletes all elements currently in the queue. > Calling Context: | Called by clients. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | This function calls DoDelete to delete each element in the queue. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPrimPCQueue::PAdd ; | void PAdd (void * item) > Interface Category: | Sample. > Purpose: | Adds an element to the queue. > Calling Context: | Called by derived classes. > Parameters: = void * item -Item to add to queue. > Return Value: | None. > Exceptions: | Throws TProducerConsumerQueueClosed exception if the queue is closed. > Concurrency: | Multithread safe. > Other Considerations: | The calling thread may block if the queue has reached its maximum size (specified in the constructor). The thread unblocks when an item is removed or the queue is closed. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPrimPCQueue::PRemoveNext ; | void * PRemoveNext () > Interface Category: | Sample. > Purpose: | Removes the next element from the queue. > Calling Context: | Called by derived classes. > Parameters: = Takes no parameters > Return Value: | Returns next element in queue. > Exceptions: | Throws TProducerConsumerQueueClosed exception if the queue is empty and closed. > Concurrency: | Multithread safe. > Other Considerations: | The calling thread will block if the queue is open and empty. It will become unblocked when an item is inserted in the queue or the queue is closed. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPrimPCQueue::~ TPrimPCQueue ; | virtual ~ TPrimPCQueue () > Interface Category: | Sample. > Purpose: | Destructor. > Calling Context: | Called to destroy an object. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | The queue is closed and all items in the queue are removed (using RemoveAll) during destruction. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPrimPCQueue::IsOpen ; | bool IsOpen () const > Interface Category: | Sample. > Purpose: | Tests to see if items can be inserted into the queue. > Calling Context: | Called by clients. > Parameters: = Takes no parameters. > Return Value: | Returns true if items may be inserted into the queue. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | If a thread other than the calling thread opens or closes the queue, the result may not be accurate. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Class: | TPCQueue > Taxonomy Category: | ConcurrentGrpahics | Local Utlities > Interface Category: | Sample. > Inherits From: | TPrimPCQueue > Inherited By: | None. > Purpose: | Provides a typesafe interface to TPrimPCQueue class functionality. > Instantiation: | Allocate on the heap or the stack. > Deriving Classes: | None. > Concurrency: | Multithread safe. > Resource Use: | No special requirements. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPCQueue::TPCQueue ; | TPCQueue (unsigned long maxSize =LONG_MAX) > Interface Category: | Sample. > Purpose: | Constructs a queue that holds no more than the specified maximum number of elements. > Calling Context: | Called by clients. > Parameters: = unsigned long maxSize =LONG_MAX -Maximum number of elements that can be in the queue at any given time. Default is unbounded. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | None. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPCQueue::~ TPCQueue ; | virtual ~ TPCQueue () > Interface Category: | Sample. > Purpose: | Destructor. > Calling Context: | Called to destroy an object. > Parameters: = Takes no parameters. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | None. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPCQueue::RemoveNext ; | AType * RemoveNext () > Interface Category: | Sample. > Purpose: | Removes the next item from the queue. > Calling Context: | Called by clients. > Parameters: = Takes no parameters. > Return Value: | Next item in the queue. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | Calls TPrimPCQueue::PRemove. --------------------------------------------------------------------------- #endif #if 0 --------------------------------------------------------------------------- > Member Function: TPCQueue::Add ; | void Add (AType * item) > Interface Category: | Sample. > Purpose: | Adds an item to the queue. > Calling Context: | Called by clients. > Parameters: = AType * item -Item to add to the queue. > Return Value: | None. > Exceptions: | Throws no exceptions, passes all exceptions through. > Concurrency: | Multithread safe. > Other Considerations: | Calls TPrimPCQueue::PAdd. --------------------------------------------------------------------------- #endif