Skip to content

Commit

Permalink
refactor: small optimization to Fiber.Ivar.{read,fill}
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>

<!-- ps-id: ad3b62b7-f72f-46f7-ba70-c9d925a0330a -->
  • Loading branch information
rgrinberg committed Apr 9, 2024
1 parent f8973fb commit 59df66f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions fiber/src/core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,20 @@ module Ivar = struct
type 'a t = 'a ivar

let create () = { state = Empty }
let read t k = Read_ivar (t, k)
let fill t x k = Fill_ivar (t, x, k)

let read t k =
match t.state with
| Full x -> k x
| Empty_with_readers _ | Empty -> Read_ivar (t, k)
;;

let fill t x k =
match t.state with
| Empty ->
t.state <- Full x;
k ()
| Full _ | Empty_with_readers _ -> Fill_ivar (t, x, k)
;;

let peek t k =
k
Expand Down

0 comments on commit 59df66f

Please sign in to comment.