ringbuffer  1.0.0
Platform-Agnostic Ring Buffer Implementation in C
ringbuffer.h
Go to the documentation of this file.
1 
6 #ifndef __RINGBUFFER_DECLARED
7 #define __RINGBUFFER_DECLARED
8 
9 #include <stdint.h>
10 
11 // Support for Windows DLL
12 #if __has_include(<windows.h>)
13  #if defined(__RINGBUFFER_INTERNAL)
14  #if defined(TEST_UNIT) || defined(TEST_INTEGRATION)
16  #define LINKED_FUNCTION extern
17  #else
19  #define LINKED_FUNCTION extern __declspec (dllexport)
20  #endif
21  #else
23  #define LINKED_FUNCTION __declspec (dllimport)
24  #endif
25 #else // __has_include(<windows.h>)
27  #define LINKED_FUNCTION extern
28 #endif // __has_include(<windows.h>)
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
41 struct ringbuffer_context;
42 
52 typedef struct ringbuffer_context *ringbuffer_context_t;
53 
93  void *target_array, const unsigned int element_size,
94  const unsigned int element_count, const unsigned int initial_read_index,
95  const unsigned int initial_write_index);
96 
139 LINKED_FUNCTION void ringbuffer_read (ringbuffer_context_t context,
140  void *pointer_to_output);
141 
181 LINKED_FUNCTION void ringbuffer_write (ringbuffer_context_t context,
182  const void *pointer_to_input);
183 
189 LINKED_FUNCTION unsigned int
191 
198 LINKED_FUNCTION unsigned int
200 
207 LINKED_FUNCTION unsigned int
209 
241 LINKED_FUNCTION void
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 
248 #undef LINKED_FUNCTION
249 
250 #endif // __RINGBUFFER_DECLARED
void ringbuffer_read(ringbuffer_context_t context, void *pointer_to_output)
Copy value from an element pointed by read index, to an intended variable.
void ringbuffer_destroy(ringbuffer_context_t *pointer_to_context)
Clean-up ringbuffer context then NULLify it.
struct ringbuffer_context * ringbuffer_context_t
Points to an allocated memory for ringbuffer module.
Definition: ringbuffer.h:52
ringbuffer_context_t ringbuffer_init(void *target_array, const unsigned int element_size, const unsigned int element_count, const unsigned int initial_read_index, const unsigned int initial_write_index)
Initiate a single instance of ringbuffer management.
void ringbuffer_write(ringbuffer_context_t context, const void *pointer_to_input)
Put value from a variable to an element which pointed by write index.
unsigned int ringbuffer_get_write_index(const ringbuffer_context_t context)
Get the write index, which means position of write cursor of ring buffer.
unsigned int ringbuffer_get_read_index(const ringbuffer_context_t context)
Get the read index, which means position of read cursor of ring buffer.
unsigned int ringbuffer_is_empty(const ringbuffer_context_t context)
Check if the ringbuffer is empty, which indicated by 'read index == write index'.