Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Private Member Functions | Private Attributes
Clasp::mt::MultiQueue< T, Deleter > Class Template Reference

A (base) class for distributing items between n different threads. More...

#include <multi_queue.h>

List of all members.

Classes

struct  FreeList

Public Types

typedef Detail::NodeBaseThreadId

Public Member Functions

ThreadId addThread ()
 adds a new thread to the object
bool hasItems (ThreadId &cId) const
uint32 maxThreads () const
 MultiQueue (uint32 m, const Deleter &d=Deleter())
 creates a new object for at most m threads
void pop (ThreadId &cId)
 pops an item from the queue associated with the given thread
void reserve (uint32 c)
bool tryConsume (ThreadId &cId, T &out)
 tries to consume an item
 ~MultiQueue ()
 destroys the object and all unconsumed items

Protected Types

typedef Detail::Node< T > Node
typedef Detail::NodeBase NodeBase

Protected Member Functions

Nodeallocate (uint32 maxR, const T &in)
uint32 maxQ () const
void publish (const T &in, const ThreadId &)
 concurrency-safe version of unsafePublish
void publishRelaxed (NodeBase *n)
 Non-atomically adds n to the global queue.
void unsafePublish (const T &in, const ThreadId &)
 publishes a new item

Private Member Functions

 MultiQueue (const MultiQueue &)
MultiQueueoperator= (const MultiQueue &)
void release (NodeBase *n)

Private Attributes

Deleter deleter_
FreeList freeList_
NodeBase head_
const uint32 maxQ_
NodeBase::AtomicPtr tail_

Detailed Description

template<class T, class Deleter = Detail::DefaultDeleter>
class Clasp::mt::MultiQueue< T, Deleter >

A (base) class for distributing items between n different threads.

Logically, the class maintains n queues, one for each involved thread. Threads must register themselves by calling addThread(). The returned handle has then to be used for publishing and consuming items.

Definition at line 57 of file multi_queue.h.


Member Typedef Documentation

template<class T, class Deleter = Detail::DefaultDeleter>
typedef Detail::Node<T> Clasp::mt::MultiQueue< T, Deleter >::Node [protected]

Definition at line 59 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
typedef Detail::NodeBase Clasp::mt::MultiQueue< T, Deleter >::NodeBase [protected]

Definition at line 60 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
typedef Detail::NodeBase* Clasp::mt::MultiQueue< T, Deleter >::ThreadId

Definition at line 62 of file multi_queue.h.


Constructor & Destructor Documentation

template<class T, class Deleter = Detail::DefaultDeleter>
Clasp::mt::MultiQueue< T, Deleter >::MultiQueue ( uint32  m,
const Deleter &  d = Deleter() 
) [inline, explicit]

creates a new object for at most m threads

Definition at line 64 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
Clasp::mt::MultiQueue< T, Deleter >::~MultiQueue ( ) [inline]

destroys the object and all unconsumed items

Definition at line 75 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
Clasp::mt::MultiQueue< T, Deleter >::MultiQueue ( const MultiQueue< T, Deleter > &  ) [private]

Member Function Documentation

template<class T, class Deleter = Detail::DefaultDeleter>
ThreadId Clasp::mt::MultiQueue< T, Deleter >::addThread ( ) [inline]

adds a new thread to the object

Note:
Shall be called at most m times
Returns:
A handle identifying the new thread

Definition at line 88 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
Node* Clasp::mt::MultiQueue< T, Deleter >::allocate ( uint32  maxR,
const T &  in 
) [inline, protected]

Definition at line 162 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
bool Clasp::mt::MultiQueue< T, Deleter >::hasItems ( ThreadId cId) const [inline]

Definition at line 93 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
uint32 Clasp::mt::MultiQueue< T, Deleter >::maxQ ( ) const [inline, protected]

Definition at line 161 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
uint32 Clasp::mt::MultiQueue< T, Deleter >::maxThreads ( ) const [inline]

Definition at line 67 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
MultiQueue& Clasp::mt::MultiQueue< T, Deleter >::operator= ( const MultiQueue< T, Deleter > &  ) [private]
template<class T, class Deleter = Detail::DefaultDeleter>
void Clasp::mt::MultiQueue< T, Deleter >::pop ( ThreadId cId) [inline]

pops an item from the queue associated with the given thread

Precondition:
hasItems(cId) == true

Definition at line 115 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
void Clasp::mt::MultiQueue< T, Deleter >::publish ( const T &  in,
const ThreadId  
) [inline, protected]

concurrency-safe version of unsafePublish

Definition at line 133 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
void Clasp::mt::MultiQueue< T, Deleter >::publishRelaxed ( NodeBase n) [inline, protected]

Non-atomically adds n to the global queue.

Definition at line 157 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
void Clasp::mt::MultiQueue< T, Deleter >::release ( NodeBase n) [inline, private]

Definition at line 215 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
void Clasp::mt::MultiQueue< T, Deleter >::reserve ( uint32  c) [inline]

Definition at line 68 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
bool Clasp::mt::MultiQueue< T, Deleter >::tryConsume ( ThreadId cId,
T &  out 
) [inline]

tries to consume an item

Precondition:
cId was initially obtained via a call to addThread()
Note:
tryConsume() is thread-safe w.r.t different ThreadIds

Definition at line 100 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
void Clasp::mt::MultiQueue< T, Deleter >::unsafePublish ( const T &  in,
const ThreadId  
) [inline, protected]

publishes a new item

Note:
the function is *not* thread-safe, i.e. it must not be called concurrently

Definition at line 127 of file multi_queue.h.


Member Data Documentation

template<class T, class Deleter = Detail::DefaultDeleter>
Deleter Clasp::mt::MultiQueue< T, Deleter >::deleter_ [private]

Definition at line 226 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
FreeList Clasp::mt::MultiQueue< T, Deleter >::freeList_ [private]

Definition at line 224 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
NodeBase Clasp::mt::MultiQueue< T, Deleter >::head_ [private]

Definition at line 222 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
const uint32 Clasp::mt::MultiQueue< T, Deleter >::maxQ_ [private]

Definition at line 225 of file multi_queue.h.

template<class T, class Deleter = Detail::DefaultDeleter>
NodeBase::AtomicPtr Clasp::mt::MultiQueue< T, Deleter >::tail_ [private]

Definition at line 223 of file multi_queue.h.


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


clasp
Author(s): Benjamin Kaufmann
autogenerated on Thu Aug 27 2015 12:41:41