Attempt to fix segmentation fault at close; widen the effective critical

section area and prohibit Close() from accessing it at the same time
with Action()
This commit is contained in:
Antti Seppälä 2007-10-20 08:32:00 +00:00
parent 3e989d7050
commit 7511373d74
1 changed files with 9 additions and 4 deletions

View File

@ -3,7 +3,7 @@
* *
* See the README file for copyright information and how to reach the author. * See the README file for copyright information and how to reach the author.
* *
* $Id: streamer.c,v 1.25 2007/10/19 22:18:55 rahrenbe Exp $ * $Id: streamer.c,v 1.26 2007/10/20 08:32:00 ajhseppa Exp $
*/ */
#include <vdr/thread.h> #include <vdr/thread.h>
@ -35,17 +35,19 @@ void cIptvStreamer::Action(void)
while (Running()) { while (Running()) {
if (ringBuffer && mutex && protocol && ringBuffer->Free()) { if (ringBuffer && mutex && protocol && ringBuffer->Free()) {
unsigned char *buffer = NULL; unsigned char *buffer = NULL;
mutex->Lock();
int length = protocol->Read(&buffer); int length = protocol->Read(&buffer);
if (length >= 0) { if (length >= 0) {
AddStatistic(length); AddStatistic(length);
mutex->Lock();
int p = ringBuffer->Put(buffer, length); int p = ringBuffer->Put(buffer, length);
if (p != length && Running()) if (p != length && Running())
ringBuffer->ReportOverflow(length - p); ringBuffer->ReportOverflow(length - p);
mutex->Unlock(); mutex->Unlock();
} }
else else {
mutex->Unlock();
cCondWait::SleepMs(100); // to reduce cpu load cCondWait::SleepMs(100); // to reduce cpu load
}
} }
else else
cCondWait::SleepMs(100); // and avoid busy loop cCondWait::SleepMs(100); // and avoid busy loop
@ -72,8 +74,11 @@ bool cIptvStreamer::Close(void)
if (Running()) if (Running())
Cancel(3); Cancel(3);
// Close the protocol // Close the protocol
if (protocol) if (protocol) {
mutex->Lock();
protocol->Close(); protocol->Close();
mutex->Unlock();
}
return true; return true;
} }