CMS 3D CMS Logo

SingleConsumerQ.cc
Go to the documentation of this file.
2 
3 namespace edm
4 {
5 
6  SingleConsumerQ::SingleConsumerQ(int max_event_size, int max_queue_depth):
7  max_event_size_(max_event_size),max_queue_depth_(max_queue_depth),
8  pos_(max_queue_depth-1),mem_(max_event_size * max_queue_depth),
9  buffer_pool_(),
10  queue_(max_queue_depth),
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  }
25 
27 
29  {
30  // get lock
31  std::unique_lock<std::mutex> 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  }
41 
43  {
44  // get lock
45  std::lock_guard<std::mutex> sl(pool_lock_);
46  ++pos_;
47  buffer_pool_[pos_] = v;
48  pool_cond_.notify_all();
49  }
50 
52  {
53  // get lock
54  std::unique_lock<std::mutex> 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
63  ++fpos_;
64  // signal consumer
65  pop_cond_.notify_all();
66  }
67 
69  {
70  // get lock
71  std::unique_lock<std::mutex> 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
79  ++bpos_;
80  // note that these operations cannot throw
81  // signal producer
82  push_cond_.notify_all();
83  return v;
84  }
85 
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  }
95 
97  {
99  }
100 }
std::condition_variable pop_cond_
void releaseConsumerBuffer(void *)
void releaseProducerBuffer(void *)
std::condition_variable pool_cond_
std::condition_variable push_cond_
void commitProducerBuffer(void *, int)
HLT enums.
void commitConsumerBuffer(void *, int)
SingleConsumerQ(int max_event_size, int max_queue_depth)