Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

simple lock free ringbuffer

License

NotificationsYou must be signed in to change notification settings

jonathan-beard/fifo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple ringbuffer template implementation in C++ thatcan utilize local or shared memory.

USE

Compile with -std=c++11 flag, there's an example threadedapp in main.cpp. One limitation of the SHM version is thatthe buffer must be statically sized. The locally allocatedversion can be allocated on the fly.

Default

By defualt this will build a library. The header file that should be includedwhen using the FIFO is simply fifo.hpp. It can be instantiated on SHM or heap.The size of each FIFO is static. It is also lock free.

Example

#include"fifo.hpp"#include<cstdint>#include<cstdlib>#include<iostream>#include<thread>usingringb_t =  RingBuffer< std::int64_t/* buffer type*/,                             Type::Heap/* allocation type*/                           >  TheBuffer;staticvoidfunc_a(ringb_t &buffer,bool &term ){int i =0;while( ! term )  {    buffer.push( i++ );  }return;}staticvoidfunc_b(ringb_t &buffer,bool &term ){while( ! term )  {int value;     buffer.push( value );    std::cout << value <<"\n";  }return;}intmain(){ringb_tbuffer(100/** size **/ );boolterm(false );  std::threada( func_a,std::ref( buffer ),std::ref( term ) );  std::threadb( func_b,std::ref( buffer ),std::ref( term ) );  term =true;  a.join();  b.join();return( EXIT_SUCCESS );}

TODO

  • Add TCP connected ringbuffer implementation.
  • Add Java implementation that can use the C/C++ allocated SHM with at least primitive types.
  • Add write and read optimizations.

About

simple lock free ringbuffer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp