summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Kristjansson <danielk@cuymedia.net>2011-07-25 22:05:36 (GMT)
committer Daniel Kristjansson <danielk@cuymedia.net>2011-07-25 22:05:36 (GMT)
commit56350fb1adcbe7c90c8db41dda60797e023f9592 (patch)
tree717dbb2f5102c16e730b85bcbe6e7f078714a4b9
parent8bc2a66dd9e4927eb0931770f20ef56bbe792374 (diff)
Backports a small portion of the RingBuffer improvements from master.
-rw-r--r--mythtv/libs/libmythtv/RingBuffer.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/mythtv/libs/libmythtv/RingBuffer.cpp b/mythtv/libs/libmythtv/RingBuffer.cpp
index aaeab4d..cb077f7 100644
--- a/mythtv/libs/libmythtv/RingBuffer.cpp
+++ b/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();
}
}
}