[asterisk-commits] russell: trunk r40782 - /trunk/main/channel.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Aug 21 12:35:29 MST 2006


Author: russell
Date: Mon Aug 21 14:35:28 2006
New Revision: 40782

URL: http://svn.digium.com/view/asterisk?rev=40782&view=rev
Log:
- use the atomic operations for incrementing the unique int
- free the string fields allocation if ast_create_channel() failes to open the
  alert pipe
- formatting tweaks

Modified:
    trunk/main/channel.c

Modified: trunk/main/channel.c
URL: http://svn.digium.com/view/asterisk/trunk/main/channel.c?rev=40782&r1=40781&r2=40782&view=diff
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Mon Aug 21 14:35:28 2006
@@ -95,7 +95,6 @@
 /*! Prevent new channel allocation if shutting down. */
 static int shutting_down = 0;
 
-AST_MUTEX_DEFINE_STATIC(uniquelock);
 static int uniqueint = 0;
 
 unsigned long global_fin = 0, global_fout = 0;
@@ -626,7 +625,7 @@
 	/* Don't bother initializing the last two FD here, because they
 	   will *always* be set just a few lines down (AST_TIMING_FD,
 	   AST_ALERT_FD). */
-	for (x=0; x<AST_MAX_FDS - 2; x++)
+	for (x = 0; x < AST_MAX_FDS - 2; x++)
 		tmp->fds[x] = -1;
 
 #ifdef HAVE_ZAPTEL
@@ -645,6 +644,7 @@
 	if (needqueue) {
 		if (pipe(tmp->alertpipe)) {
 			ast_log(LOG_WARNING, "Channel allocation failed: Can't create alert pipe!\n");
+			ast_string_field_free_all(tmp);
 			free(tmp);
 			return NULL;
 		} else {
@@ -661,27 +661,35 @@
 	/* And timing pipe */
 	tmp->fds[AST_TIMING_FD] = tmp->timingfd;
 	ast_string_field_set(tmp, name, "**Unknown**");
+	
 	/* Initial state */
 	tmp->_state = AST_STATE_DOWN;
+	
 	tmp->streamid = -1;
-	tmp->appl = NULL;
-	tmp->data = NULL;
+	
 	tmp->fin = global_fin;
 	tmp->fout = global_fout;
-	ast_mutex_lock(&uniquelock);
-	if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME))
-		ast_string_field_build(tmp, uniqueid, "%li.%d", (long) time(NULL), uniqueint++);
-	else
-		ast_string_field_build(tmp, uniqueid, "%s-%li.%d", ast_config_AST_SYSTEM_NAME, (long) time(NULL), uniqueint++);
-	ast_mutex_unlock(&uniquelock);
+
+	if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)) {
+		ast_string_field_build(tmp, uniqueid, "%li.%d", (long) time(NULL), 
+			ast_atomic_fetchadd_int(&uniqueint, 1));
+	} else {
+		ast_string_field_build(tmp, uniqueid, "%s-%li.%d", ast_config_AST_SYSTEM_NAME, 
+			(long) time(NULL), ast_atomic_fetchadd_int(&uniqueint, 1));
+	}
+
 	headp = &tmp->varshead;
+	AST_LIST_HEAD_INIT_NOLOCK(headp);
+	
 	ast_mutex_init(&tmp->lock);
-	AST_LIST_HEAD_INIT_NOLOCK(headp);
+	
 	AST_LIST_HEAD_INIT_NOLOCK(&tmp->datastores);
+	
 	strcpy(tmp->context, "default");
-	ast_string_field_set(tmp, language, defaultlanguage);
 	strcpy(tmp->exten, "s");
 	tmp->priority = 1;
+	
+	ast_string_field_set(tmp, language, defaultlanguage);
 	tmp->amaflags = ast_default_amaflags;
 	ast_string_field_set(tmp, accountcode, ast_default_accountcode);
 
@@ -690,6 +698,7 @@
 	AST_LIST_LOCK(&channels);
 	AST_LIST_INSERT_HEAD(&channels, tmp, chan_list);
 	AST_LIST_UNLOCK(&channels);
+
 	return tmp;
 }
 



More information about the asterisk-commits mailing list