diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2010-01-09 12:22:08 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2010-01-09 12:22:08 +0100 |
commit | b51a125c586f517761bae6eaff8ff8a08a1c1e09 (patch) | |
tree | 7174d9e3bdaae0ac2adef8c37792db222678781a /lf_ring_buffer.c | |
parent | 301cce4248a48512b87431509f406d59728ac886 (diff) | |
download | lock_free-b51a125c586f517761bae6eaff8ff8a08a1c1e09.zip lock_free-b51a125c586f517761bae6eaff8ff8a08a1c1e09.tar.gz |
lf_ring_buffer : use LFRB_DATA_PTR, remove defined checks
Diffstat (limited to 'lf_ring_buffer.c')
-rw-r--r-- | lf_ring_buffer.c | 28 |
1 files changed, 3 insertions, 25 deletions
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 <string.h> #include <time.h> -#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) { |