MADNESS 0.10.1
|
A thread safe, fast but simple doubled-ended queue. More...
#include <dqueue.h>
Public Member Functions | |
DQueue (size_t hint=200000) | |
virtual | ~DQueue () |
bool | empty () const |
const DQStats & | get_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. | |
T * | buf |
Actual buffer. | |
char | pad [64] |
To put the lock and the data in separate cache lines. | |
DQStats | stats |
size_t | sz |
Current capacity. | |
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.
|
inline |
|
inlinevirtual |
References madness::DQueue< T >::buf.
|
private |
Number of elements in the buffer.
bool madness::DQueue< T >::empty | ( | ) | const |
|
inlineprivate |
References madness::DQueue< T >::push_back_with_lock(), and madness::DQueue< T >::push_front_with_lock().
Referenced by madness::DQueue< T >::pop_front().
|
inline |
References madness::DQueue< T >::stats.
|
inlineprivate |
References madness::DQueue< T >::_back, madness::DQueue< T >::_front, madness::DQueue< T >::buf, lo, MADNESS_EXCEPTION, madness::DQStats::ngrow, madness::DQueue< T >::stats, madness::DQueue< T >::sz, and T().
Referenced by madness::DQueue< T >::push_back_with_lock(), and madness::DQueue< T >::push_front_with_lock().
void madness::DQueue< T >::lock_and_flush_prebuf | ( | ) |
|
inline |
Pop value off the front of queue.
References madness::DQueue< T >::pop_front(), T(), and madness::PthreadConditionVariable::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().
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().
|
inlineprivate |
References madness::DQueue< T >::_back, b, madness::DQueue< T >::buf, madness::DQueue< T >::grow(), madness::DQStats::nmax, madness::DQStats::npush_back, madness::PthreadConditionVariable::signal(), madness::DQueue< T >::stats, and madness::DQueue< T >::sz.
Referenced by madness::DQueue< T >::flush_prebuf().
void madness::DQueue< T >::push_front | ( | const T & | value | ) |
Insert value at front of queue.
References madness::is_madness_thread().
|
inlineprivate |
References madness::DQueue< T >::_front, madness::DQueue< T >::buf, madness::f, madness::DQueue< T >::grow(), madness::DQStats::nmax, madness::DQStats::npush_front, madness::PthreadConditionVariable::signal(), madness::DQueue< T >::stats, and madness::DQueue< T >::sz.
Referenced by madness::DQueue< T >::flush_prebuf().
|
inlineprivate |
|
inline |
References p(), and madness::ConditionVariable::set_wait_policy().
|
inline |
Referenced by madness::DQueue< T >::scan().
|
private |
Index of element at back of buffer.
Referenced by madness::DQueue< T >::grow(), madness::DQueue< T >::push_back_with_lock(), and madness::DQueue< T >::sanity_check().
|
private |
Index of element at front of buffer.
Referenced by madness::DQueue< T >::grow(), madness::DQueue< T >::pop_front(), madness::DQueue< T >::push_front_with_lock(), madness::DQueue< T >::sanity_check(), and madness::DQueue< T >::scan().
|
private |
|
private |
To put the lock and the data in separate cache lines.
|
private |
|
private |