[Sofaswitch-svn] [commit] r411 - in sofaswitch/trunk/sofa: include/sofa src
Author: derek Date: Tue May 13 22:51:20 2008 New Revision: 411 Modified: sofaswitch/trunk/sofa/include/sofa/messlist.h sofaswitch/trunk/sofa/src/messlist.cxx Log: The building of MessageFrame instances in the library now checks the message frames created. Those that are terminated (for whatever reason) are automatically deleted. New ones are then built. 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 13 22:51:20 2008 @@ -185,6 +185,10 @@ PDECLARE_NOTIFIER(PThread, MessageFrameListProvider, MakeNewMessageFrames); #endif + /**Go through the list of frames. Any that have terminated are dead, and so + delete them */ + void RemoveDeadEntries(); + /**The thread which will create new instances of MessageFrame structures, as required */ PThread *makeNewMessageFrame; Modified: sofaswitch/trunk/sofa/src/messlist.cxx ============================================================================== --- sofaswitch/trunk/sofa/src/messlist.cxx (original) +++ sofaswitch/trunk/sofa/src/messlist.cxx Tue May 13 22:51:20 2008 @@ -140,6 +140,7 @@ } + void MessageFrameList::AddNewMessageFrame(MessageFrame *newEntry) { if (newEntry == NULL) { @@ -168,6 +169,30 @@ PTRACE(3, "Create new MessageFrame provider."); } +void MessageFrameListProvider::RemoveDeadEntries() +{ + MessageFrameList deads; + + { + PWaitAndSignal m(mutex); + for(PINDEX i = PAbstractList::GetSize(); i > 0; i--) { + PObject *p = PAbstractList::GetAt(i - 1); + MessageFrame * c = (MessageFrame *)p; + if (c == NULL) + continue; + if (c->IsTerminated()) { + deads.AddNewMessageFrame(c); + RemoveAt(i - 1); + } + } + } + while(deads.GetSize() > 0) { + PObject *f = deads.RemoveAt(0); + delete f; + } +} + + MessageFrameListProvider::~MessageFrameListProvider() { Terminate(); @@ -188,19 +213,19 @@ void MessageFrameListProvider::MakeNewMessageFrames(PThread &, INT ) { for( ;keepGoing; ) { - /**Put more nodes into the list */ - while ((GetSize() < requiredSize) && keepGoing) { - PTRACE(3, "We have to build a new message frame "); - MessageFrame *mf = BuildMessageFrame(); - if (mf != NULL) { - PTRACE(3, "reqeustnewid Add message frame to list of " << *mf); - AddNewMessageFrame(mf); - } else { - PTRACE(3, "We had an error in buildmessageframe - null returned"); + RemoveDeadEntries(); + while ((GetSize() < requiredSize) && keepGoing) { + PTRACE(3, "We have to build a new message frame "); + MessageFrame *mf = BuildMessageFrame(); + if (mf != NULL) { + PTRACE(3, "reqeustnewid Add message frame to list of " << *mf); + AddNewMessageFrame(mf); + } else { + PTRACE(3, "We had an error in buildmessageframe - null returned"); + } } - } - if (keepGoing) - makeAnother.Wait(); + if (keepGoing) + makeAnother.Wait(1000); } PTRACE(3, "End of message frame list provider thread "); }
participants (1)
-
SofaSWITCH SVN