CQueue class

The CQueue class template implements a simple, statically sized queue.

Public MethodsDescription
CQueue Constructor method.
~CQueue Destructor method.
GetQueueObject Retrieves the next item from the queue.
PutQueueObject Puts an item onto the queue.

 

Remarks

The class constructor specifies the size of the queue. Use the CQueue::PutQueueObject to put an item on the queue, and the CQueue::GetQueueObject method to dequeues an item. If the queue is full, the PutQueueObject method blocks until an item is dequeued. If the queue is empty, the GetQueueObject blocks until an item is queued. The template parameter specifies the type of item. For example:


CQueue<int> number_queue;
number_queue.PutQueueObject(7);

The class uses two semaphores to control queuing operations, a "get" semaphore and a "put" semaphore. The GetQueueObject method waits on the "get" semaphore (using the WaitForSingleObject function) and releases the "put" semaphore (using the ReleaseSemaphore function). The PutQueueObject method waits on the "put" semaphore and releases the "get" semaphore. The class uses a critical section to serialize queuing operations among multiple threads.

Requirements

Header

Wxutil.h (include Streams.h)

Library

Strmbase.lib (retail builds);
Strmbasd.lib (debug builds)

 

 

Show: