CMS 3D CMS Logo

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

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 108 of file SingleConsumerQ.h.

◆ ConsumerBuffer

Definition at line 89 of file SingleConsumerQ.h.

◆ Pool

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

Definition at line 110 of file SingleConsumerQ.h.

◆ ProducerBuffer

Definition at line 90 of file SingleConsumerQ.h.

◆ Queue

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

Definition at line 112 of file SingleConsumerQ.h.

Constructor & Destructor Documentation

◆ SingleConsumerQ() [1/2]

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

Definition at line 5 of file SingleConsumerQ.cc.

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  }

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

◆ ~SingleConsumerQ()

edm::SingleConsumerQ::~SingleConsumerQ ( )

Definition at line 25 of file SingleConsumerQ.cc.

25 {}

◆ SingleConsumerQ() [2/2]

edm::SingleConsumerQ::SingleConsumerQ ( const SingleConsumerQ )
privatedelete

Member Function Documentation

◆ commitConsumerBuffer()

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

Definition at line 87 of file SingleConsumerQ.cc.

References releaseProducerBuffer(), and findQualityFiles::v.

◆ commitProducerBuffer()

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

Definition at line 47 of file SingleConsumerQ.cc.

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  }

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

◆ getConsumerBuffer()

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

Definition at line 62 of file SingleConsumerQ.cc.

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  }

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

◆ getProducerBuffer()

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

Definition at line 27 of file SingleConsumerQ.cc.

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  }

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

◆ maxEventSize()

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

Definition at line 100 of file SingleConsumerQ.h.

100 { return max_event_size_; }

References max_event_size_.

◆ maxQueueDepth()

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

Definition at line 101 of file SingleConsumerQ.h.

101 { return max_queue_depth_; }

References max_queue_depth_.

◆ releaseConsumerBuffer()

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

Definition at line 78 of file SingleConsumerQ.cc.

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  }

References releaseProducerBuffer(), and findQualityFiles::v.

◆ releaseProducerBuffer()

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

Definition at line 39 of file SingleConsumerQ.cc.

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  }

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

Referenced by commitConsumerBuffer(), and releaseConsumerBuffer().

Member Data Documentation

◆ bpos_

unsigned int edm::SingleConsumerQ::bpos_
private

Definition at line 120 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

◆ buffer_pool_

Pool edm::SingleConsumerQ::buffer_pool_
private

Definition at line 118 of file SingleConsumerQ.h.

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

◆ fpos_

unsigned int edm::SingleConsumerQ::fpos_
private

Definition at line 120 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

◆ max_event_size_

int edm::SingleConsumerQ::max_event_size_
private

Definition at line 114 of file SingleConsumerQ.h.

Referenced by getProducerBuffer(), and maxEventSize().

◆ max_queue_depth_

int edm::SingleConsumerQ::max_queue_depth_
private

Definition at line 115 of file SingleConsumerQ.h.

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

◆ mem_

ByteArray edm::SingleConsumerQ::mem_
private

Definition at line 117 of file SingleConsumerQ.h.

Referenced by SingleConsumerQ().

◆ pool_cond_

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

Definition at line 124 of file SingleConsumerQ.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

◆ pool_lock_

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

Definition at line 122 of file SingleConsumerQ.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

◆ pop_cond_

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

Definition at line 125 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

◆ pos_

int edm::SingleConsumerQ::pos_
private

Definition at line 116 of file SingleConsumerQ.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

◆ push_cond_

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

Definition at line 126 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

◆ queue_

Queue edm::SingleConsumerQ::queue_
private

Definition at line 119 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

◆ queue_lock_

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

Definition at line 123 of file SingleConsumerQ.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

edm::SingleConsumerQ::pool_cond_
std::condition_variable pool_cond_
Definition: SingleConsumerQ.h:124
mps_fire.i
i
Definition: mps_fire.py:355
edm::SingleConsumerQ::pos_
int pos_
Definition: SingleConsumerQ.h:116
findQualityFiles.v
v
Definition: findQualityFiles.py:179
edm::SingleConsumerQ::max_queue_depth_
int max_queue_depth_
Definition: SingleConsumerQ.h:115
edm::SingleConsumerQ::releaseProducerBuffer
void releaseProducerBuffer(void *)
Definition: SingleConsumerQ.cc:39
edm::SingleConsumerQ::pop_cond_
std::condition_variable pop_cond_
Definition: SingleConsumerQ.h:125
edm::SingleConsumerQ::queue_lock_
std::mutex queue_lock_
Definition: SingleConsumerQ.h:123
reco_skim_cfg_mod.max_event_size
max_event_size
Definition: reco_skim_cfg_mod.py:124
edm::SingleConsumerQ::mem_
ByteArray mem_
Definition: SingleConsumerQ.h:117
edm::SingleConsumerQ::buffer_pool_
Pool buffer_pool_
Definition: SingleConsumerQ.h:118
edm::SingleConsumerQ::queue_
Queue queue_
Definition: SingleConsumerQ.h:119
edm::SingleConsumerQ::fpos_
unsigned int fpos_
Definition: SingleConsumerQ.h:120
edm::SingleConsumerQ::push_cond_
std::condition_variable push_cond_
Definition: SingleConsumerQ.h:126
edm::SingleConsumerQ::max_event_size_
int max_event_size_
Definition: SingleConsumerQ.h:114
edm::SingleConsumerQ::bpos_
unsigned int bpos_
Definition: SingleConsumerQ.h:120
edm::SingleConsumerQ::pool_lock_
std::mutex pool_lock_
Definition: SingleConsumerQ.h:122
reco_skim_cfg_mod.max_queue_depth
max_queue_depth
Definition: reco_skim_cfg_mod.py:128