MADNESS 0.10.1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
madness::DQueue< T > Class Template Reference

A thread safe, fast but simple doubled-ended queue. More...

#include <dqueue.h>

Inheritance diagram for madness::DQueue< T >:
Inheritance graph
[legend]
Collaboration diagram for madness::DQueue< T >:
Collaboration graph
[legend]

Public Member Functions

 DQueue (size_t hint=200000)
 
virtual ~DQueue ()
 
bool empty () const
 
const DQStatsget_stats () const
 
void lock_and_flush_prebuf ()
 
std::pair< T, bool > pop_front (bool wait)
 Pop value off the front of queue.
 
int pop_front (int nmax, T *r, bool wait)
 Pop multiple values off the front of queue ... returns number popped ... might be zero.
 
void push_back (const T &value, int ncopy=1)
 Insert element at back of queue (default is just one copy)
 
void push_front (const T &value)
 Insert value at front of queue.
 
template<typename opT >
void scan (opT &op)
 
void set_wait_policy (WaitPolicy p, int us=0)
 
size_t size () const
 

Private Member Functions

size_t n __attribute__ ((aligned(64)))
 Number of elements in the buffer.
 
void flush_prebuf ()
 
void grow ()
 
void push_back_with_lock (const T &value)
 
void push_front_with_lock (const T &value)
 
void sanity_check () const
 
- Private Member Functions inherited from madness::PthreadConditionVariable
 PthreadConditionVariable ()
 
virtual ~PthreadConditionVariable ()
 
void broadcast () const
 
pthread_mutex_t & get_pthread_mutex ()
 
void lock () const
 
void signal () const
 
void unlock () const
 
void wait () const
 You should have acquired the mutex before entering here.
 

Private Attributes

int _back
 Index of element at back of buffer.
 
int _front
 Index of element at front of buffer.
 
Tbuf
 Actual buffer.
 
char pad [64]
 To put the lock and the data in separate cache lines.
 
DQStats stats
 
size_t sz
 Current capacity.
 

Detailed Description

template<typename T>
class madness::DQueue< T >

A thread safe, fast but simple doubled-ended queue.

Since the point is speed, the implementation is a circular buffer rather than a linked list so as to avoid the new/del overhead. It will grow as needed, but presently will not shrink. Had to modify STL API to make things thread safe.

It is now rather heavily specialized to its only use.

Constructor & Destructor Documentation

◆ DQueue()

template<typename T >
madness::DQueue< T >::DQueue ( size_t  hint = 200000)
inline

◆ ~DQueue()

template<typename T >
virtual madness::DQueue< T >::~DQueue ( )
inlinevirtual

Member Function Documentation

◆ __attribute__()

template<typename T >
size_t n madness::DQueue< T >::__attribute__ ( (aligned(64))  )
private

Number of elements in the buffer.

◆ empty()

template<typename T >
bool madness::DQueue< T >::empty ( ) const

◆ flush_prebuf()

template<typename T >
void madness::DQueue< T >::flush_prebuf ( )
inlineprivate

◆ get_stats()

template<typename T >
const DQStats & madness::DQueue< T >::get_stats ( ) const
inline

◆ grow()

template<typename T >
void madness::DQueue< T >::grow ( )
inlineprivate

◆ lock_and_flush_prebuf()

template<typename T >
void madness::DQueue< T >::lock_and_flush_prebuf ( )

◆ pop_front() [1/2]

template<typename T >
std::pair< T, bool > madness::DQueue< T >::pop_front ( bool  wait)
inline

Pop value off the front of queue.

References madness::DQueue< T >::pop_front(), T(), and madness::PthreadConditionVariable::wait().

◆ pop_front() [2/2]

template<typename T >
int madness::DQueue< T >::pop_front ( int  nmax,
T r,
bool  wait 
)
inline

Pop multiple values off the front of queue ... returns number popped ... might be zero.

r must refer to an array of dimension at least nmax ... you are presently given no more than max(size()/64,1) values ... arbitrary choice.

multi-threaded tasks might cause fewer tasks to be taken

References madness::DQueue< T >::_front, madness::DQueue< T >::buf, madness::f, madness::DQueue< T >::flush_prebuf(), madness::DQStats::npop_front, madness::DQueue< T >::stats, madness::DQueue< T >::sz, T(), and madness::PthreadConditionVariable::wait().

Referenced by madness::DQueue< T >::pop_front().

◆ push_back()

template<typename T >
void madness::DQueue< T >::push_back ( const T value,
int  ncopy = 1 
)

Insert element at back of queue (default is just one copy)

References madness::is_madness_thread().

◆ push_back_with_lock()

template<typename T >
void madness::DQueue< T >::push_back_with_lock ( const T value)
inlineprivate

◆ push_front()

template<typename T >
void madness::DQueue< T >::push_front ( const T value)

Insert value at front of queue.

References madness::is_madness_thread().

◆ push_front_with_lock()

template<typename T >
void madness::DQueue< T >::push_front_with_lock ( const T value)
inlineprivate

◆ sanity_check()

template<typename T >
void madness::DQueue< T >::sanity_check ( ) const
inlineprivate

◆ scan()

template<typename T >
template<typename opT >
void madness::DQueue< T >::scan ( opT &  op)
inline

◆ set_wait_policy()

template<typename T >
void madness::DQueue< T >::set_wait_policy ( WaitPolicy  p,
int  us = 0 
)
inline

◆ size()

template<typename T >
size_t madness::DQueue< T >::size ( ) const
inline

Member Data Documentation

◆ _back

template<typename T >
int madness::DQueue< T >::_back
private

◆ _front

template<typename T >
int madness::DQueue< T >::_front
private

◆ buf

template<typename T >
T* madness::DQueue< T >::buf
private

◆ pad

template<typename T >
char madness::DQueue< T >::pad[64]
private

To put the lock and the data in separate cache lines.

◆ stats

template<typename T >
DQStats madness::DQueue< T >::stats
private

◆ sz

template<typename T >
size_t madness::DQueue< T >::sz
private

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