summaryrefslogtreecommitdiff
path: root/otherlibs/labltk/support/tkthread.ml
diff options
context:
space:
mode:
Diffstat (limited to 'otherlibs/labltk/support/tkthread.ml')
-rw-r--r--otherlibs/labltk/support/tkthread.ml16
1 files changed, 8 insertions, 8 deletions
diff --git a/otherlibs/labltk/support/tkthread.ml b/otherlibs/labltk/support/tkthread.ml
index 0336afe3c0..8a77eb49e3 100644
--- a/otherlibs/labltk/support/tkthread.ml
+++ b/otherlibs/labltk/support/tkthread.ml
@@ -20,20 +20,18 @@ let with_jobs f =
Mutex.lock m; let y = f jobs in Mutex.unlock m; y
let loop_id = ref None
-let reset () = loop_id := None
-let cannot_sync () =
- match !loop_id with None -> true
- | Some id -> Thread.id (Thread.self ()) = id
-
let gui_safe () =
- not (Sys.os_type = "Win32") || !loop_id = Some(Thread.id (Thread.self ()))
+ !loop_id = Some(Thread.id (Thread.self ()))
+let running () =
+ !loop_id <> None
let has_jobs () = not (with_jobs Queue.is_empty)
let n_jobs () = with_jobs Queue.length
let do_next_job () = with_jobs Queue.take ()
let async j x = with_jobs (Queue.add (fun () -> j x))
let sync f x =
- if cannot_sync () then f x else
+ if !loop_id = None then failwith "Tkthread.sync";
+ if gui_safe () then f x else
let m = Mutex.create () in
let res = ref None in
Mutex.lock m;
@@ -62,6 +60,8 @@ let thread_main () =
raise exn
let start () =
- Thread.create thread_main ()
+ let th = Thread.create thread_main () in
+ loop_id := Some (Thread.id th);
+ th
let top = Widget.default_toplevel