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

Re: Asynchronous callbacks from C

Thread Previous | Thread Next
David M. Lloyd
July 5, 2001 11:20
Re: Asynchronous callbacks from C
Message ID:
On Thu, 5 Jul 2001, Paul Johnson wrote:

> On Thu, Jul 05, 2001 at 09:39:33AM -0500, David M. Lloyd wrote:
> > OK, I see how it works, and it seems simple.  However, it seems that only
> > one thing can be using the runops deal at a time.  Also, would using this
> > method invalidate -DDEBUGGING?
> You're quite right about only one module being able to use it at a time.
> It works fine with -DDEBUGGING, but of course you'll need the
> DEBUGGING code from Perl_runops_debug() in your runops if you want to
> use it.

That's what I figured... which of course means that I need to check with
every version of Perl to make sure that that code doesn't change. :-(

> > /* Returns a 'handle' that can be used to remove a callback */
> > int add_callback(void (*callback)(void *data), int enable_cb);
> > 
> > /* Remove a callback from the list */
> > void remove_callback(int handle);
> > 
> > /* Set's the 'enable' flag so that a callback is called at next
> >    opportunity (this function would be async-safe */
> > void enable_callback(int handle, void *data);
> What is data in each of these cases?

You would set 'data' in 'enable_callback', and then when the loop comes
'round, 'data' would be passed to (*callback) as the first parameter.  
That way you can pass data to your callback.

I haven't quite worked out how I can make these C functions available to
modules though.  I had some scheme involving DynaLoader in mind, but after
looking at it a bit I'm not so sure...

- D


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