Library zoo_std.waiter_mpsc__code
Require Import zoo.prelude.
Require Import zoo.language.typeclasses.
Require Import zoo.language.notations.
Require Import zoo_std.condition.
Require Import zoo_std.mutex.
Require Import zoo.options.
Notation "'waiter_mpscู mutex'" := (
in_type "zoo_std.waiter_mpsc.t" 0
)(in custom zoo_field
).
Notation "'waiter_mpscู condition'" := (
in_type "zoo_std.waiter_mpsc.t" 1
)(in custom zoo_field
).
Notation "'waiter_mpscู flag'" := (
in_type "zoo_std.waiter_mpsc.t" 2
)(in custom zoo_field
).
Definition waiter_mpscู create : val :=
๐ณ๐๐ป โฝ โ
{ mutexู create (), conditionู create (), false }.
Definition waiter_mpscู notify : val :=
๐ณ๐๐ป "t" โ
๐ถ๐ณ "t".{waiter_mpscู flag} ๐๐ต๐ฒ๐ป (
true
) ๐ฒ๐น๐๐ฒ (
๐น๐ฒ๐ "res" =
mutexู protect "t".{waiter_mpscู mutex}
(๐ณ๐๐ป โฝ โ
๐ถ๐ณ "t".{waiter_mpscู flag} ๐๐ต๐ฒ๐ป (
true
) ๐ฒ๐น๐๐ฒ (
"t" <-{waiter_mpscู flag} true โฎ
false
))
๐ถ๐ป
conditionู notify "t".{waiter_mpscู condition} โฎ
"res"
).
Definition waiter_mpscู try_wait : val :=
๐ณ๐๐ป "t" โ
"t".{waiter_mpscู flag}.
Definition waiter_mpscู wait : val :=
๐ณ๐๐ป "t" โ
๐ถ๐ณ ยฌ waiter_mpscู try_wait "t" ๐๐ต๐ฒ๐ป (
๐น๐ฒ๐ "mtx" = "t".{waiter_mpscู mutex} ๐ถ๐ป
๐น๐ฒ๐ "cond" = "t".{waiter_mpscู condition} ๐ถ๐ป
mutexู protect "mtx"
(๐ณ๐๐ป โฝ โ
conditionู wait_until
"cond"
"mtx"
(๐ณ๐๐ป โฝ โ "t".{waiter_mpscู flag}))
).
Require Import zoo.language.typeclasses.
Require Import zoo.language.notations.
Require Import zoo_std.condition.
Require Import zoo_std.mutex.
Require Import zoo.options.
Notation "'waiter_mpscู mutex'" := (
in_type "zoo_std.waiter_mpsc.t" 0
)(in custom zoo_field
).
Notation "'waiter_mpscู condition'" := (
in_type "zoo_std.waiter_mpsc.t" 1
)(in custom zoo_field
).
Notation "'waiter_mpscู flag'" := (
in_type "zoo_std.waiter_mpsc.t" 2
)(in custom zoo_field
).
Definition waiter_mpscู create : val :=
๐ณ๐๐ป โฝ โ
{ mutexู create (), conditionู create (), false }.
Definition waiter_mpscู notify : val :=
๐ณ๐๐ป "t" โ
๐ถ๐ณ "t".{waiter_mpscู flag} ๐๐ต๐ฒ๐ป (
true
) ๐ฒ๐น๐๐ฒ (
๐น๐ฒ๐ "res" =
mutexู protect "t".{waiter_mpscู mutex}
(๐ณ๐๐ป โฝ โ
๐ถ๐ณ "t".{waiter_mpscู flag} ๐๐ต๐ฒ๐ป (
true
) ๐ฒ๐น๐๐ฒ (
"t" <-{waiter_mpscู flag} true โฎ
false
))
๐ถ๐ป
conditionู notify "t".{waiter_mpscู condition} โฎ
"res"
).
Definition waiter_mpscู try_wait : val :=
๐ณ๐๐ป "t" โ
"t".{waiter_mpscู flag}.
Definition waiter_mpscู wait : val :=
๐ณ๐๐ป "t" โ
๐ถ๐ณ ยฌ waiter_mpscู try_wait "t" ๐๐ต๐ฒ๐ป (
๐น๐ฒ๐ "mtx" = "t".{waiter_mpscู mutex} ๐ถ๐ป
๐น๐ฒ๐ "cond" = "t".{waiter_mpscู condition} ๐ถ๐ป
mutexู protect "mtx"
(๐ณ๐๐ป โฝ โ
conditionู wait_until
"cond"
"mtx"
(๐ณ๐๐ป โฝ โ "t".{waiter_mpscู flag}))
).