async_queue.h File Reference

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

`#include <queue>`
`#include <list>`
`#include <exception>`
`#include <utility>`
`#include <algorithm>`
`#include <time.h>`
`#include <c++-gtk-utils/mutex.h>`
`#include <c++-gtk-utils/thread.h>`
`#include <c++-gtk-utils/cgu_config.h>`
`#include <unistd.h>`

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

| Cgu

## Constant Groups

| 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) and AsyncQueue::move_pop(value_type& obj) methods provide the popped 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 pushing and popping from different threads. It is therefore useful for passing data between threads, perhaps in response to a signal being emitted from a Notifier object. Data can be pushed or pulled by move constructor/move assignment operator or by means of a std::unique_ptr object, SharedLockPtr object or an IntrusivePtr object referencing data derived from IntrusiveLockCounter.

AsyncQueueDispatch is a class which has blocking pop() and move_pop() methods, 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 when adding an item to the queue all allocation can take place outside the queue object's mutex. However, for types which have low overhead copy or move constructors, this can be changed to, say, a std::deque object by specifying it as the second template parameter.