r3138 - in trunk/libmsip: include/libmsip source
erik at minisip.org
erik at minisip.org
Mon Jan 22 14:45:18 CET 2007
Author: erik
Date: 2007-01-22 14:45:17 +0100 (Mon, 22 Jan 2007)
New Revision: 3138
Modified:
trunk/libmsip/include/libmsip/SipSocketServer.h
trunk/libmsip/source/SipLayerTransport.cxx
trunk/libmsip/source/SipSocketServer.cxx
Log:
* Fix: There was no way to "join" the thread in a SipSocketServer
object, and since they are not "detached" threads we wasted
memory address space.
On my computer w. Linux, and application like the following code
could only run a few hundred loops before a new thread could not
be created.
(Note that it runs out of address space for the new thread in
this application, and *not* memory which could affect other
applications running on the same computer as well)
while (true){
...
MRef<SipStack*> s = new SipStack( config );
...
s->stopRunning();
...
}
This fix makes "stopRunning" Thread::join all threads in
the SIP stack. This takes up to five seconds because
we don't interrupt the SipSocketServer thread, and instead
waits for it to timeout.
Modified: trunk/libmsip/include/libmsip/SipSocketServer.h
===================================================================
--- trunk/libmsip/include/libmsip/SipSocketServer.h 2007-01-21 11:30:38 UTC (rev 3137)
+++ trunk/libmsip/include/libmsip/SipSocketServer.h 2007-01-22 13:45:17 UTC (rev 3138)
@@ -62,6 +62,7 @@
void run();
void start();
void stop();
+ void join();
virtual void inputReady();
@@ -71,6 +72,7 @@
bool doStop;
std::string externalIp;
int32_t externalPort;
+ ThreadHandle th;
};
Modified: trunk/libmsip/source/SipLayerTransport.cxx
===================================================================
--- trunk/libmsip/source/SipLayerTransport.cxx 2007-01-21 11:30:38 UTC (rev 3137)
+++ trunk/libmsip/source/SipLayerTransport.cxx 2007-01-22 13:45:17 UTC (rev 3138)
@@ -393,12 +393,13 @@
w->stop();
}
+ //tell the threads to stop. Don't "join" just yet
+ //since that might take some time and we want that
+ //time to be spent in parallel for all servers.
list<MRef<SipSocketServer *> >::iterator i;
for( i=servers.begin(); i != servers.end(); i++ ){
MRef<SipSocketServer *> server = *i;
-
server->stop();
- *i=NULL;
}
//wake up blocking threads
@@ -413,6 +414,17 @@
*j=NULL;
}
+ //wait for the threads in the servers.
+ //NOTE: this can take about five seconds
+ //(that is the read timeout in the socket
+ //server). To improve this, check out
+ //SipSocketServer.cxx
+ for( i=servers.begin(); i != servers.end(); i++ ){
+ MRef<SipSocketServer *> server = *i;
+ server->join();
+ *i=NULL;
+ }
+
workers.clear();
servers.clear();
serversLock.unlock();
Modified: trunk/libmsip/source/SipSocketServer.cxx
===================================================================
--- trunk/libmsip/source/SipSocketServer.cxx 2007-01-21 11:30:38 UTC (rev 3137)
+++ trunk/libmsip/source/SipSocketServer.cxx 2007-01-22 13:45:17 UTC (rev 3138)
@@ -97,12 +97,17 @@
void SipSocketServer::start(){
Thread t(this);
+ th=t.getHandle();
}
void SipSocketServer::stop(){
doStop=true;
}
+void SipSocketServer::join(){
+ Thread::join(th);
+}
+
void SipSocketServer::inputReady(){
}
More information about the Minisip-devel
mailing list