Skip to content
jonathan-beard edited this page Sep 15, 2014 · 3 revisions

master branch

The master branch has the basic, non-instrumented queue that currently works with heap memory allocated via C malloc and POSIX shared memory.

To instantiate the queue you simply instantiate an object with the appropriate template parameters as follows: RingBuffer< std::int64_t > fifo;

You could also use the base object as follows:

FIFO *fifo( new RingBuffer< std::int64_t >( 100 /* size */) );

A very basic example:

void
producer( FIFO *buffer )
{
   std::int64_t current_count( 0 );
   while( current_count++ < 1e6)
   {
      /** perform blocking call to FIFO to allocate memory **/
      auto &ref( buffer->allocate< std::int64_t >() );
      /** do something with ref **/
      ref = current_count;
      /** release data element ref to FIFO for consumer to receive **/
      buffer->push( (current_count == data.send_count ? 
                     RBSignal::RBEOF : RBSignal::NONE ) );
   }
   return;
}

void
consumer( FIFO *buffer )
{
   RBSignal signal( RBSignal::NONE );
   while( signal != RBSignal::RBEOF )
   {
      /** pop data element and get current signal **/
      buffer->pop( current_count, &signal );
   }
   return;
}

int
main( int argc, char **argv )
{
   /** instantiate new FIFO object **/
   FIFO *buffer( new RingBuffer< std::int64_t >( 100 ) );
   /** create new thread for producer, pass buffer **/
   std::thread a( producer,
                  buffer );
   /** create new thread for consumer, pass buffer **/
   std::thread b( consumer,
                  buffer );

   /** join both threads **/
   a.join();
   b.join();
   
   /** done, delete buffer and return **/
   delete( buffer );
   return;
}

dev branch

Clone this wiki locally