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
parent
a52c54a12c
commit
70e571fed9
|
@ -69,7 +69,7 @@ static void deallocateVirtualBuffer(void *buffer, UInt32 bufferLength);
|
||||||
|
|
||||||
- (BOOL)isEmpty
|
- (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;
|
void *newReadPointer;
|
||||||
|
|
||||||
newReadPointer = readPointer + length;
|
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)
|
if (newReadPointer >= bufferEnd)
|
||||||
newReadPointer -= bufferLength;
|
newReadPointer -= bufferLength;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue