-
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.
Merge branch 'master' of https://github.com/Sudha247/lwt-multicore
- Loading branch information
Showing
10 changed files
with
190 additions
and
205 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
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
Oops, something went wrong.