c++-gtk-utils
Classes | Namespaces | Functions
async_queue.h File Reference

This file provides thread-safe asynchronous queue classes. More...

Go to the source code of this file.

Classes

class  Cgu::AsyncQueuePopError
 An exception thrown if calling pop() on a AsyncQueue or AsyncQueueDispatch object fails because the queue is empty. More...
class  Cgu::AsyncQueue< T, Container >
 A thread-safe asynchronous queue. More...
class  Cgu::AsyncQueueDispatch< T, Container >
 A thread-safe asynchronous queue with a blocking pop() method. More...

Namespaces

namespace  Cgu

Functions

template<class T , class Container >
void Cgu::swap (Cgu::AsyncQueue< T, Container > &q1, Cgu::AsyncQueue< T, Container > &q2)
template<class T , class Container >
void Cgu::swap (Cgu::AsyncQueueDispatch< T, Container > &q1, Cgu::AsyncQueueDispatch< T, Container > &q2)

Detailed Description

This file provides thread-safe asynchronous queue classes.

AsyncQueue is a class which provides some of the functionality of a std::queue object (but note that the AsyncQueue::pop(value_type& obj) method provides the pop()ed element by reference - see the comments on that method for the reason), except that it has mutex locking of the data container so as to permit push()ing and pop()ing from different threads. It is therefore useful for passing data between threads, perhaps in response to a signal being emitted from a Notifier object. Passing the data by means of a SharedLockPtr object, or an IntrusivePtr object referencing data derived from IntrusiveLockCounter, would be ideal.

AsyncQueueDispatch is a class which has a blocking pop() method, which allows it to be waited on by a dedicated event/message dispatching thread for incoming work (represented by the data pushed onto the queue). In the same way, it can be used to implement thread pools, by having threads in the pool waiting on the queue.

By default the queues use a std::list object as their container because in the kind of use mentioned above they are unlikely to hold many objects but they can be changed to, say, a std::deque object by specifying it as the second template parameter.