2011-04-14 23:03:20 +00:00
|
|
|
/*
|
|
|
|
* ringbuffer.h
|
|
|
|
*
|
|
|
|
* Created on: Apr 1, 2011
|
|
|
|
* Author: sears
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef RINGBUFFER_H_
|
|
|
|
#define RINGBUFFER_H_
|
|
|
|
#include <stasis/common.h>
|
|
|
|
BEGIN_C_DECLS
|
|
|
|
|
|
|
|
typedef struct stasis_ringbuffer_t stasis_ringbuffer_t;
|
|
|
|
|
2011-04-20 20:34:39 +00:00
|
|
|
stasis_ringbuffer_t * stasis_ringbuffer_init(intptr_t size, lsn_t initial_offset);
|
|
|
|
lsn_t stasis_ringbuffer_nb_reserve_space(stasis_ringbuffer_t * ring, lsn_t sz);
|
|
|
|
lsn_t stasis_ringbuffer_reserve_space(stasis_ringbuffer_t * ring, lsn_t sz, lsn_t * handle);
|
|
|
|
void stasis_ringbuffer_read_done(stasis_ringbuffer_t * ring, lsn_t * handle);
|
|
|
|
void stasis_ringbuffer_advance_write_tail(stasis_ringbuffer_t * ring, lsn_t off);
|
|
|
|
lsn_t stasis_ringbuffer_current_write_tail(stasis_ringbuffer_t * ring);
|
|
|
|
const void * stasis_ringbuffer_nb_get_rd_buf(stasis_ringbuffer_t * ring, lsn_t off, lsn_t sz);
|
2011-04-14 23:03:20 +00:00
|
|
|
// sz is a pointer to the desired size, or RING_NEXT for "as many bytes as possible"
|
2011-04-20 20:34:39 +00:00
|
|
|
lsn_t stasis_ringbuffer_consume_bytes(stasis_ringbuffer_t * ring, lsn_t* sz, lsn_t * handle);
|
|
|
|
void stasis_ringbuffer_write_done(stasis_ringbuffer_t * ring, lsn_t * handle);
|
2011-04-14 23:03:20 +00:00
|
|
|
// sz is a pointer to the desired size, or RING_NEXT for "as many bytes as possible"
|
2011-04-20 20:34:39 +00:00
|
|
|
const void * stasis_ringbuffer_get_rd_buf(stasis_ringbuffer_t * ring, lsn_t off, lsn_t sz);
|
|
|
|
void * stasis_ringbuffer_get_wr_buf(stasis_ringbuffer_t * ring, lsn_t off, lsn_t sz);
|
|
|
|
lsn_t stasis_ringbuffer_get_read_tail(stasis_ringbuffer_t * ring);
|
|
|
|
lsn_t stasis_ringbuffer_get_write_tail(stasis_ringbuffer_t * ring);
|
|
|
|
lsn_t stasis_ringbuffer_get_write_frontier(stasis_ringbuffer_t * ring);
|
|
|
|
void stasis_ringbuffer_advance_read_tail(stasis_ringbuffer_t * ring, lsn_t off);
|
2011-04-18 20:21:16 +00:00
|
|
|
typedef enum { RING_TORN = -1, RING_VOLATILE = -2, RING_FULL = -3, RING_TRUNCATED = -4, RING_NEXT = -5, RING_CLOSED = -6, RING_MINERR = -7 } stasis_ringbuffer_error_t;
|
2011-04-20 20:34:39 +00:00
|
|
|
void stasis_ringbuffer_flush(stasis_ringbuffer_t * ring, lsn_t off);
|
2011-04-14 23:03:20 +00:00
|
|
|
|
2011-05-14 03:49:38 +00:00
|
|
|
// Causes ringbuffer requests to stop blocking, and return RING_CLOSED
|
|
|
|
void stasis_ringbuffer_shutdown(stasis_ringbuffer_t * ring);
|
|
|
|
// Deallocates the ringbuffer (call after any threads using the ringbuffer have shutdown).
|
|
|
|
void stasis_ringbuffer_free(stasis_ringbuffer_t * ring);
|
2011-04-14 23:03:20 +00:00
|
|
|
END_C_DECLS
|
|
|
|
#endif /* RINGBUFFER_H_ */
|