lfringbuffer.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. #include "foundation/types.h"
  3. /* lock free floating point ring buffer
  4. generic implementation
  5. */
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. typedef struct lfringbuffer_s { } *lfringbuffer_t;
  10. /* create a ring buffer with the desired number of elements */
  11. int lfringbuffer_create(lfringbuffer_t *out_ring_buffer, size_t number_of_elements);
  12. int lfringbuffer_destroy(lfringbuffer_t ring_buffer);
  13. /* ----- Read functions ----- */
  14. /* get how many elements can currently be read */
  15. size_t lfringbuffer_read_available(lfringbuffer_t ring_buffer);
  16. /* retrieve a pointer that can be read from.
  17. you might have to call this twice, because of ring buffer wraparound
  18. call lfringbuffer_read_update() when you are done */
  19. int lfringbuffer_read_get(lfringbuffer_t ring_buffer, size_t elements_requested, const float **out_buffer, size_t *elements_available);
  20. /* call to acknowledge that you have read the bytes */
  21. void lfringbuffer_read_update(lfringbuffer_t ring_buffer, size_t elements_read);
  22. /* ----- Write functions ----- */
  23. /* get how many elements can currently be written */
  24. size_t lfringbuffer_write_available(lfringbuffer_t ring_buffer);
  25. /* retrieve a pointer that can be written to.
  26. you might have to call this twice, because of ring buffer wraparound
  27. call lfringbuffer_write_update() when you are done */
  28. int lfringbuffer_write_get(lfringbuffer_t ring_buffer, size_t elements_requested, float **out_buffer, size_t *elements_available);
  29. /* call to acknowledge that you have written the bytes */
  30. void lfringbuffer_write_update(lfringbuffer_t ring_buffer, size_t elements_read);
  31. size_t lfringbuffer_write_get_position(lfringbuffer_t ring_buffer);
  32. #ifdef __cplusplus
  33. }
  34. #endif