-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Add support for domain local await
- Loading branch information
Showing
8 changed files
with
124 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,34 @@ | ||
module Domain_local_await = Kcas.Domain_local_await | ||
|
||
let prepare_for_await mode = | ||
let state = | ||
Atomic.make | ||
(mode :> [ Domain_local_await.mode | `Released | `Awaiting of _ ]) | ||
in | ||
let release () = | ||
if Atomic.get state != `Released then | ||
match Atomic.exchange state `Released with | ||
| `Awaiting b -> Broadcast.resume_all b | ||
| _ -> () | ||
and await () = | ||
match Atomic.get state with | ||
| `Released -> () | ||
| `Awaiting _ -> failwith "await called twice" | ||
| (`Cancelable | `Protected) as was -> | ||
let b = Broadcast.create () in | ||
if Atomic.compare_and_set state was (`Awaiting b) then | ||
let resume ctx enqueue = | ||
match Broadcast.suspend b (fun () -> enqueue (Ok ())) with | ||
| None -> () | ||
| Some request -> ( | ||
match Atomic.get state with | ||
| `Awaiting _ -> | ||
Cancel.Fiber_context.set_cancel_fn ctx @@ fun ex -> | ||
if Broadcast.cancel request then enqueue (Error ex) | ||
| `Cancelable | `Protected | `Released -> | ||
if Broadcast.cancel request then enqueue (Ok ())) | ||
in | ||
if was == `Cancelable then Suspend.enter resume | ||
else Suspend.enter_unchecked resume | ||
in | ||
Domain_local_await.{ release; await } |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
(library | ||
(name eio__core) | ||
(public_name eio.core) | ||
(libraries cstruct hmap lwt-dllist fmt optint)) | ||
(libraries cstruct hmap lwt-dllist fmt optint kcas)) |
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 |
---|---|---|
|
@@ -19,4 +19,6 @@ module Private = struct | |
| Fork = Fiber.Fork | ||
| Get_context = Cancel.Get_context | ||
end | ||
|
||
module Dla = Dla | ||
end |
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