[Asterisk-Dev] question about looping of code.

Martin Pycko martinp at digium.com
Mon Nov 10 09:13:21 MST 2003


That might be something ... however most function call this funtion
wihthout nfds (file descriptors) .... So that propably won't be visible in
the preformance.

Did you try running asterisk like that ?

regards
Martin

On Sun, 9 Nov 2003, Steven Critchfield wrote:

> I know, clumsy subject line.
>
> While tracking down a problem the other day, I noticed something that
> seems unnecessary. (BTW, the problem was in a private patch of mine.)
>
> In channel.c *ast_waitfor_nandfds near the end, there ire 2 loops. It
> seems that if the first loop is successful and assigns something to
> winner, then nothing would happen in the second loop do to the if
> statement. For that matter, it would seem that we continue looping
> through the first loop even if we won't do anything after winner is
> found. Would it be okay to move the time calculation to before the first
> loop and just return instead of bothering to assign to winner? If you do
> this, you can remove the winner completely from the function and just
> place a return anywhere the assignment is and a null at the end of the
> function.
>
> I'll copy the code section below for easy viewing.
>
>         for (x=0;x<n;x++) {
>                 c[x]->blocking = 0;
>                 for (y=0;y<AST_MAX_FDS;y++) {
>                         if (c[x]->fds[y] > -1) {
>                                 if ((FD_ISSET(c[x]->fds[y], &rfds) || FD_ISSET(c[x]->fds[y], &efds)) && !winner) {
>                                         /* Set exception flag if appropriate */
>                                         if (FD_ISSET(c[x]->fds[y], &efds))
>                                                 c[x]->exception = 1;
>                                         c[x]->fdno = y;
>                                         winner = c[x];
>                                 }
>                         }
>                 }
>         }
>         for (x=0;x<nfds;x++) {
>                 if ((FD_ISSET(fds[x], &rfds) || FD_ISSET(fds[x], &efds)) && !winner) {
>                         if (outfd)
>                                 *outfd = fds[x];
>                         if (FD_ISSET(fds[x], &efds) && exception)
>                                 *exception = 1;
>                         winner = NULL;
>                 }
>         }
>         *ms = tv.tv_sec * 1000 + tv.tv_usec / 1000;
>         return winner;
> }
>
> --
> Steven Critchfield <critch at basesys.com>
>
> _______________________________________________
> Asterisk-Dev mailing list
> Asterisk-Dev at lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-dev
>




More information about the asterisk-dev mailing list