RE: Puzzled at callback routine Squid is using.

From: Robert Collins <robert.collins@dont-contact.us>
Date: Fri, 19 Apr 2002 22:40:30 +1000

A normal function call:

client_code ()
{
   .. prolog
   result = foo();
   .. epilog
}

foo() executes immediately, all side effects have happened when foo
returns.
if foo blocks, the entire program blocks (unless threads are used).

a callback function call:

client_code_prolog()
{
  .. prolog
  foo(&client_code_epilog, state_variable);
}

client_code_epilog( state_variable_type *, result_type result)
{
   ... epilog
}

foo() executes before calling client_code_epilog, and all sideeffects
have occurred before client_code_epilog is called. However if foo needs
to perform a blocking activity, it registers that with the OS in some
fashion, rather than actually blocking, and returns back to
client_code_prolog.

So the call graph looks like this for a needs-to-do-blocking call:

client_code_prolog
  foo
    (foo_prolog occurs)
    register with OS

.....

select/poll/event - some OS wakeup mechanism
  foo_epilog
    client_code_epilog

For a foo() where no blocking needs to occur, the call graph is

client_code_prolog
  foo
    client_code_epilog

I hope this helps.

Rob
Received on Fri Apr 19 2002 - 06:40:33 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:15:13 MST