Class: TProducerConsumerQueue

Declaration: ProducerConsumer.h

Taxonomy Categories:

Member Functions:


Interface Category:

API.

Inherits From:

None.

Inherited By:

TStandardProducerConsumerQueue

Purpose:

The producer consumer queue is a multithread-safe queue. Producers post objects to the queue while consumers remove those objects. This provides the interface only; the implementation is provided by derived classes.

Instantiation:

Allocate on the heap or the stack.

Deriving Classes:

This class may be derived to provide concrete implementation of a producer/consumer queue.

Concurrency:

Multithread safe.

Resource Use:

The queue does not own any of the objects on its queue and does not delete them if it is deleted.

Member Function: TProducerConsumerQueue::~TProducerConsumerQueue

virtual ~ TProducerConsumerQueue ()

Interface Category:

API.

Purpose:

Destructor. The queue does not own any of the objects on its queue and does not delete them if it is deleted.

Calling Context:

Called to destroy an object. Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Multithread safe.

Other Considerations:

None.

Member Function: TProducerConsumerQueue::Add

void Add (MCollectible *)

Interface Category:

API.

Purpose:

Adds an object to the queue. If the queue is full, then this blocks until there is room on the queue for the object. It the queue is closed or becomes closed, then an exception is thrown.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws TProducerConsumerQueueClosed if the queue has been closed already.

Concurrency:

Multithread safe.

Other Considerations:

None.

Member Function: TProducerConsumerQueue::RemoveNext

MCollectible * RemoveNext ()

Interface Category:

API.

Purpose:

Removes an object from the queue. This returns the next object or blocks until an object has been added or the queue has been closed. If the queue is closed or becomes closed, then an exception is thrown.

Calling Context:

Call this function directly.

Parameters:

Return Value:

Returns the next available object.

Exceptions:

Throws TProducerConsumerQueueClosed if the queue has been closed

Concurrency:

Multithread safe.

Other Considerations:

None.

Member Function: TProducerConsumerQueue::Close

void Close ()

Interface Category:

API.

Purpose:

Closes the queue. It no longer accepts objects added to its queue and does not allow any objects to be removed. Objects that are currently on the queue remain.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Multithread safe.

Other Considerations:

None.

Member Function: TProducerConsumerQueue::Reopen

void Reopen ()

Interface Category:

API.

Purpose:

Reopens the queue. It accepts objects added to its queue and allows any objects to be removed. Objects that were currently on the queue are able to be removed.

Calling Context:

Call this function directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Multithread safe.

Other Considerations:

None.

Member Function: TProducerConsumerQueue::Count

unsigned long Count () const

Interface Category:

API.

Purpose:

Determines the number of objects on the queue.

Calling Context:

Call this function directly.

Parameters:

Return Value:

Returns the number of objects on the queue.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Multithread safe.

Other Considerations:

None.

Member Function: TProducerConsumerQueue::TProducerConsumerQueue

TProducerConsumerQueue ()

Interface Category:

API.

Purpose:

Default constructor.

Calling Context:

Called by the stream-in operators and directly.

Parameters:

Return Value:

None.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Multithread safe.

Other Considerations:

None.

Member Function: TProducerConsumerQueue::HandleAdd

virtual bool HandleAdd (MCollectible *)

Interface Category:

API.

Purpose:

This member function must be overridden in derived classes. It should add the object to its internal collection of objects. The implementation is left up to the derived class.

Calling Context:

Call this function directly.

Parameters:

Return Value:

Returns true if the object was successfully added.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Multithread safe.

Other Considerations:

None.

Member Function: TProducerConsumerQueue::HandleRemoveNext

virtual MCollectible * HandleRemoveNext ()

Interface Category:

API.

Purpose:

Removes the next object from the queue.

Calling Context:

Call this function directly.

Parameters:

Return Value:

Returns the next object on the queue.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Multithread safe.

Other Considerations:

None.

Member Function: TProducerConsumerQueue::HandleIsFull

virtual bool HandleIsFull ()

Interface Category:

API.

Purpose:

Derived classes of the producer consumer queue should override this member function to return true if they can no longer accept objects. This is called every time an object is removed from the queue to determine when space becomes available.

Calling Context:

Call this function directly.

Parameters:

Return Value:

Returns true if the queue is full.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Multithread safe.

Other Considerations:

None.

Member Function: TProducerConsumerQueue::HandleCount

virtual unsigned long HandleCount () const

Interface Category:

API.

Purpose:

Used by the Count member function to obtain the actual number of objects in the queue.

Calling Context:

Call this function directly.

Parameters:

Return Value:

Returns the number of objects in the queue.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Multithread safe.

Other Considerations:

None.

Member Function: TProducerConsumerQueue::HandleRemoveNextSatisfying

virtual MCollectible * HandleRemoveNextSatisfying (TProducerConsumerCondition &)

Interface Category:

API.

Purpose:

Removes the next request from the queue that satisfies the condition.

Calling Context:

Called by TProducerConsumerQueue.

Parameters:

Return Value:

The removed request.

Exceptions:

Throws no exceptions, passes all exceptions through.

Concurrency:

Multithread safe.

Other Considerations:

None.
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.