Browse files

Backports a small portion of the RingBuffer improvements from master.

  • Loading branch information...
1 parent 8bc2a66 commit 56350fb1adcbe7c90c8db41dda60797e023f9592 @daniel-kristjansson daniel-kristjansson committed Jul 25, 2011
Showing with 13 additions and 3 deletions.
  1. +13 −3 mythtv/libs/libmythtv/RingBuffer.cpp
View
16 mythtv/libs/libmythtv/RingBuffer.cpp
@@ -1270,6 +1270,8 @@ void RingBuffer::run(void)
int used = kBufferSize - ReadBufFree();
+ bool reads_were_allowed = readsallowed;
+
if ((0 == read_return) || (numfailures > 5) ||
(readsallowed != (used >= fill_min || ateof ||
setswitchtonext || commserror)))
@@ -1312,7 +1314,7 @@ void RingBuffer::run(void)
VERBOSE(VB_FILE|VB_EXTRA, LOC + "@ end of read ahead loop");
- if (readsallowed || commserror || ateof || setswitchtonext ||
+ if (!readsallowed || commserror || ateof || setswitchtonext ||
(wanttoread <= used && wanttoread > 0))
{
// To give other threads a good chance to handle these
@@ -1326,10 +1328,18 @@ void RingBuffer::run(void)
else
{
// yield if we have nothing to do...
- if (!request_pause &&
+ if (!request_pause && reads_were_allowed &&
(used >= fill_threshold || ateof || setswitchtonext))
{
- generalWait.wait(&rwlock, 1000);
+ generalWait.wait(&rwlock, 100);
+ }
+ else if (readsallowed)
+ { // if reads are allowed release the lock and yield so the
+ // reader gets a chance to read before the buffer is full.
+ generalWait.wakeAll();
+ rwlock.unlock();
+ usleep(5 * 1000);
+ rwlock.lockForRead();
}
}
}

0 comments on commit 56350fb

Please sign in to comment.