Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quasar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
quasar
Commits
b32fe965
Commit
b32fe965
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Pass ExceptionChannel instead of undefined
parent
6b370214
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#2685
passed
3 years ago
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Quasar/Resources/Disposer.hs
+7
-7
7 additions, 7 deletions
src/Quasar/Resources/Disposer.hs
with
7 additions
and
7 deletions
src/Quasar/Resources/Disposer.hs
+
7
−
7
View file @
b32fe965
...
...
@@ -135,7 +135,7 @@ data ResourceManager = ResourceManager {
}
data
ResourceManagerState
=
ResourceManagerNormal
(
TVar
(
HashMap
Unique
Disposer
))
TIOWorker
=
ResourceManagerNormal
(
TVar
(
HashMap
Unique
Disposer
))
TIOWorker
ExceptionChannel
|
ResourceManagerDisposing
(
Awaitable
[
DisposeDependencies
])
|
ResourceManagerDisposed
...
...
@@ -147,7 +147,7 @@ newResourceManagerSTM :: TIOWorker -> ExceptionChannel -> STM ResourceManager
newResourceManagerSTM
worker
exChan
=
do
resourceManagerKey
<-
newUniqueSTM
attachedResources
<-
newTVar
mempty
resourceManagerState
<-
newTVar
(
ResourceManagerNormal
attachedResources
worker
)
resourceManagerState
<-
newTVar
(
ResourceManagerNormal
attachedResources
worker
exChan
)
resourceManagerFinalizers
<-
newFinalizers
pure
ResourceManager
{
resourceManagerKey
,
...
...
@@ -163,7 +163,7 @@ attachResource resourceManager resource =
attachDisposer
::
ResourceManager
->
Disposer
->
STM
()
attachDisposer
resourceManager
disposer
=
do
readTVar
(
resourceManagerState
resourceManager
)
>>=
\
case
ResourceManagerNormal
attachedResources
_
->
do
ResourceManagerNormal
attachedResources
_
_
->
do
alreadyAttached
<-
isJust
.
HM
.
lookup
key
<$>
readTVar
attachedResources
unless
alreadyAttached
do
-- Returns false if the disposer is already finalized
...
...
@@ -175,7 +175,7 @@ attachDisposer resourceManager disposer = do
key
=
disposerKey
disposer
finalizer
::
STM
()
finalizer
=
readTVar
(
resourceManagerState
resourceManager
)
>>=
\
case
ResourceManagerNormal
attachedResources
_
->
modifyTVar
attachedResources
(
HM
.
delete
key
)
ResourceManagerNormal
attachedResources
_
_
->
modifyTVar
attachedResources
(
HM
.
delete
key
)
-- No finalization required in other states, since all resources are disposed soon
-- (and awaiting each resource is cheaper than modifying a HashMap until it is empty).
_
->
pure
()
...
...
@@ -189,11 +189,11 @@ beginDisposeResourceManager rm = do
beginDisposeResourceManagerInternal
::
ResourceManager
->
STM
DisposeDependencies
beginDisposeResourceManagerInternal
rm
=
do
readTVar
(
resourceManagerState
rm
)
>>=
\
case
ResourceManagerNormal
attachedResources
worker
->
do
ResourceManagerNormal
attachedResources
worker
exChan
->
do
dependenciesVar
<-
newAsyncVarSTM
writeTVar
(
resourceManagerState
rm
)
(
ResourceManagerDisposing
(
toAwaitable
dependenciesVar
))
attachedDisposers
<-
HM
.
elems
<$>
readTVar
attachedResources
startShortIO_
(
void
$
forkIO
(
disposeThread
dependenciesVar
attachedDisposers
))
worker
undefined
startShortIO_
(
void
$
forkIO
(
disposeThread
dependenciesVar
attachedDisposers
))
worker
exChan
pure
$
DisposeDependencies
rmKey
(
toAwaitable
dependenciesVar
)
ResourceManagerDisposing
deps
->
pure
$
DisposeDependencies
rmKey
deps
ResourceManagerDisposed
->
pure
$
DisposeDependencies
rmKey
mempty
...
...
@@ -247,7 +247,7 @@ resourceManagerIsDisposed rm = unsafeAwaitSTM $
resourceManagerIsDisposing
::
ResourceManager
->
Awaitable
()
resourceManagerIsDisposing
rm
=
unsafeAwaitSTM
$
readTVar
(
resourceManagerState
rm
)
>>=
\
case
(
ResourceManagerNormal
_
_
)
->
retry
(
ResourceManagerNormal
_
_
_
)
->
retry
_
->
pure
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment