[asterisk-commits] rmudgett: branch group/issue8824 r154464 - in /team/group/issue8824: ./ chann...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Nov 4 18:08:02 CST 2008


Author: rmudgett
Date: Tue Nov  4 18:08:01 2008
New Revision: 154464

URL: http://svn.digium.com/view/asterisk?view=rev&rev=154464
Log:
Resolved merge conflict and restarted automerge.

Merged revisions 154428-154429 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

........
  r154428 | tilghman | 2008-11-04 17:03:00 -0600 (Tue, 04 Nov 2008) | 7 lines
  
  Switch to using a thread condition to signal that a child thread is ready for
  work, rather than a busy wait.
  (closes issue #13011)
   Reported by: jpgrayson
   Patches: 
         chan_iax2_find_idle.patch uploaded by jpgrayson (license 492)
........
  r154429 | seanbright | 2008-11-04 17:23:39 -0600 (Tue, 04 Nov 2008) | 8 lines
  
  Introduce a new API call ast_channel_search_locked, which iterates through the
  channel list calling a caller-defined callback.  The callback returns non-zero
  if a match is found.  This should speed up some of the code that I committed
  earlier today in chan_sip (which is also updated by this commit).
  
  Reviewed by russellb and kpfleming via ReviewBoard:
  	http://reviewboard.digium.com/r/28/
........

Modified:
    team/group/issue8824/   (props changed)
    team/group/issue8824/channels/chan_iax2.c
    team/group/issue8824/channels/chan_sip.c
    team/group/issue8824/include/asterisk/channel.h
    team/group/issue8824/main/channel.c

Propchange: team/group/issue8824/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/group/issue8824/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Nov  4 18:08:01 2008
@@ -1,1 +1,1 @@
-/trunk:1-154379
+/trunk:1-154463

Modified: team/group/issue8824/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/group/issue8824/channels/chan_iax2.c?view=diff&rev=154464&r1=154463&r2=154464
==============================================================================
--- team/group/issue8824/channels/chan_iax2.c (original)
+++ team/group/issue8824/channels/chan_iax2.c Tue Nov  4 18:08:01 2008
@@ -862,7 +862,8 @@
 	time_t checktime;
 	ast_mutex_t lock;
 	ast_cond_t cond;
-	unsigned int ready_for_signal:1;
+	ast_mutex_t init_lock;
+	ast_cond_t init_cond;
 	/*! if this thread is processing a full frame,
 	  some information about that frame will be stored
 	  here, so we can avoid dispatching any more full
@@ -1203,6 +1204,9 @@
 	/* Initialize lock and condition */
 	ast_mutex_init(&thread->lock);
 	ast_cond_init(&thread->cond, NULL);
+	ast_mutex_init(&thread->init_lock);
+	ast_cond_init(&thread->init_cond, NULL);
+	ast_mutex_lock(&thread->init_lock);
 
 	/* Create thread and send it on it's way */
 	if (ast_pthread_create_detached_background(&thread->threadid, NULL, iax2_process_thread, thread)) {
@@ -1217,8 +1221,10 @@
 	memset(&thread->ffinfo, 0, sizeof(thread->ffinfo));
 
 	/* Wait for the thread to be ready before returning it to the caller */
-	while (!thread->ready_for_signal)
-		usleep(1);
+	ast_cond_wait(&thread->init_cond, &thread->init_lock);
+
+	/* Done with init_lock */
+	ast_mutex_unlock(&thread->init_lock);
 
 	return thread;
 }
@@ -9911,6 +9917,8 @@
 	struct iax2_thread *thread = data;
 	ast_mutex_destroy(&thread->lock);
 	ast_cond_destroy(&thread->cond);
+	ast_mutex_destroy(&thread->init_lock);
+	ast_cond_destroy(&thread->init_cond);
 	ast_free(thread);
 	ast_atomic_dec_and_test(&iaxactivethreadcount);
 }
@@ -9921,6 +9929,7 @@
 	struct timeval wait;
 	struct timespec ts;
 	int put_into_idle = 0;
+	int first_time = 1;
 
 	ast_atomic_fetchadd_int(&iaxactivethreadcount,1);
 	pthread_cleanup_push(iax2_process_thread_cleanup, data);
@@ -9929,8 +9938,11 @@
 		ast_mutex_lock(&thread->lock);
 
 		/* Flag that we're ready to accept signals */
