CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes
edm::EventBuffer Class Reference

#include <EventBuffer.h>

Classes

struct  Buffer
 
struct  ConsumerType
 
class  OperateBuffer
 
struct  ProducerType
 

Public Types

typedef OperateBuffer
< ConsumerType
ConsumerBuffer
 
typedef OperateBuffer
< ProducerType
ProducerBuffer
 

Public Member Functions

void commitConsumerBuffer (void *, int)
 
void commitProducerBuffer (void *, int)
 
bool empty ()
 
 EventBuffer (int max_event_size, int max_queue_depth)
 
Buffer getConsumerBuffer ()
 
Buffer getProducerBuffer ()
 
int maxEventSize () const
 
int maxQueueDepth () const
 
void releaseConsumerBuffer (void *)
 
void releaseProducerBuffer (void *)
 
 ~EventBuffer ()
 

Private Types

typedef std::vector< char > ByteArray
 
typedef std::vector< void * > Pool
 
typedef std::vector< BufferQueue
 

Private Member Functions

 EventBuffer (const EventBuffer &)
 

Private Attributes

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

Detailed Description

Definition at line 43 of file EventBuffer.h.

Member Typedef Documentation

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

Definition at line 115 of file EventBuffer.h.

Definition at line 96 of file EventBuffer.h.

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

Definition at line 117 of file EventBuffer.h.

Definition at line 97 of file EventBuffer.h.

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

Definition at line 119 of file EventBuffer.h.

Constructor & Destructor Documentation

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

Definition at line 7 of file EventBuffer.cc.

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

7  :
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  }
int i
Definition: DBlmapReader.cc:9
unsigned int fpos_
Definition: EventBuffer.h:127
unsigned int bpos_
Definition: EventBuffer.h:127
ByteArray mem_
Definition: EventBuffer.h:124
edm::EventBuffer::~EventBuffer ( )

Definition at line 20 of file EventBuffer.cc.

20 { }
edm::EventBuffer::EventBuffer ( const EventBuffer )
inlineprivate

Definition at line 112 of file EventBuffer.h.

112 { }

Member Function Documentation

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

Definition at line 90 of file EventBuffer.cc.

References releaseProducerBuffer().

Referenced by edm::EventBuffer::ConsumerType::commit().

91  {
93  }
mathSSE::Vec4< T > v
void releaseProducerBuffer(void *)
Definition: EventBuffer.cc:35
void edm::EventBuffer::commitProducerBuffer ( void *  v,
int  len 
)

Definition at line 45 of file EventBuffer.cc.

References bpos_, fpos_, max_queue_depth_, pop_cond_, push_cond_, queue_, and queue_lock_.

Referenced by edm::EventBuffer::ProducerType::commit().

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
55  queue_[fpos_ % max_queue_depth_]=Buffer(v,len);
56  ++fpos_;
57  // signal consumer
58  pop_cond_.notify_one();
59  // pop_cond_.notify_all();
60  }
unsigned int fpos_
Definition: EventBuffer.h:127
boost::mutex queue_lock_
Definition: EventBuffer.h:130
unsigned int bpos_
Definition: EventBuffer.h:127
boost::condition push_cond_
Definition: EventBuffer.h:133
boost::condition pop_cond_
Definition: EventBuffer.h:132
mathSSE::Vec4< T > v
bool edm::EventBuffer::empty ( void  )
inline

Definition at line 136 of file EventBuffer.h.

References bpos_, fpos_, and queue_lock_.

136 { boost::mutex::scoped_lock sl(queue_lock_); return (bpos_==fpos_); }
unsigned int fpos_
Definition: EventBuffer.h:127
boost::mutex queue_lock_
Definition: EventBuffer.h:130
unsigned int bpos_
Definition: EventBuffer.h:127
EventBuffer::Buffer edm::EventBuffer::getConsumerBuffer ( )

Definition at line 62 of file EventBuffer.cc.

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

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
71  Buffer v = queue_[bpos_ % max_queue_depth_];
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  }
unsigned int fpos_
Definition: EventBuffer.h:127
boost::mutex queue_lock_
Definition: EventBuffer.h:130
unsigned int bpos_
Definition: EventBuffer.h:127
boost::condition push_cond_
Definition: EventBuffer.h:133
boost::condition pop_cond_
Definition: EventBuffer.h:132
mathSSE::Vec4< T > v
EventBuffer::Buffer edm::EventBuffer::getProducerBuffer ( )

Definition at line 22 of file EventBuffer.cc.

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

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  }
boost::mutex pool_lock_
Definition: EventBuffer.h:129
boost::condition pool_cond_
Definition: EventBuffer.h:131
mathSSE::Vec4< T > v
int edm::EventBuffer::maxEventSize ( ) const
inline

Definition at line 107 of file EventBuffer.h.

References max_event_size_.

107 { return max_event_size_; }
int edm::EventBuffer::maxQueueDepth ( ) const
inline

Definition at line 108 of file EventBuffer.h.

References max_queue_depth_.

108 { return max_queue_depth_; }
void edm::EventBuffer::releaseConsumerBuffer ( void *  v)

Definition at line 80 of file EventBuffer.cc.

References releaseProducerBuffer().

Referenced by edm::EventBuffer::ConsumerType::release().

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  }
mathSSE::Vec4< T > v
void releaseProducerBuffer(void *)
Definition: EventBuffer.cc:35
void edm::EventBuffer::releaseProducerBuffer ( void *  v)

Definition at line 35 of file EventBuffer.cc.

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

Referenced by commitConsumerBuffer(), edm::EventBuffer::ProducerType::release(), and releaseConsumerBuffer().

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  }
boost::mutex pool_lock_
Definition: EventBuffer.h:129
boost::condition pool_cond_
Definition: EventBuffer.h:131
mathSSE::Vec4< T > v

Member Data Documentation

unsigned int edm::EventBuffer::bpos_
private

Definition at line 127 of file EventBuffer.h.

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

Pool edm::EventBuffer::buffer_pool_
private

Definition at line 125 of file EventBuffer.h.

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

unsigned int edm::EventBuffer::fpos_
private

Definition at line 127 of file EventBuffer.h.

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

int edm::EventBuffer::max_event_size_
private

Definition at line 121 of file EventBuffer.h.

Referenced by getProducerBuffer(), and maxEventSize().

int edm::EventBuffer::max_queue_depth_
private

Definition at line 122 of file EventBuffer.h.

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

ByteArray edm::EventBuffer::mem_
private

Definition at line 124 of file EventBuffer.h.

Referenced by EventBuffer().

boost::condition edm::EventBuffer::pool_cond_
private

Definition at line 131 of file EventBuffer.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

boost::mutex edm::EventBuffer::pool_lock_
private

Definition at line 129 of file EventBuffer.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

boost::condition edm::EventBuffer::pop_cond_
private

Definition at line 132 of file EventBuffer.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

int edm::EventBuffer::pos_
private

Definition at line 123 of file EventBuffer.h.

Referenced by getProducerBuffer(), and releaseProducerBuffer().

boost::condition edm::EventBuffer::push_cond_
private

Definition at line 133 of file EventBuffer.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

Queue edm::EventBuffer::queue_
private

Definition at line 126 of file EventBuffer.h.

Referenced by commitProducerBuffer(), and getConsumerBuffer().

boost::mutex edm::EventBuffer::queue_lock_
private

Definition at line 130 of file EventBuffer.h.

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