forked from ocaml/ocaml
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separation des locks et des conditions. Nettoyage du scheduler.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@396 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
- Loading branch information
1 parent
3865625
commit ef689c7
Showing
8 changed files
with
117 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
(***********************************************************************) | ||
(* *) | ||
(* Caml Special Light *) | ||
(* *) | ||
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) | ||
(* *) | ||
(* Copyright 1995 Institut National de Recherche en Informatique et *) | ||
(* Automatique. Distributed only by permission. *) | ||
(* *) | ||
(***********************************************************************) | ||
|
||
(* $Id$ *) | ||
|
||
type t = | ||
{ mutable cond_waiting: t list } | ||
|
||
let new () = { cond_waiting = [] } | ||
|
||
let wait cond lock = | ||
cond.cond_waiting <- Thread.self() :: cond.cond_waiting; | ||
Mutex.unlock lock; | ||
Thread.sleep() | ||
|
||
let signal cond = | ||
match cond.cond_waiting with | ||
[] -> () | ||
| pid :: rem -> Thread.wakeup pid; cond.cond_waiting <- rem | ||
|
||
let broadcast cond = | ||
List.iter Thread.wakeup cond.cond_waiting; | ||
cond.cond_waiting <- [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(***********************************************************************) | ||
(* *) | ||
(* Caml Special Light *) | ||
(* *) | ||
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) | ||
(* *) | ||
(* Copyright 1995 Institut National de Recherche en Informatique et *) | ||
(* Automatique. Distributed only by permission. *) | ||
(* *) | ||
(***********************************************************************) | ||
|
||
(* $Id$ *) | ||
|
||
(* Module [Condition]: synchronization between threads via conditions *) | ||
|
||
type t | ||
val new: unit -> t | ||
val wait: t -> Mutex.t -> unit | ||
val signal: t -> unit | ||
val broadcast: t -> unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
(***********************************************************************) | ||
(* *) | ||
(* Caml Special Light *) | ||
(* *) | ||
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) | ||
(* *) | ||
(* Copyright 1995 Institut National de Recherche en Informatique et *) | ||
(* Automatique. Distributed only by permission. *) | ||
(* *) | ||
(***********************************************************************) | ||
|
||
(* $Id$ *) | ||
|
||
type t = | ||
{ mutable locked: bool; | ||
mutable lock_waiting: t list } | ||
|
||
(* We rely heavily on the fact that signals are detected only at | ||
function applications and beginning of loops, making all other operations | ||
atomic. *) | ||
|
||
let new_lock () = { locked = false; lock_waiting = [] } | ||
|
||
let rec lock l = | ||
if l.locked then begin | ||
l.lock_waiting <- Thread.self() :: l.lock_waiting; | ||
Thread.sleep(); | ||
lock l | ||
end else begin | ||
l.locked <- true | ||
end | ||
|
||
let try_lock l = | ||
if l.locked then false else begin l.locked <- true; true end | ||
|
||
let unlock l = | ||
List.iter Thread.wakeup l.lock_waiting; | ||
l.locked <- false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(***********************************************************************) | ||
(* *) | ||
(* Caml Special Light *) | ||
(* *) | ||
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) | ||
(* *) | ||
(* Copyright 1995 Institut National de Recherche en Informatique et *) | ||
(* Automatique. Distributed only by permission. *) | ||
(* *) | ||
(***********************************************************************) | ||
|
||
(* $Id$ *) | ||
|
||
(* Module [Mutex]: mutually-exclusive locks *) | ||
|
||
type t | ||
val new: unit -> t | ||
val lock: t -> unit | ||
val try_lock: t -> bool | ||
val unlock: t -> unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters