Skip to content

Commit

Permalink
Backports a small portion of the RingBuffer improvements from master.
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-kristjansson committed Jul 25, 2011
1 parent 8bc2a66 commit 56350fb
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions mythtv/libs/libmythtv/RingBuffer.cpp
Expand Up @@ -1270,6 +1270,8 @@ void RingBuffer::run(void)


int used = kBufferSize - ReadBufFree(); int used = kBufferSize - ReadBufFree();


bool reads_were_allowed = readsallowed;

if ((0 == read_return) || (numfailures > 5) || if ((0 == read_return) || (numfailures > 5) ||
(readsallowed != (used >= fill_min || ateof || (readsallowed != (used >= fill_min || ateof ||
setswitchtonext || commserror))) setswitchtonext || commserror)))
Expand Down Expand Up @@ -1312,7 +1314,7 @@ void RingBuffer::run(void)


VERBOSE(VB_FILE|VB_EXTRA, LOC + "@ end of read ahead loop"); 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)) (wanttoread <= used && wanttoread > 0))
{ {
// To give other threads a good chance to handle these // To give other threads a good chance to handle these
Expand All @@ -1326,10 +1328,18 @@ void RingBuffer::run(void)
else else
{ {
// yield if we have nothing to do... // yield if we have nothing to do...
if (!request_pause && if (!request_pause && reads_were_allowed &&
(used >= fill_threshold || ateof || setswitchtonext)) (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();
} }
} }
} }
Expand Down

0 comments on commit 56350fb

Please sign in to comment.