CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Types | Private Attributes
edm::SingleConsumerQ Class Reference

#include <SingleConsumerQ.h>

Classes

struct  Buffer
 
struct  ConsumerType
 
class  OperateBuffer
 
struct  ProducerType
 

Public Types

typedef OperateBuffer< ConsumerTypeConsumerBuffer
 
typedef OperateBuffer< ProducerTypeProducerBuffer
 

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 (const SingleConsumerQ &)=delete
 
 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 Attributes

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

Detailed Description

Definition at line 43 of file SingleConsumerQ.h.

Member Typedef Documentation

◆ ByteArray

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

Definition at line 107 of file SingleConsumerQ.h.

◆ ConsumerBuffer

Definition at line 91 of file SingleConsumerQ.h.

◆ Pool

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

Definition at line 109 of file SingleConsumerQ.h.

◆ ProducerBuffer

Definition at line 92 of file SingleConsumerQ.h.

◆ Queue

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

Definition at line 111 of file SingleConsumerQ.h.

Constructor & Destructor Documentation

◆ SingleConsumerQ() [1/2]

edm::SingleConsumerQ::SingleConsumerQ ( const SingleConsumerQ )
delete

◆ SingleConsumerQ() [2/2]

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

Definition at line 5 of file SingleConsumerQ.cc.

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

10  buffer_pool_(),
12  fpos_(),
13  bpos_(),
14  pool_lock_(),
15  queue_lock_(),
16  pool_cond_(),
17  pop_cond_(),
18  push_cond_() {
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  }
std::condition_variable pop_cond_
std::condition_variable pool_cond_
std::condition_variable push_cond_

◆ ~SingleConsumerQ()

edm::SingleConsumerQ::~SingleConsumerQ ( )

Definition at line 25 of file SingleConsumerQ.cc.

25 {}

Member Function Documentation

◆ commitConsumerBuffer()

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

◆ commitProducerBuffer()

void edm::SingleConsumerQ::commitProducerBuffer ( void *  v,
int  len 
)

Definition at line 47 of file SingleConsumerQ.cc.

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

47  {
48  // get lock
49  std::unique_lock<std::mutex> sl(queue_lock_);
50  // if full, wait for item to be removed
51  while ((bpos_ + max_queue_depth_) == fpos_) {
52  push_cond_.wait(sl);
53  }
54 
55  // put buffer into queue
56  queue_[fpos_ % max_queue_depth_] = Buffer(v, len);
57  ++fpos_;
58  // signal consumer
59  pop_cond_.notify_all();
60  }
std::condition_variable pop_cond_
std::condition_variable push_cond_

◆ getConsumerBuffer()

SingleConsumerQ::Buffer edm::SingleConsumerQ::getConsumerBuffer ( )

Definition at line 62 of file SingleConsumerQ.cc.

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

62  {
63  // get lock
64  std::unique_lock<std::mutex> sl(queue_lock_);
65  // if empty, wait for item to appear
66  while (bpos_ == fpos_) {
67  pop_cond_.wait(sl);
68  }
69  // get a buffer from the queue and return it
70  Buffer v = queue_[bpos_ % max_queue_depth_];
71  ++bpos_;
72  // note that these operations cannot throw
73  // signal producer
74  push_cond_.notify_all();
75  return v;
76  }
std::condition_variable pop_cond_
std::condition_variable push_cond_

◆ getProducerBuffer()

SingleConsumerQ::Buffer edm::SingleConsumerQ::getProducerBuffer ( )

Definition at line 27 of file SingleConsumerQ.cc.

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

27  {
28  // get lock
29  std::unique_lock<std::mutex> sl(pool_lock_);
30  // wait for buffer to appear
31  while (pos_ < 0) {
32  pool_cond_.wait(sl);
33  }
34  void* v = buffer_pool_[pos_];
35  --pos_;
36  return Buffer(v, max_event_size_);
37  }
std::condition_variable pool_cond_

◆ maxEventSize()

int edm::SingleConsumerQ::maxEventSize ( ) const
inline

Definition at line 102 of file SingleConsumerQ.h.

References max_event_size_.

102 { return max_event_size_; }

◆ maxQueueDepth()

int edm::SingleConsumerQ::maxQueueDepth ( ) const
inline

Definition at line 103 of file SingleConsumerQ.h.

References max_queue_depth_.

103 { return max_queue_depth_; }

◆ releaseConsumerBuffer()

void edm::SingleConsumerQ::releaseConsumerBuffer ( void *  v)

Definition at line 78 of file SingleConsumerQ.cc.

References releaseProducerBuffer(), and findQualityFiles::v.

78  {
79  // should the buffer be placed back onto the queue and not released?
80  // we got here because a commit did to occur in the consumer.
81  // we will allow consumers to call or not call commit for now, meaning
82  // that we cannot distinguish between exception conditions and normal
83  // return. The buffer will always be released
85  }
void releaseProducerBuffer(void *)

◆ releaseProducerBuffer()

void edm::SingleConsumerQ::releaseProducerBuffer ( void *  v)

Definition at line 39 of file SingleConsumerQ.cc.

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

Referenced by commitConsumerBuffer(), and releaseConsumerBuffer().

39  {
40  // get lock
41  std::lock_guard<std::mutex> sl(pool_lock_);
42  ++pos_;
43  buffer_pool_[pos_] = v;
44  pool_cond_.notify_all();
45  }
std::condition_variable pool_cond_

Member Data Documentation

◆ bpos_

unsigned int edm::SingleConsumerQ::bpos_
private

Definition at line 119 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

◆ buffer_pool_

Pool edm::SingleConsumerQ::buffer_pool_
private

Definition at line 117 of file SingleConsumerQ.h.

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

◆ fpos_

unsigned int edm::SingleConsumerQ::fpos_
private

Definition at line 119 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

◆ max_event_size_

int edm::SingleConsumerQ::max_event_size_
private

Definition at line 113 of file SingleConsumerQ.h.

Referenced by getProducerBuffer(), and maxEventSize().

◆ max_queue_depth_

int edm::SingleConsumerQ::max_queue_depth_
private

Definition at line 114 of file SingleConsumerQ.h.

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

◆ mem_

ByteArray edm::SingleConsumerQ::mem_
private

Definition at line 116 of file SingleConsumerQ.h.

Referenced by SingleConsumerQ().

◆ pool_cond_

std::condition_variable edm::SingleConsumerQ::pool_cond_
private

Definition at line 123 of file SingleConsumerQ.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

◆ pool_lock_

std::mutex edm::SingleConsumerQ::pool_lock_
private

Definition at line 121 of file SingleConsumerQ.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

◆ pop_cond_

std::condition_variable edm::SingleConsumerQ::pop_cond_
private

Definition at line 124 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

◆ pos_

int edm::SingleConsumerQ::pos_
private

Definition at line 115 of file SingleConsumerQ.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

◆ push_cond_

std::condition_variable edm::SingleConsumerQ::push_cond_
private

Definition at line 125 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

◆ queue_

Queue edm::SingleConsumerQ::queue_
private

Definition at line 118 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

◆ queue_lock_

std::mutex edm::SingleConsumerQ::queue_lock_
private

Definition at line 122 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().