[asterisk-commits] file: branch group/sip-tcptls r99022 - /team/group/sip-tcptls/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 18 09:01:24 CST 2008


Author: file
Date: Fri Jan 18 09:01:24 2008
New Revision: 99022

URL: http://svn.digium.com/view/asterisk?view=rev&rev=99022
Log:
Make the thread list safe. It could have been possible for the list to be modified by multiple threads at the same time.

Modified:
    team/group/sip-tcptls/channels/chan_sip.c

Modified: team/group/sip-tcptls/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/sip-tcptls/channels/chan_sip.c?view=diff&rev=99022&r1=99021&r2=99022
==============================================================================
--- team/group/sip-tcptls/channels/chan_sip.c (original)
+++ team/group/sip-tcptls/channels/chan_sip.c Fri Jan 18 09:01:24 2008
@@ -2144,7 +2144,9 @@
 	else
 		me->type = SIP_TRANSPORT_TCP;
 
+	AST_LIST_LOCK(&threadl);
 	AST_LIST_INSERT_TAIL(&threadl, me, list);
+	AST_LIST_UNLOCK(&threadl);
 
 	req.socket.lock = ast_calloc(1, sizeof(*req.socket.lock));
 
@@ -2206,7 +2208,9 @@
 	}
 
 cleanup:
+	AST_LIST_LOCK(&threadl);
 	AST_LIST_REMOVE(&threadl, me, list);
+	AST_LIST_UNLOCK(&threadl);
 	ast_free(me);
 cleanup2:
 	fclose(ser->f);
@@ -11529,6 +11533,7 @@
 		return CLI_SHOWUSAGE;
 
 	ast_cli(a->fd, FORMAT2, "Host", "Port", "Transport", "Type");
+	AST_LIST_LOCK(&threadl);
 	AST_LIST_TRAVERSE(&threadl, th, list) {
 		ast_cli(a->fd, FORMAT, ast_inet_ntoa(th->ser->requestor.sin_addr), 
 			ntohs(th->ser->requestor.sin_port), 
@@ -11536,6 +11541,7 @@
 			(th->ser->client ? "Client" : "Server"));
 
 	}
+	AST_LIST_UNLOCK(&threadl);
 	return CLI_SUCCESS;
 #undef FORMAT
 #undef FORMAT2
@@ -17853,12 +17859,14 @@
 {
 	struct sip_threadinfo *th;
 
+	AST_LIST_LOCK(&threadl);
 	AST_LIST_TRAVERSE(&threadl, th, list) {
 		if ((s->sin_family == th->ser->requestor.sin_family) &&
 			(s->sin_addr.s_addr == th->ser->requestor.sin_addr.s_addr) &&
 			(s->sin_port == th->ser->requestor.sin_port)) 
 				return th->ser;
 	}
+	AST_LIST_UNLOCK(&threadl);
 	return NULL;
 }
 
@@ -21137,12 +21145,17 @@
 		server_stop(&sip_tls_desc);
 
 	/* Kill all existing TCP/TLS threads */
-	while(!AST_LIST_EMPTY(&threadl)) {
-		AST_LIST_TRAVERSE(&threadl, th, list) {
-			th->stop = 1;
-			pthread_kill(th->threadid, SIGURG);
-		}
-	}
+	AST_LIST_LOCK(&threadl);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&threadl, th, list) {
+		pthread_t thread = th->threadid;
+		th->stop = 1;
+		AST_LIST_UNLOCK(&threadl);
+		pthread_kill(thread, SIGURG);
+		pthread_join(thread, NULL);
+		AST_LIST_LOCK(&threadl);
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
+	AST_LIST_UNLOCK(&threadl);
 
 	dialoglist_lock();
 	/* Hangup all dialogs if they have an owner */




More information about the asterisk-commits mailing list