-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement a simple lock for multicore
- Loading branch information
Showing
8 changed files
with
86 additions
and
12 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,32 @@ | ||
(** Locks for multicore*) | ||
module C = Domainslib.Chan | ||
|
||
type t = int C.t | ||
|
||
let create_lock () = | ||
let c = C.make_bounded 1 in | ||
C.send c 0; | ||
c | ||
|
||
let acquire_lock lock = | ||
C.recv lock |> ignore | ||
|
||
let release_lock lock = | ||
C.send lock 0 | ||
|
||
let is_locked lock = | ||
let c = C.recv_poll lock in | ||
match c with | ||
| Some v -> | ||
C.send lock v; | ||
false | ||
| None -> | ||
true | ||
|
||
let try_acquire lock = | ||
match C.recv_poll lock with | ||
| Some _ -> true | ||
| None -> false | ||
|
||
let try_release lock = | ||
C.send_poll lock 0 |
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,9 @@ | ||
(** Locks for m*) | ||
|
||
type t | ||
val create_lock : unit -> t | ||
val acquire_lock : t -> unit | ||
val release_lock : t -> unit | ||
val is_locked : t -> bool | ||
val try_acquire : t -> bool | ||
val try_release : t -> bool |
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
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