Skip to content
Snippets Groups Projects
Commit 48dbb7f5 authored by rswindell's avatar rswindell
Browse files

Bugfix: leave ringbuf mutex protected through-out RingBufRead() - should keep

semaphore from being prematurely reset.
parent 3721e701
No related branches found
No related tags found
No related merge requests found
...@@ -227,14 +227,12 @@ DWORD RINGBUFCALL RingBufRead( RingBuf* rb, BYTE* dst, DWORD cnt ) ...@@ -227,14 +227,12 @@ DWORD RINGBUFCALL RingBufRead( RingBuf* rb, BYTE* dst, DWORD cnt )
{ {
DWORD max, first, remain, len; DWORD max, first, remain, len;
len = RingBufFull( rb );
if( len == 0 )
return(0);
#ifdef RINGBUF_MUTEX #ifdef RINGBUF_MUTEX
pthread_mutex_lock(&rb->mutex); pthread_mutex_lock(&rb->mutex);
#endif #endif
len = RINGBUF_FILL_LEVEL(rb);
if( len < cnt ) if( len < cnt )
cnt = len; cnt = len;
...@@ -249,7 +247,7 @@ DWORD RINGBUFCALL RingBufRead( RingBuf* rb, BYTE* dst, DWORD cnt ) ...@@ -249,7 +247,7 @@ DWORD RINGBUFCALL RingBufRead( RingBuf* rb, BYTE* dst, DWORD cnt )
remain = cnt - first; remain = cnt - first;
} }
if(dst!=NULL) { if(first && dst!=NULL) {
rb_memcpy( dst, rb->pTail, first ); rb_memcpy( dst, rb->pTail, first );
dst += first; dst += first;
} }
...@@ -267,14 +265,14 @@ DWORD RINGBUFCALL RingBufRead( RingBuf* rb, BYTE* dst, DWORD cnt ) ...@@ -267,14 +265,14 @@ DWORD RINGBUFCALL RingBufRead( RingBuf* rb, BYTE* dst, DWORD cnt )
rb->pTail = rb->pStart; rb->pTail = rb->pStart;
#ifdef RINGBUF_SEM /* clear/signal semaphores, if appropriate */ #ifdef RINGBUF_SEM /* clear/signal semaphores, if appropriate */
if(len-cnt==0) /* empty */ if(RINGBUF_FILL_LEVEL(rb) == 0) /* empty */
sem_reset(&rb->sem); sem_reset(&rb->sem);
if(len-cnt<rb->highwater_mark) if(RINGBUF_FILL_LEVEL(rb) < rb->highwater_mark)
sem_reset(&rb->highwater_sem); sem_reset(&rb->highwater_sem);
#endif #endif
#ifdef RINGBUF_EVENT #ifdef RINGBUF_EVENT
if(rb->empty_event!=NULL && len-cnt==0) if(rb->empty_event!=NULL && RINGBUF_FILL_LEVEL(rb)==0)
SetEvent(rb->empty_event); SetEvent(rb->empty_event);
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment