CQueue Class


CQueue class hierarchy

This class implements a simple Queue Abstract Data Type (ADT). The queue contains a finite number of objects, and a semaphore controls access to these objects. The semaphore is created with an initial count (N). Each time an object is added, a call to the Microsoft® Win32® WaitForSingleObject function is made on the handle of the semaphore. When this function returns, it reserves a slot in the queue for the new object. If no slots are available, the member function blocks until it becomes available. Each time an object is removed from the queue, the Win32 ReleaseSemaphore function is called on the handle of the semaphore, thus freeing a slot in the queue. If no objects are present in the queue, the function blocks until an object has been added.

Member Functions
Name Description
CQueue Constructs a CQueue object.
GetQueueObject Retrieves an object from the queue.
PutQueueObject Puts an object into the queue.


CQueue::CQueue

CQueue Class

Constructs a CQueue object.

CQueue(
  int n
  );
CQueue( );

Parameters
n
Size of the queue to create.
Return Values

No return value.

Remarks

If constructed with no parameters, the size of the queue is set to DEFAULT_QUEUESIZE.


CQueue::GetQueueObject

CQueue Class

Retrieves an object from the queue.

T GetQueueObject( );

Return Values

Returns an object of type T (template).

Remarks

This member function blocks until an object is available on the queue. It uses a CCritSec object for security.


CQueue::PutQueueObject

CQueue Class

Puts an object into the queue.

void PutQueueObject(
  T object
  );

Parameters
object
Template object to be inserted into the queue.
Return Values

No return value.

Remarks

This member function blocks if there is no open slot into which to put the object. It releases any blocking CQueue::GetQueueObject member function that is waiting for an object to retrieve.

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.