Documentation
Concurrency
.
Semaphore
Search
return to top
source
Imports
Init
Std.Sync.Mutex
Imported by
Concurrency
.
Semaphore
.
Count
Concurrency
.
Semaphore
Concurrency
.
Semaphore
.
new
Concurrency
.
Semaphore
.
isAvailable
Concurrency
.
Semaphore
.
isUnavailable
Concurrency
.
Semaphore
.
wait
Concurrency
.
Semaphore
.
signal
Concurrency
.
Semaphore
.
bracket
source
@[reducible, inline]
abbrev
Concurrency
.
Semaphore
.
Count
:
Type
Equations
Concurrency.Semaphore.Count
=
Nat
Instances For
source
structure
Concurrency
.
Semaphore
:
Type
condition :
Std.Condvar
count :
Std.Mutex
Nat
Instances For
source
def
Concurrency
.
Semaphore
.
new
(
n
:
Nat
:=
0
)
:
BaseIO
Semaphore
Equations
Concurrency.Semaphore.new
n
=
Concurrency.Semaphore.mk✝
<$>
Std.Condvar.new
<*>
Std.Mutex.new
n
Instances For
source
def
Concurrency
.
Semaphore
.
isAvailable
{
m
:
Type
→
Type
u_1
}
[
Monad
m
]
[
MonadState
Nat
m
]
:
m
Bool
Equations
Concurrency.Semaphore.isAvailable
=
do let
count
←
get
pure
(
decide
(
count
>
0
))
Instances For
source
def
Concurrency
.
Semaphore
.
isUnavailable
{
m
:
Type
→
Type
u_1
}
[
Monad
m
]
[
MonadState
Nat
m
]
:
m
Bool
Equations
Concurrency.Semaphore.isUnavailable
=
not
<$>
Concurrency.Semaphore.isAvailable
Instances For
source
def
Concurrency
.
Semaphore
.
wait
(
self
:
Semaphore
)
:
BaseIO
Unit
Equations
self
.
wait
=
self
.
count
.
atomicallyOnce
self
.
condition
Concurrency.Semaphore.isAvailable
(
modify
Nat.pred
)
Instances For
source
def
Concurrency
.
Semaphore
.
signal
(
self
:
Semaphore
)
:
BaseIO
Unit
Equations
self
.
signal
=
self
.
count
.
atomically
do
modify
Nat.succ
liftM
self
.
condition
.
notifyOne
Instances For
source
def
Concurrency
.
Semaphore
.
bracket
{
m
:
Type
→
Type
u_1
}
{
a
:
Type
}
[
Monad
m
]
[
MonadFinally
m
]
[
MonadLift
BaseIO
m
]
(
self
:
Semaphore
)
(
action
:
m
a
)
:
m
a
Equations
self
.
bracket
action
=
tryFinally
(do
liftM
self
.
wait
action
)
(
liftM
self
.
signal
)
Instances For