chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] performance isssue with FFI callbacks


From: tomtom
Subject: Re: [Chicken-users] performance isssue with FFI callbacks
Date: Sat, 26 Mar 2011 12:42:05 +0100
User-agent: Sup/0.11

hi 
 
> Is the callback perhaps invoked also by "jack_deactivate"?
> You can try adding some output in the callback and between
> the forms that invoke the "jack_..." functions.

I tried adding outputs here and there, and it radically changed the behaviour
of the program.

> (define jack_activate
>   (foreign-safe-lambda
>    int
>    "jack_activate"
>    (c-pointer jack_client)))
> 
> (define jack_deactivate
>   (foreign-lambda
>    int
>    "jack_deactivate"
>    (c-pointer jack_client)))
> 
> (define-external
>   (process (jack_nframes nframes) ((c-pointer void) arg))
>   int
>   ;; body
>   (display "processing ...\n")
>   nframes)
> 
> ((foreign-lambda* 
>   void () 
>   "jack_set_process_callback(client, process, NULL);"))
> 
> (display "jack_activate ...\n")
> (jack_activate client)
> (display "ok\n")
> 
> (sleep 1)
> 
> (display "jack_deactivate ...\n")
> (jack_deactivate client)
> (display "ok\n")
> 
> (jack_client_close client)

If I comment out jack_set_process_callback, everything is fine. But if the
callback is set, here are the different results I can get:

# jack_activate = foreign-lambda

[panic] callback invoked in non-safe context - execution terminated
[...]
jack.scm:172: jack_activate     <--

# jack_activate = foreign-safe-lambda

jack_activate ...
Segmentation fault


By pure curiosity, I tried various combinations with jack_deactivate as
foreign-safe-lambda, and I get other errors that are not necessarily the same
with each run (I guess it has something to do with my program and jacks running
in two different processes)

I might be wrong, but I think the tricky part is that scheme is not calling any
C function that calls back into scheme. jack_set_process_callback merely gives
informations to the jack server, and jack_activate only tells the server "okay,
you can start using the callback".

the other day some folk on #chicken told me that "callbacks are hairy". I can
totally understand that feeling now ...

tom



reply via email to

[Prev in Thread] Current Thread [Next in Thread]