CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
edm::SingleConsumerQ Class Reference

#include <SingleConsumerQ.h>

Classes

struct  Buffer
 
struct  ConsumerType
 
class  OperateBuffer
 
struct  ProducerType
 

Public Types

typedef OperateBuffer
< ConsumerType
ConsumerBuffer
 
typedef OperateBuffer
< ProducerType
ProducerBuffer
 

Public Member Functions

void commitConsumerBuffer (void *, int)
 
void commitProducerBuffer (void *, int)
 
Buffer getConsumerBuffer ()
 
Buffer getProducerBuffer ()
 
int maxEventSize () const
 
int maxQueueDepth () const
 
void releaseConsumerBuffer (void *)
 
void releaseProducerBuffer (void *)
 
 SingleConsumerQ (int max_event_size, int max_queue_depth)
 
 ~SingleConsumerQ ()
 

Private Types

typedef std::vector< char > ByteArray
 
typedef std::vector< void * > Pool
 
typedef std::vector< BufferQueue
 

Private Member Functions

 SingleConsumerQ (const SingleConsumerQ &)
 

Private Attributes

unsigned int bpos_
 
Pool buffer_pool_
 
unsigned int fpos_
 
int max_event_size_
 
int max_queue_depth_
 
ByteArray mem_
 
boost::condition pool_cond_
 
boost::mutex pool_lock_
 
boost::condition pop_cond_
 
int pos_
 
boost::condition push_cond_
 
Queue queue_
 
boost::mutex queue_lock_
 

Detailed Description

Definition at line 43 of file SingleConsumerQ.h.

Member Typedef Documentation

typedef std::vector<char> edm::SingleConsumerQ::ByteArray
private

Definition at line 115 of file SingleConsumerQ.h.

Definition at line 96 of file SingleConsumerQ.h.

typedef std::vector<void*> edm::SingleConsumerQ::Pool
private

Definition at line 117 of file SingleConsumerQ.h.

Definition at line 97 of file SingleConsumerQ.h.

typedef std::vector<Buffer> edm::SingleConsumerQ::Queue
private

Definition at line 119 of file SingleConsumerQ.h.

Constructor & Destructor Documentation

edm::SingleConsumerQ::SingleConsumerQ ( int  max_event_size,
int  max_queue_depth 
)

Definition at line 6 of file SingleConsumerQ.cc.

References buffer_pool_, i, reco_skim_cfg_mod::max_event_size, and mem_.

6  :
9  buffer_pool_(),
11  fpos_(),
12  bpos_(),
13  pool_lock_(),
14  queue_lock_(),
15  pool_cond_(),
16  pop_cond_(),
17  push_cond_()
18  {
19  // throw if event size 0 or queue depth 0
20 
21  for(char* i=&mem_[0];i<&mem_[mem_.size()];i+=max_event_size)
22  buffer_pool_.push_back(i);
23 
24  }
boost::condition pop_cond_
int i
Definition: DBlmapReader.cc:9
boost::condition push_cond_
boost::mutex queue_lock_
boost::condition pool_cond_
edm::SingleConsumerQ::~SingleConsumerQ ( )

Definition at line 26 of file SingleConsumerQ.cc.

26 { }
edm::SingleConsumerQ::SingleConsumerQ ( const SingleConsumerQ )
private

Member Function Documentation

void edm::SingleConsumerQ::commitConsumerBuffer ( void *  v,
int   
)

Definition at line 96 of file SingleConsumerQ.cc.

References releaseProducerBuffer().

Referenced by edm::SingleConsumerQ::ConsumerType::commit().

97  {
99  }
void releaseProducerBuffer(void *)
mathSSE::Vec4< T > v
void edm::SingleConsumerQ::commitProducerBuffer ( void *  v,
int  len 
)

Definition at line 51 of file SingleConsumerQ.cc.

References bpos_, fpos_, max_queue_depth_, pop_cond_, push_cond_, queue_, and queue_lock_.

Referenced by edm::SingleConsumerQ::ProducerType::commit().

52  {
53  // get lock
54  boost::mutex::scoped_lock sl(queue_lock_);
55  // if full, wait for item to be removed
56  while((bpos_+max_queue_depth_)==fpos_)
57  {
58  push_cond_.wait(sl);
59  }
60 
61  // put buffer into queue
62  queue_[fpos_ % max_queue_depth_]=Buffer(v,len);
63  ++fpos_;
64  // signal consumer
65  pop_cond_.notify_all();
66  }
boost::condition pop_cond_
boost::condition push_cond_
boost::mutex queue_lock_
mathSSE::Vec4< T > v
SingleConsumerQ::Buffer edm::SingleConsumerQ::getConsumerBuffer ( )