-		thread->ready_for_signal = 1;
-		
+		if (first_time) {
+			signal_condition(&thread->init_lock, &thread->init_cond);
+			first_time = 0;
+		}
+
 		/* Put into idle list if applicable */
 		if (put_into_idle)
 			insert_idle_thread(thread);

Modified: team/group/issue8824/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/issue8824/channels/chan_sip.c?view=diff&rev=154464&r1=154463&r2=154464
==============================================================================
--- team/group/issue8824/channels/chan_sip.c (original)
+++ team/group/issue8824/channels/chan_sip.c Tue Nov  4 18:08:01 2008
@@ -10124,19 +10124,21 @@
 			   callee must be dialing the same extension that is being monitored.  Simply dialing
 			   the hint'd device is not sufficient. */
 			if (global_notifycid) {
-				struct ast_channel *caller = NULL;
-
-				while ((caller = ast_channel_walk_locked(caller))) {
-					if (caller->pbx &&
-						(!strcasecmp(caller->macroexten, p->exten) || !strcasecmp(caller->exten, p->exten)) &&
-						!strcasecmp(caller->context, p->context)) {
-						local_display = ast_strdupa(caller->cid.cid_name);
-						local_target = ast_strdupa(caller->cid.cid_num);
-						ast_channel_unlock(caller);
-						break;
-					}
+				auto int find_calling_channel(struct ast_channel *c);
+				int find_calling_channel(struct ast_channel *c) {
+					return (c->pbx &&
+							(!strcasecmp(c->macroexten, p->exten) || !strcasecmp(c->exten, p->exten)) &&
+							!strcasecmp(c->context, p->context));
+				}
+
+				struct ast_channel *caller = ast_channel_search_locked(find_calling_channel);
+
+				if (caller) {
+					local_display = ast_strdupa(caller->cid.cid_name);
+					local_target = ast_strdupa(caller->cid.cid_num);
 					ast_channel_unlock(caller);
-				}				
+					caller = NULL;
+				}
 			}
 
 			/* We create a fake call-id which the phone will send back in an INVITE

Modified: team/group/issue8824/include/asterisk/channel.h
URL: http://svn.digium.com/view/asterisk/team/group/issue8824/include/asterisk/channel.h?view=diff&rev=154464&r1=154463&r2=154464
==============================================================================
--- team/group/issue8824/include/asterisk/channel.h (original)
+++ team/group/issue8824/include/asterisk/channel.h Tue Nov  4 18:08:01 2008
@@ -1334,6 +1334,17 @@
 struct ast_channel *ast_walk_channel_by_exten_locked(const struct ast_channel *chan, const char *exten,
 						     const char *context);
 
+/*! \brief Search for a channel based on the passed channel matching callback
+ * Search for a channel based on the specified is_match callback, and return the
+ * first channel that we match.  When returned, the channel will be locked.  Note
+ * that the is_match callback is called with the passed channel locked, and should
+ * return 0 if there is no match, and non-zero if there is.
+ * \param is_match callback executed on each channel until non-zero is returned, or we
+ *        run out of channels to search.
+ * \return Returns the matched channel, or NULL if no channel was matched.
+ */
+struct ast_channel *ast_channel_search_locked(int (*is_match)(struct ast_channel *));
+
 /*! \brief Waits for a digit
  * \param c channel to wait for a digit on
  * \param ms how many milliseconds to wait

Modified: team/group/issue8824/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/group/issue8824/main/channel.c?view=diff&rev=154464&r1=154463&r2=154464
==============================================================================
--- team/group/issue8824/main/channel.c (original)
+++ team/group/issue8824/main/channel.c Tue Nov  4 18:08:01 2008
@@ -1224,6 +1224,24 @@
 						     const char *context)
 {
 	return channel_find_locked(chan, NULL, 0, context, exten);
+}
+
+/*! \brief Search for a channel based on the passed channel matching callback (first match) and return it, locked */
+struct ast_channel *ast_channel_search_locked(int (*is_match)(struct ast_channel *))
+{
+	struct ast_channel *c = NULL;
+
+	AST_RWLIST_RDLOCK(&channels);
+	AST_RWLIST_TRAVERSE(&channels, c, chan_list) {
+		ast_channel_lock(c);
+		if (is_match(c)) {
+			break;
+		}
+		ast_channel_unlock(c);
+	}
+	AST_RWLIST_UNLOCK(&channels);
+
+	return c;
 }
 
 /*! \brief Wait, look for hangups and condition arg */




More information about the asterisk-commits mailing list