> On Mon, 2 Jul 2001, Sander Striker wrote:
>
> > apr_sms_thread_register(sms, os_thread)
> > {
>
> [snip]
>
> >     pms = sms->parent;
> >     while (pms) {
> >        apr_sms_thread_register(os_thread);
> >        pms = pms->parent;
> >     }
>
> [snip]
>
> > }
>
> You don't need a while loop here... the recursion ought to take care of it
> for you.

Ah, indeed. Good it was only pseudo code :)
Actually it should be unrolled in the while loop.
Recursion only slows us down :)

So it would become something like this:

apr_sms_thread_register(sms, os_thread)
{
    do {
        if (!sms->lock) {
            sms->lock = apr_lock_create();
        }

        apr_lock_acquire(sms->lock);

        sms->thread_count++;

        /* let the sms know about the thread if it is
         * interested (so it can protect its private
         * data with its own lock)
         */
        if (sms->thread_register_fn)
            sms->thread_register_fn(os_thread);

        apr_lock_release(sms->lock);

        sms = sms->parent;
    } while (sms);
}

Sander

Reply via email to