-
Notifications
You must be signed in to change notification settings - Fork 0
/
ringbuffer.h
52 lines (39 loc) · 1.97 KB
/
ringbuffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*!
* \file ringbuffer.h
* \brief Public interface for ringbuffer.c
* \author Henrique Nascimento Gouveia <henrique.gouveia@aker.com.br>
*/
#ifndef _AKWBS_MT_RINGBUFFER_H_
#define _AKWBS_MT_RINGBUFFER_H_
#define RING_BUFFER_SUCCESS 0 /*!< Return value for success. */
#define RING_BUFFER_ERROR -1 /*!< Return value for error. */
#define RING_BUFFER_ERROR_INVALID_PARAMETER -2 /*!< Invalid parameter. */
#define RING_BUFFER_ERROR_NO_SPARE_ROOM -3 /*!< The buffer do NOT have space to
* store all the data.
*/
#define RING_BUFFER_IS_FULL -4 /*!< Buffer is full. */
#define RING_BUFFER_PATH \
"/tmp/ring-buffer-XXXXXX" /*!< Path of the buffer. */
/*!
* Structure representing a buffer and its accounting.
*/
struct ring_buffer
{
void *address; /*!< Buffer's address. */
size_t count_bytes; /*!< Bytes on buffer. */
size_t write_offset_bytes; /*!< Offset where new data must be written. */
size_t read_offset_bytes; /*!< Offset where new data must be read. */
};
/*
* Public interface.
*/
int ring_buffer_create (struct ring_buffer *buffer, size_t order);
int ring_buffer_free (struct ring_buffer *buffer);
void *ring_buffer_write_address(struct ring_buffer *buffer);
void ring_buffer_write_advance(struct ring_buffer *buffer, size_t count_bytes);
void *ring_buffer_read_address(struct ring_buffer *buffer);
void ring_buffer_read_advance(struct ring_buffer *buffer, size_t count_bytes);
unsigned long ring_buffer_count_bytes(struct ring_buffer *buffer);
unsigned long ring_buffer_count_free_bytes(struct ring_buffer *buffer);
void ring_buffer_clear(struct ring_buffer *buffer);
#endif