|
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 | flush_prebufhi () |
| void | flush_prebuflo () |
| 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 buf.
|
private |
Number of elements in the buffer.
| bool madness::DQueue< T >::empty | ( | ) | const |
|
inlineprivate |
References flush_prebufhi(), and flush_prebuflo().
Referenced by lock_and_flush_prebuf(), pop_front(), and push_back().
|
inlineprivate |
References push_front_with_lock().
Referenced by flush_prebuf(), and push_front().
|
inlineprivate |
References push_back_with_lock().
Referenced by flush_prebuf().
|
inline |
References stats.
|
inlineprivate |
References _back, _front, buf, lo, MADNESS_EXCEPTION, stats, and sz.
Referenced by push_back_with_lock(), and push_front_with_lock().
| void madness::DQueue< T >::lock_and_flush_prebuf | ( | ) |
References flush_prebuf(), and MADNESS_ASSERT.
|
inline |
Pop value off the front of queue.
References pop_front(), 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 _front, buf, madness::f, flush_prebuf(), stats, sz, and madness::PthreadConditionVariable::wait().
Referenced by 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 flush_prebuf(), madness::Future< void >::value, madness::is_madness_thread(), MADNESS_ASSERT, and push_back_with_lock().
|
inlineprivate |
References _back, b, buf, madness::Future< void >::value, grow(), madness::PthreadConditionVariable::signal(), stats, and sz.
Referenced by flush_prebuflo(), and push_back().
| void madness::DQueue< T >::push_front | ( | const T & | value | ) |
Insert value at front of queue.
References flush_prebufhi(), madness::Future< void >::value, madness::is_madness_thread(), MADNESS_ASSERT, and push_front_with_lock().
|
inlineprivate |
References _front, buf, madness::f, madness::Future< void >::value, grow(), madness::PthreadConditionVariable::signal(), stats, and sz.
Referenced by flush_prebufhi(), and push_front().
|
inlineprivate |
References _back, _front, MADNESS_ASSERT, and sz.
|
inline |
References p(), and madness::ConditionVariable::set_wait_policy().
|
inline |
Referenced by scan().
|
private |
Index of element at back of buffer.
Referenced by DQueue(), grow(), push_back_with_lock(), and sanity_check().
|
private |
Index of element at front of buffer.
Referenced by DQueue(), grow(), pop_front(), push_front_with_lock(), sanity_check(), and scan().
|
private |
Actual buffer.
Referenced by DQueue(), ~DQueue(), grow(), pop_front(), push_back_with_lock(), push_front_with_lock(), and scan().
|
private |
To put the lock and the data in separate cache lines.
|
private |
Referenced by get_stats(), grow(), pop_front(), push_back_with_lock(), and push_front_with_lock().
|
private |
Current capacity.
Referenced by DQueue(), grow(), pop_front(), push_back_with_lock(), push_front_with_lock(), sanity_check(), and scan().