MLIB
Loading...
Searching...
No Matches
mlib::async_queue< M, C > Class Template Reference

A template class that implements "asynchronous queues". More...

#include <syncque.h>

Inheritance diagram for mlib::async_queue< M, C >:

Public Member Functions

 async_queue (size_t limit_=INFINITE)
 Crates a queue with the given maximum size.
 
virtual bool produce (const M &obj, DWORD timeout=INFINITE)
 
virtual bool consume (M &result, int timeout=INFINITE)
 
bool empty ()
 Return true if queue is empty.
 
bool full ()
 Return true if queue is at capacity.
 
size_t size ()
 Return queue size.
 

Protected Attributes

size_t limit
 
semaphore prod_sema
 producers' semaphore counts down until queue is full
 
semaphore cons_sema
 consumers' semaphore counts down until queue is empty
 
criticalsection update
 critical section protects queue's integrity
 

Detailed Description

template<class M, class C = std::deque<M>>
class mlib::async_queue< M, C >

A template class that implements "asynchronous queues".

These are producer/consumer queues which can hold "messages" and deliver them in FIFO order. Attempting to consume from an empty queue will block the calling thread until a message arrives.

Note
The default size of async_queue is INFINITE and it can grow up to the available memory.

Member Function Documentation

◆ consume()

template<class M , class C = std::deque<M>>
virtual bool mlib::async_queue< M, C >::consume ( M &  result,
int  timeout = INFINITE 
)
inlinevirtual

Extract the first element in queue Return true if an element was extracted or false if a timeout occurred.

◆ produce()

template<class M , class C = std::deque<M>>
virtual bool mlib::async_queue< M, C >::produce ( const M &  obj,
DWORD  timeout = INFINITE 
)
inlinevirtual

Append an element to queue

Returns
true if the element was appended or false if a timeout occurred.

The documentation for this class was generated from the following file: