[Sofaswitch-svn] [commit] r409 - in sofaswitch/trunk/sofa: include/sofa src
Author: derek Date: Tue May 6 00:44:14 2008 New Revision: 409 Modified: sofaswitch/trunk/sofa/include/sofa/messlist.h sofaswitch/trunk/sofa/src/messages.cxx sofaswitch/trunk/sofa/src/messlist.cxx Log: fix logic in handling frames that initiate, but never go anywhere. These frames are now correctly deleted, and the leaks are fixed... Modified: sofaswitch/trunk/sofa/include/sofa/messlist.h ============================================================================== --- sofaswitch/trunk/sofa/include/sofa/messlist.h (original) +++ sofaswitch/trunk/sofa/include/sofa/messlist.h Tue May 6 00:44:14 2008 @@ -237,9 +237,10 @@ protected: #ifdef DOC_PLUS_PLUS /**The thread, which runs to destroy old and unwanted MessageFrame instances */ - void RemoveOldMessageFrames(PThread &, INT param); + void RemoveOldMessageFrameMain(PThread &, INT param); #else - PDECLARE_NOTIFIER(PThread, MessageFrameListPending, RemoveOldMessageFrames); + PDECLARE_NOTIFIER(PThread, MessageFrameListPending, + RemoveOldMessageFrameMain); #endif /**Do the work of the purger of old message frames */ Modified: sofaswitch/trunk/sofa/src/messages.cxx ============================================================================== --- sofaswitch/trunk/sofa/src/messages.cxx (original) +++ sofaswitch/trunk/sofa/src/messages.cxx Tue May 6 00:44:14 2008 @@ -367,7 +367,7 @@ void MessageFrame::OnTermination() { - PTRACE(5, " End of the emssage frame thread.for " << GetOurId()); + PTRACE(5, " End of the message frame thread.for " << GetOurId()); } void MessageFrame::ProcessIncomingMessages(PBYTEArray & block, Modified: sofaswitch/trunk/sofa/src/messlist.cxx ============================================================================== --- sofaswitch/trunk/sofa/src/messlist.cxx (original) +++ sofaswitch/trunk/sofa/src/messlist.cxx Tue May 6 00:44:14 2008 @@ -275,7 +275,7 @@ MessageFrameListPending::MessageFrameListPending() { MessageFrameList::Initialise(); - removeOldMessageFrame = PThread::Create(PCREATE_NOTIFIER(RemoveOldMessageFrames), 0, + removeOldMessageFrame = PThread::Create(PCREATE_NOTIFIER(RemoveOldMessageFrameMain), 0, PThread::NoAutoDeleteThread, PThread::LowPriority, PString("%X OldMessageFrame")); @@ -288,9 +288,9 @@ Terminate(); WaitForTermination(); - PTRACE(1, "Delete old message frame thread pending thread"); + PTRACE(5, "Delete old message frame thread pending thread"); delete removeOldMessageFrame; - PTRACE(1, "old Message Frame Pending collector now deleted. "); + PTRACE(5, "old Message Frame Pending collector now deleted. "); } void MessageFrameListPending::WaitForTermination() @@ -309,36 +309,52 @@ MessageFrameList::AddNewMessageFrame(src); } -void MessageFrameListPending::RemoveOldMessageFrames(PThread &, INT) +void MessageFrameListPending::RemoveOldMessageFrameMain(PThread &, INT) { + PTRACE(5, "old Message Frame Pending collector now START."); while(!removeAnother.Wait(delayPurgePeriod)) PurgeOldMessageFrameBody(10 * 1000); /* Pending frames can last for 10 seconds */ PurgeOldMessageFrameBody(0); - PTRACE(1, "old Message Frame Pending collector now start to exit "); + PTRACE(5, "old Message Frame Pending collector now start to exit "); } void MessageFrameListPending::PurgeOldMessageFrameBody(PINDEX maxTimeInterval) { PTimeInterval maxTime(maxTimeInterval); PWaitAndSignal m(mutex); - PTRACE(6, " One iteration of Message Frame garbage. Remove " << PAbstractList::GetSize()); + PTRACE(5, " One iteration of Message Frame garbage. Remove " << PAbstractList::GetSize()); - for (PINDEX i = PAbstractList::GetSize(); i > 0; i--) - if (((MessageFrame *)PAbstractList::GetAt(i - 1))->TimeSinceCreation() > maxTime) { - MessageFrame *dead = (MessageFrame *)PAbstractList::GetAt(i - 1); - PTRACE(3, " Message Frame pending delete " << dead->GetOurId()); - dead->Terminate(); + for (PINDEX i = PAbstractList::GetSize(); i > 0; i--) { + MessageFrame *possible = (MessageFrame *)PAbstractList::GetAt(i - 1); + PTRACE(5, possible->GetOurId() << " has been alive for " << possible->TimeSinceCreation()); + if (possible->TimeSinceCreation() > maxTime) { + PTRACE(5, " Message Frame pending delete " << possible->GetOurId()); + possible->Terminate(); + possible->WaitForTermination(); + PAbstractList::RemoveAt(i - 1); + delete possible; + continue; + } + PTRACE(5, "Message frame pending delete for " << possible->GetOurId() << " still alive"); + if (possible->IsTerminated()) { + PAbstractList::RemoveAt(i - 1); + delete possible; + } else { + PTRACE(5, "Message frame pending delete for " << possible->GetOurId() << " skipped as still alive"); } + } if (PAbstractList::GetSize() > 0) { - PTRACE(6, " One iteration of Message Frame pending. Remaining " + PTRACE(5, " One iteration of Message Frame pending. Remaining " << PAbstractList::GetSize()); } } + + void MessageFrameListPending::SetPurgeInterval(PINDEX newInterval) { delayPurgePeriod = newInterval;
participants (1)
-
SofaSWITCH SVN