CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EventBuffer.cc
Go to the documentation of this file.
1 
3 
4 namespace edm
5 {
6 
8  max_event_size_(max_event_size),max_queue_depth_(max_queue_depth),
9  pos_(max_queue_depth-1),mem_(max_event_size * max_queue_depth),
10  queue_(max_queue_depth),
11  fpos_(),bpos_()
12  {
13  // throw if event size 0 or queue depth 0
14 
15  for(char* i = &mem_[0]; i < &mem_[mem_.size()]; i += max_event_size)
16  buffer_pool_.push_back(i);
17 
18  }
19 
21 
23  {
24  // get lock
25  boost::mutex::scoped_lock sl(pool_lock_);
26  // wait for buffer to appear
27  while(pos_ < 0) {
28  pool_cond_.wait(sl);
29  }
30  void* v = buffer_pool_[pos_];
31  --pos_;
32  return Buffer(v,max_event_size_);
33  }
34 
36  {
37  // get lock
38  boost::mutex::scoped_lock sl(pool_lock_);
39  ++pos_;
40  buffer_pool_[pos_] = v;
41  pool_cond_.notify_one();
42  // pool_cond_.notify_all();
43  }
44 
45  void EventBuffer::commitProducerBuffer(void* v, int len)
46  {
47  // get lock
48  boost::mutex::scoped_lock sl(queue_lock_);
49  // if full, wait for item to be removed
50  while((bpos_+max_queue_depth_)==fpos_) {
51  push_cond_.wait(sl);
52  }
53 
54  // put buffer into queue
56  ++fpos_;
57  // signal consumer
58  pop_cond_.notify_one();
59  // pop_cond_.notify_all();
60  }
61 
63  {
64  // get lock
65  boost::mutex::scoped_lock sl(queue_lock_);
66  // if empty, wait for item to appear
67  while(bpos_==fpos_) {
68  pop_cond_.wait(sl);
69  }
70  // get a buffer from the queue and return it
72  ++bpos_;
73  // note that these operations cannot throw
74  // signal producer
75  push_cond_.notify_one();
76  // push_cond_.notify_all();
77  return v;
78  }
79 
81  {
82  // should the buffer be placed back onto the queue and not released?
83  // we got here because a commit did to occur in the consumer.
84  // we will allow consumers to call or not call commit for now, meaning
85  // that we cannot distinguish between exception conditions and normal
86  // return. The buffer will always be released
88  }
89 
91  {
93  }
94 }
int i
Definition: DBlmapReader.cc:9
Buffer getConsumerBuffer()
Definition: EventBuffer.cc:62
EventBuffer(int max_event_size, int max_queue_depth)
Definition: EventBuffer.cc:7
void commitProducerBuffer(void *, int)
Definition: EventBuffer.cc:45
boost::mutex pool_lock_
Definition: EventBuffer.h:129
unsigned int fpos_
Definition: EventBuffer.h:127
boost::mutex queue_lock_
Definition: EventBuffer.h:130
unsigned int bpos_
Definition: EventBuffer.h:127
boost::condition pool_cond_
Definition: EventBuffer.h:131
boost::condition push_cond_
Definition: EventBuffer.h:133
boost::condition pop_cond_
Definition: EventBuffer.h:132
Buffer getProducerBuffer()
Definition: EventBuffer.cc:22
void releaseConsumerBuffer(void *)
Definition: EventBuffer.cc:80
ByteArray mem_
Definition: EventBuffer.h:124
void commitConsumerBuffer(void *, int)
Definition: EventBuffer.cc:90
void releaseProducerBuffer(void *)
Definition: EventBuffer.cc:35