Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] GC and caml_oldify_local_roots taking too much time
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christophe Raffalli <christophe.raffalli@u...>
Subject: Re: [Caml-list] Calback

>  > 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