develooper Front page | perl.perl5.porters | Postings from August 2001

RE: Adding callbacks to the core

Thread Previous | Thread Next
David M. Lloyd
August 20, 2001 14:10
RE: Adding callbacks to the core
Message ID:
On Mon, 20 Aug 2001, Dan Sugalski wrote:

> At 03:36 PM 8/20/2001 -0500, David M. Lloyd wrote:
> >On Mon, 20 Aug 2001, Arthur Bergman wrote:
> >
> > > Isn't callback check the same as async check?
> >
> >Similar but not the same.  Async check scans an array looking to see which
> >signal was triggered; Callback check doesn't need to scan.  Also, with
> >callback check, you can add and remove callbacks at runtime.
> Why not piggyback the callback stuff onto the event stuff? The check
> can still be cheap--while the ultimate figuring out and dispatch to
> the appropriate routine might be more expensive, the user only pays
> that when something happens rather than all the time.

That may be an option.  I'm going to try doing the seperate check + 'use
callbacks' to enable the callback-checking runops routine, and we'll see
how that is.

I'm hesitant to mess with the current event stuff because it was really
not designed to do anything but signals.  The basic logic runs like this:

Do I have a signal? If yes:
1. Reset signal pending flag.
2. Scan PL_psig_pend to find any waiting signals... this includes scanning
for signals that are not waiting. For each waiting signal, call
(*PL_sighandlerp) with the signal.

The (current) callback checker would run like this:

Do I have a callback? If yes:
1. Run all callbacks.

All the work of managing callbacks happens when you signal it; not when
they are checked for.

The scanning nature of the signal handler was designed to work on a static
signal set, and it was designed to be reentrant by using ++, which is
pretty safe on most platforms I think.

The (current) callback handler is designed to be threadsafe, not
necessarily reentrant; and it's optimized to be faster when callbacks are
being executed, not when they are being registered.  This is because a
callback may be called continuously (for instance, in a profiler), so you
wouldn't want to spend lots of time scanning an array.

I suppose it would be possible to merge the two ideas.  That would take a
bigger effort though.  I will start small. :-)

- D


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About