clingo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | List of all members
Clasp::mt::MultiQueue< T, Deleter > Class Template Reference

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

#include <multi_queue.h>

Inheritance diagram for Clasp::mt::MultiQueue< T, Deleter >:
Inheritance graph
Collaboration diagram for Clasp::mt::MultiQueue< T, Deleter >:
Collaboration graph

Public Types

typedef Detail::NodeBaseThreadId
 

Public Member Functions

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

Protected Types

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

Protected Member Functions

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

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.

Member Typedef Documentation

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

Constructor & Destructor Documentation

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

creates a new object for at most m threads

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

destroys the object and all unconsumed items

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
template<class T, class Deleter = Detail::DefaultDeleter>
Node* Clasp::mt::MultiQueue< T, Deleter >::allocate ( uint32  maxR,
const T &  in 
)
inlineprotected
template<class T, class Deleter = Detail::DefaultDeleter>
bool Clasp::mt::MultiQueue< T, Deleter >::hasItems ( ThreadId cId) const
inline
template<class T, class Deleter = Detail::DefaultDeleter>
uint32 Clasp::mt::MultiQueue< T, Deleter >::maxQ ( ) const
inlineprotected
template<class T, class Deleter = Detail::DefaultDeleter>
uint32 Clasp::mt::MultiQueue< T, Deleter >::maxThreads ( ) const
inline
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
template<class T, class Deleter = Detail::DefaultDeleter>
void Clasp::mt::MultiQueue< T, Deleter >::publish ( const T &  in,
const ThreadId  
)
inlineprotected

concurrency-safe version of unsafePublish

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

Non-atomically adds n to the global queue.

template<class T, class Deleter = Detail::DefaultDeleter>
void Clasp::mt::MultiQueue< T, Deleter >::reserve ( uint32  c)
inline
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
template<class T, class Deleter = Detail::DefaultDeleter>
void Clasp::mt::MultiQueue< T, Deleter >::unsafePublish ( const T &  in,
const ThreadId  
)
inlineprotected

publishes a new item

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

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