[svn-commits] russell: branch russell/issue_13566 r166056 - /team/russell/issue_13566/res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Dec 19 15:15:31 CST 2008


Author: russell
Date: Fri Dec 19 15:15:30 2008
New Revision: 166056

URL: http://svn.digium.com/view/asterisk?view=rev&rev=166056
Log:
Improve readability of refcount adjustments.

Modified:
    team/russell/issue_13566/res/res_musiconhold.c

Modified: team/russell/issue_13566/res/res_musiconhold.c
URL: http://svn.digium.com/view/asterisk/team/russell/issue_13566/res/res_musiconhold.c?view=diff&rev=166056&r1=166055&r2=166056
==============================================================================
--- team/russell/issue_13566/res/res_musiconhold.c (original)
+++ team/russell/issue_13566/res/res_musiconhold.c Fri Dec 19 15:15:30 2008
@@ -170,6 +170,9 @@
 
 static int reload(void);
 
+#define mohclass_ref(class)   (ao2_ref((class), +1), class)
+#define mohclass_unref(class) (ao2_ref((class), -1), NULL)
+
 static void moh_files_release(struct ast_channel *chan, void *data)
 {
 	struct moh_files_state *state;
@@ -195,7 +198,7 @@
 
 	state->save_pos = state->pos;
 
-	state->class = (ao2_ref(state->class, -1), NULL);
+	state->class = mohclass_unref(state->class);
 }
 
 
@@ -300,7 +303,7 @@
 
 	if (!chan->music_state && (state = ast_calloc(1, sizeof(*state)))) {
 		chan->music_state = state;
-		state->class = (ao2_ref(class, +1), class);
+		state->class = mohclass_ref(class);
 		state->save_pos = -1;
 	} else {
 		state = chan->music_state;
@@ -313,10 +316,10 @@
 	if (state->class != class) {
 		/* (re-)initialize */
 		if (state->class) {
-			state->class = (ao2_ref(state->class, -1), NULL);
+			state->class = mohclass_unref(state->class);
 		}
 		memset(state, 0, sizeof(*state));
-		state->class = (ao2_ref(class, +1), class);
+		state->class = mohclass_ref(class);
 		if (ast_test_flag(state->class, MOH_RANDOMIZE) && class->total_files) {
 			state->pos = ast_random() % class->total_files;
 		}
@@ -676,7 +679,7 @@
 	moh->f.subclass = cl->format;
 	moh->f.offset = AST_FRIENDLY_OFFSET;
 
-	moh->parent = (ao2_ref(cl, +1), cl);
+	moh->parent = mohclass_ref(cl);
 
 	ao2_lock(cl);
 	AST_LIST_INSERT_HEAD(&cl->members, moh, list);
@@ -700,7 +703,7 @@
 
 	oldwfmt = moh->origwfmt;
 
-	moh->parent = class = (ao2_ref(class, -1), NULL);
+	moh->parent = class = mohclass_unref(class);
 
 	free(moh);
 
@@ -947,11 +950,11 @@
 	if ((mohclass = get_mohbyname(moh->name, 0))) {
 		if (!mohclass->delete) {
  			ast_log(LOG_WARNING, "Music on Hold class '%s' already exists\n", moh->name);
-			mohclass = (ao2_ref(mohclass, -1), NULL);
-			moh = (ao2_ref(moh, -1), NULL);
+			mohclass = mohclass_unref(mohclass);
+			moh = mohclass_unref(moh);
 			return -1;
  		}
-		mohclass = (ao2_ref(mohclass, -1), NULL);
+		mohclass = mohclass_unref(mohclass);
 	}
 
 	time(&moh->start);
@@ -959,25 +962,25 @@
 	
 	if (!strcasecmp(moh->mode, "files")) {
 		if (init_files_class(moh)) {
-			moh = (ao2_ref(moh, -1), NULL);
+			moh = mohclass_unref(moh);
 			return -1;
 		}
 	} else if (!strcasecmp(moh->mode, "mp3") || !strcasecmp(moh->mode, "mp3nb") || 
 			!strcasecmp(moh->mode, "quietmp3") || !strcasecmp(moh->mode, "quietmp3nb") ||
 			!strcasecmp(moh->mode, "httpmp3") || !strcasecmp(moh->mode, "custom")) {
 		if (init_app_class(moh)) {
-			moh = (ao2_ref(moh, -1), NULL);
+			moh = mohclass_unref(moh);
 			return -1;
 		}
 	} else {
 		ast_log(LOG_WARNING, "Don't know how to do a mode '%s' music on hold\n", moh->mode);
-		moh = (ao2_ref(moh, -1), NULL);
+		moh = mohclass_unref(moh);
 		return -1;
 	}
 
 	ao2_link(mohclasses, moh);
 
-	moh = (ao2_ref(moh, -1), NULL);
+	moh = mohclass_unref(moh);
 	
 	return 0;
 }
@@ -1031,7 +1034,7 @@
 		res = ast_activate_generator(chan, &mohgen, mohclass);
 	}
 
