Now handling a race condition where the buffer is emptied between where it is read and where it is told how much has been read from it

CQTexperiment
Chris Moeller 2013-10-13 05:59:19 -07:00
parent a52c54a12c
commit 70e571fed9
1 changed files with 7 additions and 1 deletions

View File

@ -69,7 +69,7 @@ static void deallocateVirtualBuffer(void *buffer, UInt32 bufferLength);
- (BOOL)isEmpty
{
return (readPointer != NULL && writePointer != NULL);
return (readPointer == NULL && writePointer == NULL);
}
@ -127,6 +127,12 @@ static void deallocateVirtualBuffer(void *buffer, UInt32 bufferLength);
void *newReadPointer;
newReadPointer = readPointer + length;
if (newReadPointer == (void *)(intptr_t) length) {
// Someone somehow read from us before another thread emptied the buffer
newReadPointer = NULL;
}
if (newReadPointer >= bufferEnd)
newReadPointer -= bufferLength;