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.
*
* $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>
@ -35,17 +35,19 @@ void cIptvStreamer::Action(void)
while (Running()) {
if (ringBuffer && mutex && protocol && ringBuffer->Free()) {
unsigned char *buffer = NULL;
mutex->Lock();
int length = protocol->Read(&buffer);
if (length >= 0) {
AddStatistic(length);
mutex->Lock();
int p = ringBuffer->Put(buffer, length);
if (p != length && Running())
ringBuffer->ReportOverflow(length - p);
mutex->Unlock();
}
else
else {
mutex->Unlock();
cCondWait::SleepMs(100); // to reduce cpu load
}
}
else
cCondWait::SleepMs(100); // and avoid busy loop
@ -72,8 +74,11 @@ bool cIptvStreamer::Close(void)
if (Running())
Cancel(3);
// Close the protocol
if (protocol)
if (protocol) {
mutex->Lock();
protocol->Close();
mutex->Unlock();
}
return true;
}