-	mohclass = (ao2_ref(mohclass, -1), NULL);
+	mohclass = mohclass_unref(mohclass);
 
 	return res;
 }
@@ -1189,20 +1192,20 @@
 				ast_copy_string(class->dir, "nodir", sizeof(class->dir));
 			} else {
 				ast_log(LOG_WARNING, "A directory must be specified for class '%s'!\n", class->name);
-				class = (ao2_ref(class, -1), NULL);
+				class = mohclass_unref(class);
 				continue;
 			}
 		}
 
 		if (ast_strlen_zero(class->mode)) {
 			ast_log(LOG_WARNING, "A mode must be specified for class '%s'!\n", class->name);
-			class = (ao2_ref(class, -1), NULL);
+			class = mohclass_unref(class);
 			continue;
 		}
 
 		if (ast_strlen_zero(class->args) && !strcasecmp(class->mode, "custom")) {
 			ast_log(LOG_WARNING, "An application must be specified for class '%s'!\n", class->name);
-			class = (ao2_ref(class, -1), NULL);
+			class = mohclass_unref(class);
 			continue;
 		}
 
@@ -1232,7 +1235,7 @@
 		}
 
 		if ((tmp_class = get_mohbyname(var->name, 0))) {
-			tmp_class = (ao2_ref(tmp_class, -1), NULL);
+			tmp_class = mohclass_unref(tmp_class);
 			continue;
 		}
 
@@ -1262,7 +1265,7 @@
 		}
 
 		if ((tmp_class = get_mohbyname(var->name, 0))) {
-			tmp_class = (ao2_ref(tmp_class, -1), NULL);
+			tmp_class = mohclass_unref(tmp_class);
 			continue;
 		}
 
@@ -1317,7 +1320,7 @@
 
 	i = ao2_iterator_init(mohclasses, 0);
 
-	for (; (class = ao2_iterator_next(&i)); ao2_ref(class, -1)) {
+	for (; (class = ao2_iterator_next(&i)); mohclass_unref(class)) {
 		int x;
 
 		if (!class->total_files) {
@@ -1341,7 +1344,7 @@
 
 	i = ao2_iterator_init(mohclasses, 0);
 
-	for (; (class = ao2_iterator_next(&i)); ao2_ref(class, -1)) {
+	for (; (class = ao2_iterator_next(&i)); mohclass_unref(class)) {
 		ast_cli(fd, "Class: %s\n", class->name);
 		ast_cli(fd, "\tMode: %s\n", S_OR(class->mode, "<none>"));
 		ast_cli(fd, "\tDirectory: %s\n", S_OR(class->dir, "<none>"));
@@ -1450,7 +1453,7 @@
 	/* XXX This check shouldn't be required if module ref counting was being used
 	 * properly ... */
 	if ((class = ao2_callback(mohclasses, 0, moh_class_inuse, NULL))) {
-		class = (ao2_ref(class, -1), NULL);
+		class = mohclass_unref(class);
 		res = -1;
 	}
 




More information about the svn-commits mailing list