From 5dff51292c2d08b38db010dfe291c1e829e1945f Mon Sep 17 00:00:00 2001 From: louis Date: Wed, 5 Dec 2012 21:06:52 +0100 Subject: Fix Ticket 1147, cancelling threads in a safer way --- displaychannel.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'displaychannel.c') diff --git a/displaychannel.c b/displaychannel.c index ba8102c..563e50b 100644 --- a/displaychannel.c +++ b/displaychannel.c @@ -31,6 +31,9 @@ cNopacityDisplayChannel::cNopacityDisplayChannel(bool WithInfo) { } cNopacityDisplayChannel::~cNopacityDisplayChannel() { + Cancel(-1); + while (Active()) + cCondWait::SleepMs(10); osd->DestroyPixmap(pixmapBackgroundTop); osd->DestroyPixmap(pixmapBackgroundBottom); osd->DestroyPixmap(pixmapLogo); @@ -293,8 +296,7 @@ void cNopacityDisplayChannel::DrawSignal(void) { lastSignalStrength = SignalStrength; lastSignalQuality = SignalQuality; lastSignalDisplay = Now; - } - + } } void cNopacityDisplayChannel::SetChannel(const cChannel *Channel, int Number) { @@ -319,12 +321,12 @@ void cNopacityDisplayChannel::SetChannel(const cChannel *Channel, int Number) { ChannelNumber = cString::sprintf("%d%s", Channel->Number(), Number ? "-" : ""); } else groupSep = true; - } else if (Number) { + } else if (Number) { ChannelNumber = cString::sprintf("%d-", Number); } else { ChannelName = ChannelString(NULL, 0); } - + cString channelString = cString::sprintf("%s %s", *ChannelNumber, *ChannelName); if (!groupSep) { @@ -493,11 +495,11 @@ void cNopacityDisplayChannel::Flush(void) { void cNopacityDisplayChannel::Action(void) { uint64_t Start = cTimeMs::Now(); - while (true) { + while (Running()) { uint64_t Now = cTimeMs::Now(); cPixmap::Lock(); double t = min(double(Now - Start) / FadeTime, 1.0); - int Alpha = t * ALPHA_OPAQUE; + int Alpha = t * ALPHA_OPAQUE; pixmapBackgroundTop->SetAlpha(Alpha); pixmapBackgroundBottom->SetAlpha(Alpha); pixmapLogo->SetAlpha(Alpha); @@ -517,13 +519,14 @@ void cNopacityDisplayChannel::Action(void) { pixmapSignalMeter->SetAlpha(Alpha); pixmapSignalLabel->SetAlpha(Alpha); } - osd->Flush(); + if (Running()) + osd->Flush(); cPixmap::Unlock(); - int Delta = cTimeMs::Now() - Now; - if (Delta < FrameTime) - cCondWait::SleepMs(FrameTime - Delta); + int Delta = cTimeMs::Now() - Now; + if (Running() && (Delta < FrameTime)) + cCondWait::SleepMs(FrameTime - Delta); if ((int)(Now - Start) > FadeTime) { break; } - } + } } \ No newline at end of file -- cgit v1.2.3