27 lines
699 B
C
27 lines
699 B
C
#ifndef _RINGBUFFER_H_
|
|
#define _RINGBUFFER_H_
|
|
|
|
#include <stdint.h>
|
|
#include <pthread.h>
|
|
#include <stdbool.h>
|
|
|
|
#define BUFFER_SIZE 256
|
|
|
|
typedef struct {
|
|
void* buffer[BUFFER_SIZE+5];
|
|
uint32_t bufferReadIdx;
|
|
uint32_t bufferWriteIdx;
|
|
bool interrupted;
|
|
pthread_mutex_t eventMutex;
|
|
pthread_cond_t eventSignal;
|
|
} ringbuffer_t;
|
|
|
|
void ringbufferInit(ringbuffer_t *handle);
|
|
void ringbufferPut(ringbuffer_t *handle, void *f);
|
|
void *ringbufferGet(ringbuffer_t *handle);
|
|
void *ringbufferPeek(ringbuffer_t *handle); // get without remove
|
|
void ringbufferRemove(ringbuffer_t *handle); // remove element peeked before
|
|
void ringbufferInterrupt(ringbuffer_t *handle);
|
|
|
|
#endif // _RINGBUFFER_H_
|