From b51a125c586f517761bae6eaff8ff8a08a1c1e09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sat, 9 Jan 2010 12:22:08 +0100 Subject: lf_ring_buffer : use LFRB_DATA_PTR, remove defined checks --- Makefile | 2 +- lf_ring_buffer.c | 28 +++------------------------- lf_ring_buffer_data.h | 1 - 3 files changed, 4 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 212fc12..ba02f07 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ lf_fifo_test.o: lf_fifo_test.c lf_fifo_test: lf_fifo.o lf_fifo_test.o $(CC) lf_fifo.o lf_fifo_test.o -o lf_fifo_test -lf_ring_buffer.o: lf_ring_buffer.h lf_ring_buffer.c lf_portable_cas.h +lf_ring_buffer.o: lf_ring_buffer.h lf_ring_buffer.c lf_ring_buffer_data.h lf_portable_cas.h lf_ring_buffer_test.o: lf_ring_buffer_test.c lf_ring_buffer_test: lf_ring_buffer.o lf_ring_buffer_test.o $(CC) -lrt lf_ring_buffer.o lf_ring_buffer_test.o -o lf_ring_buffer_test diff --git a/lf_ring_buffer.c b/lf_ring_buffer.c index 79edcff..ec071ec 100644 --- a/lf_ring_buffer.c +++ b/lf_ring_buffer.c @@ -31,28 +31,6 @@ #include #include -#if !defined LFRB_DATA_SIZE - #error "LFRB_DATA_SIZE is not defined" -#endif -#if !defined LFRB_BUFFER_TYPE - #error "LFRB_BUFFER_TAPE is not defined" -#endif -#if !defined LFRB_BUFFER_SIZE - #error "LFRB_BUFFER_SIZE is not defined" -#endif -#if !defined LFRB_IS_AVAILABLE - #error "LFRB_IS_AVAILABLE is not defined" -#endif -#if !defined LFRB_MARK_AS_FILLED - #error "LFRB_MARK_AS_FILLED is not defined" -#endif -#if !defined LFRB_MARK_AS_READ - #error "LFRB_MARK_AS_READ is not defined" -#endif -#if !defined LFRB_DATA_PTR - #error "LFRB_DATA_PTR is not defined" -#endif - //#define DEBUG_LFR_RING 1 #ifdef DEBUG_LFR_RING @@ -110,7 +88,7 @@ int lf_ring_buffer_write( lf_ring_buffer_t *r, void *data, int flags ) { if( CompareAndSwapInt( &r->write_to, idx, next ) ) { /* !!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!! * - if the ring is empty before this write operation (r->read_from==-1 or latest idx) - * - and n_buf other threads call this same function before this point + * - and n_buf other threads execute this same function before the next CAS is finished * then, the last thread will : * - see this buffer as available * - and see the ring as empty instead of full !!!!! @@ -135,7 +113,7 @@ int lf_ring_buffer_write( lf_ring_buffer_t *r, void *data, int flags ) { } } /* fill this buffer and mark it as filled */ - memcpy( r->buffer[idx].data, data, LFRB_DATA_SIZE ); + memcpy( LFRB_DATA_PTR(r->buffer[idx]), data, LFRB_DATA_SIZE ); LFRB_MARK_AS_FILLED( r->buffer[idx] ); return 0; } @@ -150,7 +128,7 @@ int lf_ring_buffer_read( lf_ring_buffer_t *r, void *data, int flags ) { next = idx+1; if (next==r->n_buf) next=0; /* will do bad things if data dst buffer is too small !! */ - memcpy( data, r->buffer[idx].data, LFRB_DATA_SIZE ); + memcpy( data, LFRB_DATA_PTR(r->buffer[idx]), LFRB_DATA_SIZE ); _LOG_( "read: CAS %d %d %d\n", r->read_from, idx, next ); if( CompareAndSwapInt( &r->read_from, idx, next ) ) { if(r->read_from==r->write_to) { diff --git a/lf_ring_buffer_data.h b/lf_ring_buffer_data.h index cf6e9c9..6a1290f 100644 --- a/lf_ring_buffer_data.h +++ b/lf_ring_buffer_data.h @@ -18,4 +18,3 @@ typedef struct buffer { #define LFRB_MARK_AS_READ( el ) { (el).status=0; } #define LFRB_DATA_PTR( el ) (el).data - -- cgit v1.1-2-g2b99