Library zoo_std.lazy__code
Require Import zoo.prelude.
Require Import zoo.language.typeclasses.
Require Import zoo.language.notations.
Require Import zoo_std.mutex.
Require Import zoo.options.
Notation "'lazyู Unset'" := (
in_type "zoo_std.lazy.state" 0
)(in custom zoo_tag
).
Notation "'lazyู Setting'" := (
in_type "zoo_std.lazy.state" 1
)(in custom zoo_tag
).
Notation "'lazyู Set'" := (
in_type "zoo_std.lazy.state" 2
)(in custom zoo_tag
).
Definition lazyู make : val :=
๐ณ๐๐ป "fn" โ
๐ฟ๐ฒ๐ณ โlazyู Unset( "fn" ).
Definition lazyู return : val :=
๐ณ๐๐ป "res" โ
๐ฟ๐ฒ๐ณ โlazyู Set( "res" ).
Definition lazyู is_set : val :=
๐ณ๐๐ป "t" โ
๐บ๐ฎ๐๐ฐ๐ต !"t" ๐๐ถ๐๐ต
| lazyู Set โฝ โ
true
| โฝ โ
false
๐ฒ๐ป๐ฑ.
Definition lazyู is_unset : val :=
๐ณ๐๐ป "t" โ
ยฌ lazyู is_set "t".
Definition lazyู get : val :=
๐ฟ๐ฒ๐ฐ "get" "t" โ
๐บ๐ฎ๐๐ฐ๐ต !"t" ๐๐ถ๐๐ต
| lazyู Set "res" โ
"res"
| lazyู Setting "mtx" โ
mutexู synchronize "mtx" โฎ
"get" "t"
| lazyู Unset "fn" ๐ฎ๐ "state" โ
๐น๐ฒ๐ "mtx" = mutexู create_lock () ๐ถ๐ป
๐ถ๐ณ
๐ฐ๐ฎ๐ "t".[contents] "state" โlazyู Setting( "mtx" )
๐๐ต๐ฒ๐ป (
๐น๐ฒ๐ "res" = "fn" () ๐ถ๐ป
"t" <- โlazyู Set( "res" ) โฎ
mutexู unlock "mtx" โฎ
"res"
) ๐ฒ๐น๐๐ฒ (
mutexู unlock "mtx" โฎ
"get" "t"
)
๐ฒ๐ป๐ฑ.
Require Import zoo.language.typeclasses.
Require Import zoo.language.notations.
Require Import zoo_std.mutex.
Require Import zoo.options.
Notation "'lazyู Unset'" := (
in_type "zoo_std.lazy.state" 0
)(in custom zoo_tag
).
Notation "'lazyู Setting'" := (
in_type "zoo_std.lazy.state" 1
)(in custom zoo_tag
).
Notation "'lazyู Set'" := (
in_type "zoo_std.lazy.state" 2
)(in custom zoo_tag
).
Definition lazyู make : val :=
๐ณ๐๐ป "fn" โ
๐ฟ๐ฒ๐ณ โlazyู Unset( "fn" ).
Definition lazyู return : val :=
๐ณ๐๐ป "res" โ
๐ฟ๐ฒ๐ณ โlazyู Set( "res" ).
Definition lazyู is_set : val :=
๐ณ๐๐ป "t" โ
๐บ๐ฎ๐๐ฐ๐ต !"t" ๐๐ถ๐๐ต
| lazyู Set โฝ โ
true
| โฝ โ
false
๐ฒ๐ป๐ฑ.
Definition lazyู is_unset : val :=
๐ณ๐๐ป "t" โ
ยฌ lazyู is_set "t".
Definition lazyู get : val :=
๐ฟ๐ฒ๐ฐ "get" "t" โ
๐บ๐ฎ๐๐ฐ๐ต !"t" ๐๐ถ๐๐ต
| lazyู Set "res" โ
"res"
| lazyู Setting "mtx" โ
mutexู synchronize "mtx" โฎ
"get" "t"
| lazyู Unset "fn" ๐ฎ๐ "state" โ
๐น๐ฒ๐ "mtx" = mutexู create_lock () ๐ถ๐ป
๐ถ๐ณ
๐ฐ๐ฎ๐ "t".[contents] "state" โlazyู Setting( "mtx" )
๐๐ต๐ฒ๐ป (
๐น๐ฒ๐ "res" = "fn" () ๐ถ๐ป
"t" <- โlazyู Set( "res" ) โฎ
mutexู unlock "mtx" โฎ
"res"
) ๐ฒ๐น๐๐ฒ (
mutexู unlock "mtx" โฎ
"get" "t"
)
๐ฒ๐ป๐ฑ.