From 1b393afeafa57a1a9baf72834b4f75388361931e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 12 Jan 2010 12:58:49 +0100 Subject: rename struct ring_buffer into ringbuffer --- .gitignore | 3 +-- lf_ringbuffer.c | 18 +++++++++--------- lf_ringbuffer.h | 18 +++++++++--------- lf_ringbuffer_test.c | 34 +++++++++++++++++----------------- 4 files changed, 36 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index 2bdb0e4..4ea41d1 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,5 @@ cas container_of lf_fifo_test -lf_ring_buffer_test -lf_ring_buffer_test2 +lf_ringbuffer_test lock_free_queue_test diff --git a/lf_ringbuffer.c b/lf_ringbuffer.c index 99b8766..facf055 100644 --- a/lf_ringbuffer.c +++ b/lf_ringbuffer.c @@ -63,13 +63,13 @@ * Thus the maximum size of the buffer is 0xffff-1 = 65534 elements */ -/* initialize an empty lf_ring_buffer struct */ -lf_ring_buffer_t* lf_ring_buffer_create( size_t n_buf ) { +/* initialize an empty lf_ringbuffer struct */ +lf_ringbuffer_t* lf_ringbuffer_create( size_t n_buf ) { if(n_buf>=USHORTMAX) { return NULL; } - /* alloc ring_buffer struct */ - lf_ring_buffer_t *r = malloc(sizeof(lf_ring_buffer_t)); + /* alloc ringbuffer struct */ + lf_ringbuffer_t *r = malloc(sizeof(lf_ringbuffer_t)); if(r==NULL) return NULL; /* alloc buffer */ r->buffer = malloc(LFRB_BUFFER_SIZE*n_buf); @@ -83,17 +83,17 @@ lf_ring_buffer_t* lf_ring_buffer_create( size_t n_buf ) { return r; } -/* destroy an lf_ring_buffer strcture */ -void lf_ring_buffer_destroy( lf_ring_buffer_t *r ) { +/* destroy an lf_ringbuffer strcture */ +void lf_ringbuffer_destroy( lf_ringbuffer_t *r ) { free(r->buffer); free(r); } /* return 1 if is empty */ -int lf_ring_buffer_empty( lf_ring_buffer_t *r ) { return (r->indexes>>16)==USHORTMAX; } +int lf_ringbuffer_empty( lf_ringbuffer_t *r ) { return (r->indexes>>16)==USHORTMAX; } /* write data into the ring buffer */ -int lf_ring_buffer_write( lf_ring_buffer_t *r, void *data, int flags ) { +int lf_ringbuffer_write( lf_ringbuffer_t *r, void *data, int flags ) { unsigned int current, next; unsigned int write_to, read_from; struct timespec backoff; @@ -139,7 +139,7 @@ int lf_ring_buffer_write( lf_ring_buffer_t *r, void *data, int flags ) { } /* read data from the ring buffer */ -int lf_ring_buffer_read( lf_ring_buffer_t *r, void *data, int flags ) { +int lf_ringbuffer_read( lf_ringbuffer_t *r, void *data, int flags ) { unsigned int current, next; unsigned int write_to, read_from, tmp; struct timespec backoff; diff --git a/lf_ringbuffer.h b/lf_ringbuffer.h index 2266ba2..a5dc0cb 100644 --- a/lf_ringbuffer.h +++ b/lf_ringbuffer.h @@ -39,32 +39,32 @@ extern "C" { #define IS_NOT_BLOCKING( flags ) ( (flags)&LFRB_NO_BLOCK ) /* the ring buffer structure */ -typedef struct ring_buffer { +typedef struct ringbuffer { LFRB_BUFFER_TYPE *buffer; /* buffer data */ size_t n_buf; /* number of buffers, max 65534, see implementation for details */ unsigned int indexes; /* indexes where to read_from and write_to */ -} lf_ring_buffer_t; +} lf_ringbuffer_t; -/* return an initialized lf_ring_buffer_t struct, size is limited to 65534, see implementation for details */ -lf_ring_buffer_t* lf_ring_buffer_create( size_t n_buf ); +/* return an initialized lf_ringbuffer_t struct, size is limited to 65534, see implementation for details */ +lf_ringbuffer_t* lf_ringbuffer_create( size_t n_buf ); -/* destroy an lf_ring_buffer_t struct */ -void lf_ring_buffer_destroy( lf_ring_buffer_t *r ); +/* destroy an lf_ringbuffer_t struct */ +void lf_ringbuffer_destroy( lf_ringbuffer_t *r ); /* return 1 if is empty */ -int lf_ring_buffer_empty( lf_ring_buffer_t *r ); +int lf_ringbuffer_empty( lf_ringbuffer_t *r ); /* write data into the ring buffer * return 0 on success * return -1 if IS_NOT_BLOCKING and buffer is full */ -int lf_ring_buffer_write( lf_ring_buffer_t *r, void *data, int flags ); +int lf_ringbuffer_write( lf_ringbuffer_t *r, void *data, int flags ); /* read data from the ring buffer * return 0 on success * return -1 if IS_NOT_BLOCKING and buffer is empty */ -int lf_ring_buffer_read( lf_ring_buffer_t *r, void *data, int flags ); +int lf_ringbuffer_read( lf_ringbuffer_t *r, void *data, int flags ); # ifdef __cplusplus } diff --git a/lf_ringbuffer_test.c b/lf_ringbuffer_test.c index 8c41b97..eca1cca 100644 --- a/lf_ringbuffer_test.c +++ b/lf_ringbuffer_test.c @@ -27,7 +27,7 @@ static void report( char* op, int n, uint64_t dt, int redo ) { } struct thread_params { - lf_ring_buffer_t *ring; + lf_ringbuffer_t *ring; int n; int flags; uint64_t dt; @@ -42,16 +42,16 @@ static void feed_data( int n){ } */ -static uint64_t sequential_writes( lf_ring_buffer_t *ring, int n, int flags ) { +static uint64_t sequential_writes( lf_ringbuffer_t *ring, int n, int flags ) { int i, redo=0; rb_data_t data[RB_DATA_LEN]; struct timespec start, end; clock_gettime(CLOCK_MONOTONIC, &start); if(flags==0) { - for(i=0; i