From: Christophe Raffalli <christophe.raffalli@univ-savoie.fr>
To: Olivier Andrieu <andrieu@ijm.jussieu.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Calback
Date: Tue, 20 Jul 2004 19:09:47 -0400 [thread overview]
Message-ID: <40FDA63B.8020306@univ-savoie.fr> (raw)
In-Reply-To: <20040720.164053.104046716.andrieu@ijm.jussieu.fr>
> > static void glutTimerFunc_cb(int fun_arg)
> > {
> > // fun_arg is a pointer on a caml pair hidden in an integer.
> > // Moreover we remove the global root because each callback is used once
> > // by the timer.
> > value *v = (value) fun_arg;
>
> I'm afraid this will break on plaforms where `sizeof (int) != sizeof (long)'.
>
Anyway, for GlSurf, I am just using this (which is faster) and for most
case I think this a the right code (except that set_timer should raise
an exception it init_timer was not called previously).
This code allow to change the callback associated with timers but does
not allow to have two timers with different callbacks. But the later is
only usefull (in GLUT) for timers, all other callback could use code
similar to this.
-- ML -------------------------------
(* init_timer f set the function to be called by all timer *)
external init_timer : (value:int -> unit) -> unit = "myinit_glutTimerFunc"
(* set_timer ms val : set a timer in ms milliseconds calling the
function registered by init_timer with val as argument *)
external set_timer : int -> int -> unit = "myml_glutTimerFunc"
-- C --------------------------------
static value* caml_glutTimerFunc_cb = NULL;
static void myglutTimerFunc_cb(int val)
{
leave_blocking_section ();
callback (*caml_glutTimerFunc_cb, Val_int(val));
enter_blocking_section ();
}
CAMLprim value myml_glutTimerFunc(value millis_val, value v) // set
Timer callback
{
glutTimerFunc(Int_val(millis_val), &myglutTimerFunc_cb, Int_val(v));
return Val_unit;
}
CAMLprim value myinit_glutTimerFunc(value v) {
if (caml_glutTimerFunc_cb) {
caml_remove_global_root(caml_glutTimerFunc_cb);
} else {
caml_glutTimerFunc_cb = (value*) malloc(sizeof(value));
}
*caml_glutTimerFunc_cb = v;
caml_register_global_root(caml_glutTimerFunc_cb);
return Val_unit;
}
--
Christophe Raffalli
Université de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex
tél: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@univ-savoie.fr
www: http://www.lama.univ-savoie.fr/~RAFFALLI
---------------------------------------------
IMPORTANT: this mail is signed using PGP/MIME
At least Enigmail/Mozilla, mutt or evolution
can check this signature
---------------------------------------------
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
prev parent reply other threads:[~2004-07-20 17:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-19 17:59 [Caml-list] GC and caml_oldify_local_roots taking too much time Christophe Raffalli
2004-07-19 12:21 ` Damien Doligez
2004-07-19 19:33 ` Christophe Raffalli
2004-07-19 20:17 ` Christophe Raffalli
2004-07-19 14:28 ` Richard Jones
2004-07-19 14:38 ` Richard Jones
2004-07-19 15:12 ` Olivier Andrieu
2004-07-19 20:36 ` Christophe Raffalli
2004-07-20 20:00 ` [Caml-list] Calback (was caml_oldify_local_roots taking too much time) Christophe Raffalli
2004-07-20 14:40 ` [Caml-list] Calback Olivier Andrieu
[not found] ` <40FD9FDE.3070000@univ-savoie.fr>
2004-07-20 22:44 ` Christophe Raffalli
2004-07-21 0:54 ` Jere Sanisalo
2004-07-20 23:09 ` Christophe Raffalli [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=40FDA63B.8020306@univ-savoie.fr \
--to=christophe.raffalli@univ-savoie.fr \
--cc=andrieu@ijm.jussieu.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox