X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Flablgtk%2Flablgtk_20001129-0.1.0%2FgtkThread.ml;fp=helm%2FDEVEL%2Flablgtk%2Flablgtk_20001129-0.1.0%2FgtkThread.ml;h=3ab577e3e41aa7a60771b9b768df05687858f33c;hb=993347ab3975ccc7c39dc0324255fab4a75bc0e2;hp=0000000000000000000000000000000000000000;hpb=1cd4dd7c3838fee49e5851c0ac7acf42f4fc3d67;p=helm.git diff --git a/helm/DEVEL/lablgtk/lablgtk_20001129-0.1.0/gtkThread.ml b/helm/DEVEL/lablgtk/lablgtk_20001129-0.1.0/gtkThread.ml new file mode 100644 index 000000000..3ab577e3e --- /dev/null +++ b/helm/DEVEL/lablgtk/lablgtk_20001129-0.1.0/gtkThread.ml @@ -0,0 +1,33 @@ +(* $Id$ *) + +open GtkMain + +(* We check first whether there are some event pending, and run + some iterations. We then need to delay, thus focing a thread switch. *) + +let main () = + try + let loop = (Glib.Main.create true) in + Main.loops := loop :: !Main.loops; + while Glib.Main.is_running loop do + let i = ref 0 in + while !i < 100 && Glib.Main.pending () do + Glib.Main.iteration true; + incr i + done; + Thread.delay 0.001 + done; + Main.loops := List.tl !Main.loops + with exn -> + Main.loops := List.tl !Main.loops; + raise exn + +let start = Thread.create main + +let _ = + let mutex = Mutex.create () in + let depth = ref 0 in + GtkSignal.enter_callback := + (fun () -> if !depth = 0 then Mutex.lock mutex; incr depth); + GtkSignal.exit_callback := + (fun () -> decr depth; if !depth = 0 then Mutex.unlock mutex)