[asterisk-commits] russell: branch 1.4 r105563 - in /branches/1.4: include/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Mar 3 09:50:44 CST 2008
Author: russell
Date: Mon Mar 3 09:50:43 2008
New Revision: 105563
URL: http://svn.digium.com/view/asterisk?view=rev&rev=105563
Log:
Merge in some changes from team/russell/autoservice-nochans-1.4
These changes fix up some dubious code that I came across while auditing what
happens in the autoservice thread when there are no channels currently in
autoservice.
1) Change it so that autoservice thread doesn't keep looping around calling
ast_waitfor_n() on 0 channels twice a second. Instead, use a thread condition
so that the thread properly goes to sleep and does not wake up until a
channel is put into autoservice.
This actually fixes an interesting bug, as well. If the autoservice thread
is already running (almost always is the case), then when the thread goes
from having 0 channels to have 1 channel to autoservice, that channel would
have to wait for up to 1/2 of a second to have the first frame read from it.
2) Fix up the code in ast_waitfor_nandfds() for when it gets called with no
channels and no fds to poll() on, such as was the case with the previous code
for the autoservice thread. In this case, the code would call alloca(0), and
pass the result as the first argument to poll(). In this case, the 2nd
argument to poll() specified that there were no fds, so this invalid pointer
shouldn't actually get dereferenced, but, this code makes it explicit and
ensures the pointers are NULL unless we have valid data to put there.
Modified:
branches/1.4/include/asterisk.h
branches/1.4/main/asterisk.c
branches/1.4/main/autoservice.c
branches/1.4/main/channel.c
Modified: branches/1.4/include/asterisk.h
URL: http://svn.digium.com/view/asterisk/branches/1.4/include/asterisk.h?view=diff&rev=105563&r1=105562&r2=105563
==============================================================================
--- branches/1.4/include/asterisk.h (original)
+++ branches/1.4/include/asterisk.h Mon Mar 3 09:50:43 2008
@@ -75,6 +75,7 @@
int dnsmgr_reload(void); /*!< Provided by dnsmgr.c */
void threadstorage_init(void); /*!< Provided by threadstorage.c */
int astobj2_init(void); /*! Provided by astobj2.c */
+void ast_autoservice_init(void); /*!< Provided by autoservice.c */
/* Many headers need 'ast_channel' to be defined */
struct ast_channel;
Modified: branches/1.4/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/asterisk.c?view=diff&rev=105563&r1=105562&r2=105563
==============================================================================
--- branches/1.4/main/asterisk.c (original)
+++ branches/1.4/main/asterisk.c Mon Mar 3 09:50:43 2008
@@ -2896,6 +2896,8 @@
astobj2_init();
+ ast_autoservice_init();
+
if (load_modules(1)) {
printf(term_quit());
exit(1);
Modified: branches/1.4/main/autoservice.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/autoservice.c?view=diff&rev=105563&r1=105562&r2=105563
==============================================================================
--- branches/1.4/main/autoservice.c (original)
+++ branches/1.4/main/autoservice.c Mon Mar 3 09:50:43 2008
@@ -64,6 +64,7 @@
};
static AST_LIST_HEAD_STATIC(aslist, asent);
+static ast_cond_t as_cond;
static pthread_t asthread = AST_PTHREADT_NULL;
@@ -97,6 +98,9 @@
/* At this point, we know that no channels that have been removed are going
* to get used again. */
as_chan_list_state++;
+
+ if (AST_LIST_EMPTY(&aslist))
+ ast_cond_wait(&as_cond, &aslist.lock);
AST_LIST_TRAVERSE(&aslist, as, list) {
if (!as->chan->_softhangup) {
@@ -106,6 +110,7 @@
ast_log(LOG_WARNING, "Exceeded maximum number of automatic monitoring events. Fix autoservice.c\n");
}
}
+
AST_LIST_UNLOCK(&aslist);
chan = ast_waitfor_n(mons, x, &ms);
@@ -194,6 +199,8 @@
ast_channel_unlock(chan);
AST_LIST_LOCK(&aslist);
+ if (AST_LIST_EMPTY(&aslist))
+ ast_cond_signal(&as_cond);
AST_LIST_INSERT_HEAD(&aslist, as, list);
AST_LIST_UNLOCK(&aslist);
@@ -276,3 +283,8 @@
return res;
}
+
+void ast_autoservice_init(void)
+{
+ ast_cond_init(&as_cond, NULL);
+}
Modified: branches/1.4/main/channel.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/channel.c?view=diff&rev=105563&r1=105562&r2=105563
==============================================================================
--- branches/1.4/main/channel.c (original)
+++ branches/1.4/main/channel.c Mon Mar 3 09:50:43 2008
@@ -1616,7 +1616,7 @@
int *exception, int *outfd, int *ms)
{
struct timeval start = { 0 , 0 };
- struct pollfd *pfds;
+ struct pollfd *pfds = NULL;
int res;
long rms;
int x, y, max;
@@ -1627,11 +1627,12 @@
struct fdmap {
int chan;
int fdno;
- } *fdmap;
-
- sz = n * AST_MAX_FDS + nfds;
- pfds = alloca(sizeof(*pfds) * sz);
- fdmap = alloca(sizeof(*fdmap) * sz);
+ } *fdmap = NULL;
+
+ if ((sz = n * AST_MAX_FDS + nfds)) {
+ pfds = alloca(sizeof(*pfds) * sz);
+ fdmap = alloca(sizeof(*fdmap) * sz);
+ }
if (outfd)
*outfd = -99999;
More information about the asterisk-commits
mailing list