[asterisk-commits] jpeeler: branch jpeeler/bug13173 r155501 - /team/jpeeler/bug13173/apps/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Nov 7 18:03:23 CST 2008


Author: jpeeler
Date: Fri Nov  7 18:03:23 2008
New Revision: 155501

URL: http://svn.digium.com/view/asterisk?view=rev&rev=155501
Log:
Make use of ao2 references to determine if an announcement has been played. Make the announce_thread responsible for freeing all the announcement data instead of cleaning up elsewhere.

Modified:
    team/jpeeler/bug13173/apps/app_meetme.c

Modified: team/jpeeler/bug13173/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/bug13173/apps/app_meetme.c?view=diff&rev=155501&r1=155500&r2=155501
==============================================================================
--- team/jpeeler/bug13173/apps/app_meetme.c (original)
+++ team/jpeeler/bug13173/apps/app_meetme.c Fri Nov  7 18:03:23 2008
@@ -64,6 +64,7 @@
 #include "asterisk/translate.h"
 #include "asterisk/ulaw.h"
 #include "asterisk/astobj.h"
+#include "asterisk/astobj2.h"
 #include "asterisk/devicestate.h"
 #include "asterisk/dial.h"
 #include "asterisk/causes.h"
@@ -1256,7 +1257,6 @@
 static int conf_free(struct ast_conference *conf)
 {
 	int x;
-	struct announce_listitem *item;
 	
 	AST_LIST_REMOVE(&confs, conf, list);
 
@@ -1285,11 +1285,6 @@
 		ast_cond_signal(&conf->announcelist_addition);
 		ast_mutex_unlock(&conf->announcelistlock);
 		pthread_join(conf->announcethread, NULL);
-		while ((item = AST_LIST_REMOVE_HEAD(&conf->announcelist, entry))) {
-				ast_log(LOG_DEBUG, "jpeeler: deleting %s\n", item->namerecloc);
-			ast_filedelete(item->namerecloc, NULL);
-			ast_free(item);
-		}
 		ast_mutex_destroy(&conf->announcelistlock);
 	}
 	if (conf->origframe)
@@ -1425,6 +1420,7 @@
 }
 
 /* jpeeler: I think using this function warrants use of astobj2 */
+/*
 static int announcement_played(struct ast_conference *conf, struct ast_channel *chan)
 {
 	struct announce_listitem *item;
@@ -1451,6 +1447,7 @@
 	ast_mutex_unlock(&conf->announcelistlock);
 	return ret;
 }
+*/
 
 static void *announce_thread(void *data)
 {
@@ -1463,14 +1460,14 @@
 		ast_mutex_lock(&conf->announcelistlock);
 		if (conf->announcethread_stop) {
 			ast_mutex_unlock(&conf->announcelistlock);
-			return NULL;
+			goto finish;
 		}
 		if (AST_LIST_EMPTY(&conf->announcelist))
 			ast_cond_wait(&conf->announcelist_addition, &conf->announcelistlock);
 		next = AST_LIST_FIRST(&conf->announcelist);
 		ast_mutex_unlock(&conf->announcelistlock);
 		if (conf->announcethread_stop) {
-			return NULL;
+			goto finish;
 		}
 
 		while ((current = next) && !conf->announcethread_stop) {
@@ -1486,7 +1483,7 @@
 					}
 				}
 				if (current->announcetype == CONF_HASLEFT) {
-					ast_log(LOG_DEBUG, "jpeeler: deleting %s\n", current->namerecloc);
+					ast_log(LOG_DEBUG, "jpeeler: deleting %s %d\n", current->namerecloc, ao2_ref(current, 0));
 					ast_filedelete(current->namerecloc, NULL);
 				} else {
 					ast_log(LOG_DEBUG, "jpeeler type= %d\n", current->announcetype);
@@ -1495,11 +1492,19 @@
 			next = AST_LIST_NEXT(current, entry);
 			ast_mutex_lock(&conf->announcelistlock);
 			AST_LIST_REMOVE_HEAD(&conf->announcelist, entry);
-			ast_free(current);
+			ao2_ref(current, -1);
+			//ast_free(current);
 			ast_mutex_unlock(&conf->announcelistlock);
 		}
 	}
 
+finish:
+	while ((current = AST_LIST_REMOVE_HEAD(&conf->announcelist, entry))) {
+		ast_log(LOG_DEBUG, "jpeeler: deleting %s\n", current->namerecloc);
+		ast_filedelete(current->namerecloc, NULL);
+		ao2_ref(current, -1);
+		//ast_free(current);
+	}
 	return NULL;
 }
 
@@ -1814,7 +1819,7 @@
 
 	if (!(confflags & CONFFLAG_QUIET) && ((confflags & CONFFLAG_INTROUSER) || (confflags & CONFFLAG_INTROUSERNOREVIEW)) && conf->users > 1) {
 		struct announce_listitem *item;
-		if (!(item = ast_calloc(1, sizeof(*item))))
+		if (!(item = ao2_alloc(sizeof(*item), NULL)))
 			return -1;
 		ast_copy_string(item->namerecloc, user->namerecloc, sizeof(item->namerecloc));
 		ast_copy_string(item->language, chan->language, sizeof(item->language));
@@ -1823,9 +1828,15 @@
 		item->confusers = conf->users;
 		item->announcetype = CONF_HASJOIN;
 		ast_mutex_lock(&conf->announcelistlock);
+		ao2_ref(item, +1); /* add one more so we can determine when announce_thread is done playing it */
 		AST_LIST_INSERT_TAIL(&conf->announcelist, item, entry);
 		ast_cond_signal(&conf->announcelist_addition);
 		ast_mutex_unlock(&conf->announcelistlock);
+
+		while (!ast_check_hangup(conf->chan) && ao2_ref(item, 0) == 2 && !ast_safe_sleep(chan, 1000)) {
+			ast_log(LOG_NOTICE, "jpeeler: waiting for announcement to finish for %s...\n", chan->name);
+		}
+		ao2_ref(item, -1);
 	}
 
 	if (confflags & CONFFLAG_WAITMARKED && !conf->markedusers)
@@ -1836,11 +1847,7 @@
 		ztc.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER;
 	else 
 		ztc.confmode = DAHDI_CONF_CONF | DAHDI_CONF_TALKER | DAHDI_CONF_LISTENER;
-
-	while (!ast_check_hangup(chan) && !ast_check_hangup(conf->chan) && announcement_played(conf, chan)) {
-		ast_log(LOG_NOTICE, "jpeeler: waiting for announcement to finish for %s...\n", chan->name);
-		ast_safe_sleep(chan, 1000);
-	}
+	
 	if (ioctl(fd, DAHDI_SETCONF, &ztc)) {
 		ast_log(LOG_WARNING, "Error setting conference\n");
 		close(fd);
@@ -2420,7 +2427,7 @@
 
 	if (!(confflags & CONFFLAG_QUIET) && ((confflags & CONFFLAG_INTROUSER) || (confflags & CONFFLAG_INTROUSERNOREVIEW)) && conf->users > 1) {
 		struct announce_listitem *item;
-		if (!(item = ast_calloc(1, sizeof(*item))))
+		if (!(item = ao2_alloc(sizeof(*item), NULL)))
 			return -1;
 		ast_copy_string(item->namerecloc, user->namerecloc, sizeof(item->namerecloc));
 		ast_copy_string(item->language, chan->language, sizeof(item->language));




More information about the asterisk-commits mailing list