oasys::MsgQueue< _elt_t > Class Template Reference

#include <MsgQueue.h>

Inheritance diagram for oasys::MsgQueue< _elt_t >:

oasys::Notifier oasys::Logger List of all members.

Detailed Description

template<typename _elt_t>
class oasys::MsgQueue< _elt_t >

A producer/consumer queue for passing data between threads in the system, using the Notifier functionality to block and wakeup threads.

Definition at line 60 of file MsgQueue.h.

Public Member Functions

 MsgQueue (const char *logpath, SpinLock *lock=NULL)
 ~MsgQueue ()
 Destructor.
void push (_elt_t msg, bool at_back=true)
 Atomically add msg to the back of the queue and signal a waiting thread.
void push_front (_elt_t msg)
 Atomically add msg to the front of the queue, and signal waiting threads.
void push_back (_elt_t msg)
 Atomically add msg to the back of the queue, and signal waiting threads.
_elt_t pop_blocking ()
 Block and pop msg from the queue.
bool try_pop (_elt_t *eltp)
 Try to pop a msg from the queue, but don't block.
size_t size ()
 
Returns:
Size of the queue.

void notify_when_empty ()
 Change the semantics of the queue such that notify() is only called if the queue is empty.

Protected Attributes

SpinLocklock_
std::deque< _elt_t > queue_
bool notify_when_empty_


Constructor & Destructor Documentation

template<typename _elt_t>
oasys::MsgQueue< _elt_t >::MsgQueue ( const char *  logpath,
SpinLock lock = NULL 
)

Constructor.

Definition at line 150 of file MsgQueue.h.

template<typename _elt_t>
oasys::MsgQueue< _elt_t >::~MsgQueue (  ) 

Destructor.

Definition at line 163 of file MsgQueue.h.


Member Function Documentation

template<typename _elt_t>
void oasys::MsgQueue< _elt_t >::push ( _elt_t  msg,
bool  at_back = true 
)

Atomically add msg to the back of the queue and signal a waiting thread.

Definition at line 176 of file MsgQueue.h.

Referenced by oasys::MsgQueue< dtn::BundleEvent * >::push_back(), oasys::MsgQueue< dtn::BundleEvent * >::push_front(), and oasys::QueuingTimer::timeout().

template<typename _elt_t>
void oasys::MsgQueue< _elt_t >::push_front ( _elt_t  msg  )  [inline]

Atomically add msg to the front of the queue, and signal waiting threads.

Definition at line 82 of file MsgQueue.h.

template<typename _elt_t>
void oasys::MsgQueue< _elt_t >::push_back ( _elt_t  msg  )  [inline]

Atomically add msg to the back of the queue, and signal waiting threads.

Definition at line 91 of file MsgQueue.h.

Referenced by dtntunnel::TCPTunnel::Connection::handle_bundle().

template<typename _elt_t>
_elt_t oasys::MsgQueue< _elt_t >::pop_blocking (  ) 

Block and pop msg from the queue.

Definition at line 199 of file MsgQueue.h.

Referenced by dtntunnel::TCPTunnel::Connection::run().

template<typename _elt_t>
bool oasys::MsgQueue< _elt_t >::try_pop ( _elt_t *  eltp  ) 

Try to pop a msg from the queue, but don't block.

Return true if there was a message on the queue, false otherwise.

Definition at line 231 of file MsgQueue.h.

Referenced by dtntunnel::TCPTunnel::Connection::~Connection().

template<typename _elt_t>
size_t oasys::MsgQueue< _elt_t >::size (  )  [inline]

Returns:
Size of the queue.

Definition at line 110 of file MsgQueue.h.

template<typename _elt_t>
void oasys::MsgQueue< _elt_t >::notify_when_empty (  ) 

Change the semantics of the queue such that notify() is only called if the queue is empty.

This assumes that the user of the queue will completely drain it before blocking on the notifier, unlike the simple model of calling pop_blocking() each time.

This can be used in situations where a large number of messages may potentially be queued, such that calling notify() on each one might fill up the pipe.

Definition at line 252 of file MsgQueue.h.


Member Data Documentation

template<typename _elt_t>
SpinLock* oasys::MsgQueue< _elt_t >::lock_ [protected]

Definition at line 131 of file MsgQueue.h.

Referenced by oasys::MsgQueue< dtn::BundleEvent * >::size().

template<typename _elt_t>
std::deque<_elt_t> oasys::MsgQueue< _elt_t >::queue_ [protected]

Definition at line 132 of file MsgQueue.h.

Referenced by oasys::MsgQueue< dtn::BundleEvent * >::size().

template<typename _elt_t>
bool oasys::MsgQueue< _elt_t >::notify_when_empty_ [protected]

Definition at line 133 of file MsgQueue.h.


The documentation for this class was generated from the following file:
Generated on Fri Dec 22 14:48:07 2006 for DTN Reference Implementation by  doxygen 1.5.1