-
Notifications
You must be signed in to change notification settings - Fork 0
/
sbuffer.h
52 lines (43 loc) · 1.74 KB
/
sbuffer.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
/**
* \author Arthur Tavares Quintao
*/
#ifndef _SBUFFER_H_
#define _SBUFFER_H_
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <assert.h>
#include "config.h"
#define SBUFFER_FAILURE -1
#define SBUFFER_SUCCESS 0
#define SBUFFER_NO_DATA 1
typedef struct sbuffer sbuffer_t;
/**
* Allocates and initializes a new shared buffer
* \param buffer a double pointer to the buffer that needs to be initialized
* \return SBUFFER_SUCCESS on success and SBUFFER_FAILURE if an error occurred
*/
int sbuffer_init(sbuffer_t **buffer);
/**
* All allocated resources are freed and cleaned up
* \param buffer a double pointer to the buffer that needs to be freed
* \return SBUFFER_SUCCESS on success and SBUFFER_FAILURE if an error occurred
*/
int sbuffer_free(sbuffer_t **buffer);
/**
* Removes the first sensor data in 'buffer' (at the 'head') and returns this sensor data as '*data'
* If 'buffer' is empty, the function blocks until data becomes available.
*
* \param buffer a pointer to the buffer that is used
* \param data a pointer to pre-allocated sensor_data_t space, the data will be copied into this structure. No new memory is allocated for 'data' in this function.
* \return SBUFFER_SUCCESS on success and SBUFFER_FAILURE if an error occurred
*/
int sbuffer_remove(sbuffer_t *buffer, sensor_data_t *data);
/**
* Inserts the sensor data in 'data' at the end of 'buffer' (at the 'tail')
* \param buffer a pointer to the buffer that is used
* \param data a pointer to sensor_data_t data, that will be copied into the buffer
* \return SBUFFER_SUCCESS on success and SBUFFER_FAILURE if an error occurred
*/
int sbuffer_insert(sbuffer_t *buffer, sensor_data_t *data);
#endif //_SBUFFER_H_