1995-11-05 09:27:32 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1995-11-05 09:27:32 -08:00
|
|
|
(* *)
|
1995-11-14 09:12:57 -08:00
|
|
|
(* Xavier Leroy and Damien Doligez, INRIA Rocquencourt *)
|
1995-11-05 09:27:32 -08:00
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
2001-12-07 05:41:02 -08:00
|
|
|
(* under the terms of the GNU Library General Public License, with *)
|
|
|
|
(* the special exception on linking described in file ../../LICENSE. *)
|
1995-11-05 09:27:32 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
1996-04-03 02:02:34 -08:00
|
|
|
type t = { mutable waiting: Thread.t list }
|
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
let create () = { waiting = [] }
|
1996-04-03 02:02:34 -08:00
|
|
|
|
|
|
|
let wait cond mut =
|
|
|
|
Thread.critical_section := true;
|
|
|
|
Mutex.unlock mut;
|
|
|
|
cond.waiting <- Thread.self() :: cond.waiting;
|
|
|
|
Thread.sleep();
|
|
|
|
Mutex.lock mut
|
|
|
|
|
|
|
|
let signal cond =
|
|
|
|
match cond.waiting with (* atomic *)
|
|
|
|
[] -> ()
|
|
|
|
| th :: rem -> cond.waiting <- rem (* atomic *); Thread.wakeup th
|
|
|
|
|
|
|
|
let broadcast cond =
|
|
|
|
let w = cond.waiting in (* atomic *)
|
|
|
|
cond.waiting <- []; (* atomic *)
|
|
|
|
List.iter Thread.wakeup w
|