Public Member Functions | Private Attributes | List of all members
gov::fnal::cd::rms::util::LinkedBlockingQueue< QueueType > Class Template Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-01-18/rms/cxx/include/util/LinkedBlockingQueue.h"

Public Member Functions

void add (QueueType object)
 
QueueType take ()
 
QueueType poll (long timeout)
 
QueueType poll ()
 

Private Attributes

boost::mutex _queueLock
 
boost::condition _queueCondition
 
std::queue< QueueType > _queue
 

Detailed Description

template<class QueueType>
class gov::fnal::cd::rms::util::LinkedBlockingQueue< QueueType >

This is a templated thread safe container that is meant to emulate the LinkedBlockingQueue that is used in the Java version of RMS.

Author
Kurt Biery
Steve Foulkes
Version
Revision
1.2.14.1
Date
2019/09/27 00:07:32

Definition at line 30 of file LinkedBlockingQueue.h.

Member Function Documentation

template<class QueueType>
void gov::fnal::cd::rms::util::LinkedBlockingQueue< QueueType >::add ( QueueType  object)
inline

Add an element to the queue. After obtaining the queue lock, push an object onto the stack and notify the condition variable that the queue is not empty.

Parameters
objectThe object that is to be inserted into the queue.

Definition at line 39 of file LinkedBlockingQueue.h.

Referenced by gov::fnal::cd::rms::provider::BufferedProviderListener::textReceived().

39  {
40  boost::mutex::scoped_lock lk(_queueLock);
41 
42  _queue.push(object);
43  _queueCondition.notify_one();
44 
45  return;
46  }
template<class QueueType>
QueueType gov::fnal::cd::rms::util::LinkedBlockingQueue< QueueType >::poll ( long  timeout)
inline

Take an element off the queue. If the queue is empty, this will wait at most timeout seconds before returning.

Parameters
timeoutThe amount of time to wait, in seconds, before returning if the queue is empty.
Returns
An object from the queue if one be can retrieved before the timeout. An object created with its befault constructor will be returned otherwise.

Definition at line 80 of file LinkedBlockingQueue.h.

Referenced by gov::fnal::cd::rms::RmsConsumer::receiveMessage(), gov::fnal::cd::rms::RmsConsumer::receiveMessageNoWait(), gov::fnal::cd::rms::RmsProducer::receiveReply(), gov::fnal::cd::rms::RmsProducer::receiveReplyNoWait(), gov::fnal::cd::rms::RmsConsumer::receiveString(), gov::fnal::cd::rms::RmsConsumer::receiveStringNoWait(), and gov::fnal::cd::rms::ClientListenerLoop::run().

80  {
81  QueueType queueEntry;
82 
83  boost::xtime xt;
84 
85 #if BOOST_VERSION >= 105000
86  boost::xtime_get(&xt, boost::TIME_UTC_);
87 #else
88  boost::xtime_get(&xt, boost::TIME_UTC);
89 #endif
90 
91  xt.sec += timeout;
92 
93  boost::mutex::scoped_lock lk(_queueLock);
94 
95  while (_queue.size() == 0) {
96  if (!_queueCondition.timed_wait(lk, xt)) {
97  return queueEntry;
98  }
99  }
100 
101  queueEntry = _queue.front();
102  _queue.pop();
103 
104  return queueEntry;
105  }
template<class QueueType>
QueueType gov::fnal::cd::rms::util::LinkedBlockingQueue< QueueType >::poll ( )
inline

Take an element off the queue. This function will not block if the queue is empty.

Returns
An object from the queue if the queue is not empty. An object created with its befault constructor will be returned otherwise.

Definition at line 115 of file LinkedBlockingQueue.h.

115  {
116  QueueType queueEntry;
117  boost::mutex::scoped_lock lk(_queueLock);
118 
119  while (_queue.size() == 0) {
120  return queueEntry;
121  }
122 
123  queueEntry = _queue.front();
124  _queue.pop();
125 
126  return queueEntry;
127  }
template<class QueueType>
QueueType gov::fnal::cd::rms::util::LinkedBlockingQueue< QueueType >::take ( )
inline

Take an element off the queue. If the queue is empty, this will block until an element is added to the queue.

Returns
An object from the queue.

Definition at line 54 of file LinkedBlockingQueue.h.

Referenced by gov::fnal::cd::rms::RmsConsumer::receiveMessage(), gov::fnal::cd::rms::RmsProducer::receiveReply(), and gov::fnal::cd::rms::RmsConsumer::receiveString().

54  {
55  QueueType queueEntry;
56 
57  boost::mutex::scoped_lock lk(_queueLock);
58 
59  while (_queue.size() == 0) {
60  _queueCondition.wait(lk);
61  }
62 
63  queueEntry = _queue.front();
64  _queue.pop();
65 
66  return queueEntry;
67  }

Member Data Documentation

template<class QueueType>
std::queue<QueueType> gov::fnal::cd::rms::util::LinkedBlockingQueue< QueueType >::_queue
private
template<class QueueType>
boost::condition gov::fnal::cd::rms::util::LinkedBlockingQueue< QueueType >::_queueCondition
private
template<class QueueType>
boost::mutex gov::fnal::cd::rms::util::LinkedBlockingQueue< QueueType >::_queueLock
private

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