DUECA/DUSIME
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Friends | List of all members
dueca::AsyncQueueMT< T, Alloc > Class Template Reference

This implements a singly linked fifo queue, which uses a sentinel technique and the atomic_swap64 call for implementing non-blocking transfer of commands/data from multiple threads to a single reading thread. More...

#include <AsyncQueueMT.hxx>

Public Types

typedef T value_type
 Type of the objects in the queue.
 

Public Member Functions

void init_list (int size)
 List initialisation, special case for when init should be later.
 
 AsyncQueueMT (int size=10, const char *name="anon AsyncQueueMT")
 Constructor.
 
 ~AsyncQueueMT ()
 Destructor.
 
bool notEmpty () const
 Returns true if there is more than the sentinel.
 
bool isEmpty () const
 Returns true if there is no data to be read.
 
const Tfront () const
 Peek at data without removing.
 
const Tback () const
 Peek at data without removing.
 
Tfront ()
 Access data.
 
Tback ()
 Access data.
 
void pop ()
 Remove element at head.
 
unsigned int size ()
 Return the number of elements in the list.
 
void push_back (const T &data)
 Push back, with a writer, convenience method, involves an assigment of the to-be pushed object.
 
template<class... Args>
void emplace_back (Args &&... args)
 Construct an element at the end of the asynchronous list.
 

Public Attributes

Alloc allocator
 Allocator used.
 

Friends

class AsyncQueueWriter< T, Alloc >
 only access to writing data on the queue
 
class AsyncQueueReader< T, Alloc >
 only point of access for reading data from the queue
 
Alloc::element_ptr get_list_spare (AsyncQueueMT< T, Alloc > &list)
 friend function for accessing an element from the spare stack
 
void write_list_back (AsyncQueueMT< T, Alloc > &list, typename Alloc::element_ptr elt)
 write back a previously obtained spare
 
void return_list_elt (AsyncQueueMT< T, Alloc > &list, typename Alloc::element_ptr elt)
 return a previously obtained spare to the spares
 

Detailed Description

template<class T, class Alloc = ListElementAllocator<T>>
class dueca::AsyncQueueMT< T, Alloc >

This implements a singly linked fifo queue, which uses a sentinel technique and the atomic_swap64 call for implementing non-blocking transfer of commands/data from multiple threads to a single reading thread.

By design, this is only thread-safe for a single reader and multiple writers, and only for the inserting and extracting.

Use the dueca::AsyncQueueWriter and dueca::AsyncQueueReader helpers for inserting and extracting data.

Accessing members in the list through the front() and back() functions is possible, but not locked in any way. As long as the single reading thread does it, using front() will be safe. Using back() will only be safe if there is no reading/pop() action, and no other threads write.

Constructor & Destructor Documentation

◆ ~AsyncQueueMT()

template<class T , class Alloc = ListElementAllocator<T>>
dueca::AsyncQueueMT< T, Alloc >::~AsyncQueueMT ( )
inline

Destructor.

Todo
This apparently does not clean up all points?

Member Function Documentation

◆ emplace_back()

template<class T , class Alloc = ListElementAllocator<T>>
template<class... Args>
void dueca::AsyncQueueMT< T, Alloc >::emplace_back ( Args &&... args)
inline

Construct an element at the end of the asynchronous list.

Parameters
argsArguments for constructing the element.

Friends And Related Symbol Documentation

◆ get_list_spare

template<class T , class Alloc = ListElementAllocator<T>>
Alloc::element_ptr get_list_spare ( AsyncQueueMT< T, Alloc > & list)
friend

friend function for accessing an element from the spare stack

Note that you are responsible for returning this element with write_list_back or return_list_spare

Template Parameters
TType of object
AllocMemory allocator/handler for this list
Parameters
listList object

◆ write_list_back

template<class T , class Alloc = ListElementAllocator<T>>
void write_list_back ( AsyncQueueMT< T, Alloc > & list,
typename Alloc::element_ptr elt )
friend

write back a previously obtained spare

Note that you are responsible for obtaining this element with get_list_spare

Template Parameters
TType of object.
AllocMemory allocator/handler for this list.
Parameters
listList object.
eltElement to append.

◆ return_list_elt

template<class T , class Alloc = ListElementAllocator<T>>
void return_list_elt ( AsyncQueueMT< T, Alloc > & list,
typename Alloc::element_ptr elt )
friend

return a previously obtained spare to the spares

Note that you are responsible for obtaining this element with get_list_spare. Note: either recycle or append, do not do both!

Template Parameters
TType of object.
AllocMemory allocator/handler for this list.
Parameters
listList object.
eltElement to recycle.

Member Data Documentation

◆ allocator

template<class T , class Alloc = ListElementAllocator<T>>
Alloc dueca::AsyncQueueMT< T, Alloc >::allocator

Allocator used.

Normally (default allocator) not modifyable, but custom allocators may be tuned.


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