[asterisk-commits] russell: branch 1.4 r115990 - /branches/1.4/main/autoservice.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue May 13 16:05:58 CDT 2008


Author: russell
Date: Tue May 13 16:05:57 2008
New Revision: 115990

URL: http://svn.digium.com/view/asterisk?view=rev&rev=115990
Log:
Fix an issue that I noticed in autoservice while mmichelson and I were debugging
a different problem.  I noticed that it was theoretically possible for two threads
to attempt to start the autoservice thread at the same time.  This change makes the
process of starting the autoservice thread, thread-safe.

Modified:
    branches/1.4/main/autoservice.c

Modified: branches/1.4/main/autoservice.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/autoservice.c?view=diff&rev=115990&r1=115989&r2=115990
==============================================================================
--- branches/1.4/main/autoservice.c (original)
+++ branches/1.4/main/autoservice.c Tue May 13 16:05:57 2008
@@ -201,24 +201,28 @@
 	ast_channel_unlock(chan);
 
 	AST_LIST_LOCK(&aslist);
-	if (AST_LIST_EMPTY(&aslist))
+
+	if (AST_LIST_EMPTY(&aslist) && asthread != AST_PTHREADT_NULL) {
 		ast_cond_signal(&as_cond);
+	}
+
 	AST_LIST_INSERT_HEAD(&aslist, as, list);
-	AST_LIST_UNLOCK(&aslist);
 
 	if (asthread == AST_PTHREADT_NULL) { /* need start the thread */
 		if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) {
 			ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
 			/* There will only be a single member in the list at this point,
 			   the one we just added. */
-			AST_LIST_LOCK(&aslist);
 			AST_LIST_REMOVE(&aslist, as, list);
-			AST_LIST_UNLOCK(&aslist);
 			free(as);
+			asthread = AST_PTHREADT_NULL;
 			res = -1;
-		} else
+		} else {
 			pthread_kill(asthread, SIGURG);
-	}
+		}
+	}
+
+	AST_LIST_UNLOCK(&aslist);
 
 	return res;
 }




More information about the asterisk-commits mailing list