CMS 3D CMS Logo

SingleConsumerQ.cc
Go to the documentation of this file.
2 
3 namespace edm {
4 
6  : max_event_size_(max_event_size),
7  max_queue_depth_(max_queue_depth),
8  pos_(max_queue_depth - 1),
10  buffer_pool_(),
11  queue_(max_queue_depth),
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  }
24 
26 
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  }
38 
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  }
46 
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
57  ++fpos_;
58  // signal consumer
59  pop_cond_.notify_all();
60  }
61 
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
71  ++bpos_;
72  // note that these operations cannot throw
73  // signal producer
74  push_cond_.notify_all();
75  return v;
76  }
77 
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  }
86 
88 } // namespace edm
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(const SingleConsumerQ &)=delete