[asterisk-commits] tilghman: branch 1.6.1 r154917 - in /branches/1.6.1: ./ channels/chan_iax2.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Nov 5 16:00:57 CST 2008
Author: tilghman
Date: Wed Nov 5 16:00:56 2008
New Revision: 154917
URL: http://svn.digium.com/view/asterisk?view=rev&rev=154917
Log:
Merged revisions 154428 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)
........
Modified:
branches/1.6.1/ (props changed)
branches/1.6.1/channels/chan_iax2.c
Propchange: branches/1.6.1/
------------------------------------------------------------------------------
Binary property 'trunk-merged' - no diff available.
Modified: branches/1.6.1/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.1/channels/chan_iax2.c?view=diff&rev=154917&r1=154916&r2=154917
==============================================================================
--- branches/1.6.1/channels/chan_iax2.c (original)
+++ branches/1.6.1/channels/chan_iax2.c Wed Nov 5 16:00:56 2008
@@ -778,7 +778,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
@@ -1119,6 +1120,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)) {
@@ -1133,8 +1137,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;
}
@@ -9737,6 +9743,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);
}
@@ -9747,6 +9755,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);
@@ -9755,8 +9764,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);
More information about the asterisk-commits
mailing list