Definition at line 68 of file SingleConsumerQ.cc.

References bpos_, fpos_, max_queue_depth_, pop_cond_, push_cond_, queue_, queue_lock_, and v.

69  {
70  // get lock
71  boost::mutex::scoped_lock sl(queue_lock_);
72  // if empty, wait for item to appear
73  while(bpos_==fpos_)
74  {
75  pop_cond_.wait(sl);
76  }
77  // get a buffer from the queue and return it
78  Buffer v = queue_[bpos_ % max_queue_depth_];
79  ++bpos_;
80  // note that these operations cannot throw
81  // signal producer
82  push_cond_.notify_all();
83  return v;
84  }
boost::condition pop_cond_
boost::condition push_cond_
boost::mutex queue_lock_
mathSSE::Vec4< T > v
SingleConsumerQ::Buffer edm::SingleConsumerQ::getProducerBuffer ( )

Definition at line 28 of file SingleConsumerQ.cc.

References buffer_pool_, max_event_size_, pool_cond_, pool_lock_, pos_, and v.

29  {
30  // get lock
31  boost::mutex::scoped_lock sl(pool_lock_);
32  // wait for buffer to appear
33  while(pos_ < 0)
34  {
35  pool_cond_.wait(sl);
36  }
37  void* v = buffer_pool_[pos_];
38  --pos_;
39  return Buffer(v,max_event_size_);
40  }
boost::condition pool_cond_
mathSSE::Vec4< T > v
int edm::SingleConsumerQ::maxEventSize ( ) const
inline

Definition at line 107 of file SingleConsumerQ.h.

References max_event_size_.

107 { return max_event_size_; }
int edm::SingleConsumerQ::maxQueueDepth ( ) const
inline

Definition at line 108 of file SingleConsumerQ.h.

References max_queue_depth_.

108 { return max_queue_depth_; }
void edm::SingleConsumerQ::releaseConsumerBuffer ( void *  v)

Definition at line 86 of file SingleConsumerQ.cc.

References releaseProducerBuffer().

Referenced by edm::SingleConsumerQ::ConsumerType::release().

87  {
88  // should the buffer be placed back onto the queue and not released?
89  // we got here because a commit did to occur in the consumer.
90  // we will allow consumers to call or not call commit for now, meaning
91  // that we cannot distinguish between exception conditions and normal
92  // return. The buffer will always be released
94  }
void releaseProducerBuffer(void *)
mathSSE::Vec4< T > v
void edm::SingleConsumerQ::releaseProducerBuffer ( void *  v)

Definition at line 42 of file SingleConsumerQ.cc.

References buffer_pool_, pool_cond_, pool_lock_, pos_, and v.

Referenced by commitConsumerBuffer(), edm::SingleConsumerQ::ProducerType::release(), and releaseConsumerBuffer().

43  {
44  // get lock
45  boost::mutex::scoped_lock sl(pool_lock_);
46  ++pos_;
47  buffer_pool_[pos_] = v;
48  pool_cond_.notify_all();
49  }
boost::condition pool_cond_
mathSSE::Vec4< T > v

Member Data Documentation

unsigned int edm::SingleConsumerQ::bpos_
private

Definition at line 127 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

Pool edm::SingleConsumerQ::buffer_pool_
private

Definition at line 125 of file SingleConsumerQ.h.

Referenced by getProducerBuffer(), releaseProducerBuffer(), and SingleConsumerQ().

unsigned int edm::SingleConsumerQ::fpos_
private

Definition at line 127 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

int edm::SingleConsumerQ::max_event_size_
private

Definition at line 121 of file SingleConsumerQ.h.

Referenced by getProducerBuffer(), and maxEventSize().

int edm::SingleConsumerQ::max_queue_depth_
private

Definition at line 122 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), getConsumerBuffer(), and maxQueueDepth().

ByteArray edm::SingleConsumerQ::mem_
private

Definition at line 124 of file SingleConsumerQ.h.

Referenced by SingleConsumerQ().

boost::condition edm::SingleConsumerQ::pool_cond_
private

Definition at line 131 of file SingleConsumerQ.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

boost::mutex edm::SingleConsumerQ::pool_lock_
private

Definition at line 129 of file SingleConsumerQ.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

boost::condition edm::SingleConsumerQ::pop_cond_
private

Definition at line 132 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

int edm::SingleConsumerQ::pos_
private

Definition at line 123 of file SingleConsumerQ.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

boost::condition edm::SingleConsumerQ::push_cond_
private

Definition at line 133 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

Queue edm::SingleConsumerQ::queue_
private

Definition at line 126 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

boost::mutex edm::SingleConsumerQ::queue_lock_
private

Definition at line 130 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().