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
5d37a842
Commit
5d37a842
authored
3 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Move fork functions for STM to Quasar.Async.Fork
parent
83ea9c08
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
quasar.cabal
+1
-0
1 addition, 0 deletions
quasar.cabal
src/Quasar/Async/Fork.hs
+51
-0
51 additions, 0 deletions
src/Quasar/Async/Fork.hs
src/Quasar/Async/STMHelper.hs
+2
-24
2 additions, 24 deletions
src/Quasar/Async/STMHelper.hs
src/Quasar/Async/V2.hs
+1
-0
1 addition, 0 deletions
src/Quasar/Async/V2.hs
with
55 additions
and
24 deletions
quasar.cabal
+
1
−
0
View file @
5d37a842
...
...
@@ -85,6 +85,7 @@ library
unordered-containers,
exposed-modules:
Quasar
Quasar.Async.Fork
Quasar.Async.STMHelper
Quasar.Async.V2
Quasar.Awaitable
...
...
This diff is collapsed.
Click to expand it.
src/Quasar/Async/Fork.hs
0 → 100644
+
51
−
0
View file @
5d37a842
module
Quasar.Async.Fork
(
-- * Forking with an asynchronous exception channel
-- ** STM
fork
,
fork_
,
forkWithUnmask
,
forkWithUnmask_
,
-- ** ShortIO
forkWithUnmaskShortIO
,
forkWithUnmaskShortIO_
,
)
where
import
Control.Concurrent
(
ThreadId
)
import
Control.Concurrent.STM
import
Control.Monad.Catch
import
Quasar.Async.STMHelper
import
Quasar.Awaitable
import
Quasar.Exceptions
import
Quasar.Prelude
import
Quasar.Utils.ShortIO
-- * Fork in STM (with ExceptionChannel)
fork
::
IO
()
->
TIOWorker
->
ExceptionChannel
->
STM
(
Awaitable
ThreadId
)
fork
fn
=
forkWithUnmask
(
\
unmask
->
unmask
fn
)
fork_
::
IO
()
->
TIOWorker
->
ExceptionChannel
->
STM
()
fork_
fn
worker
exChan
=
void
$
fork
fn
worker
exChan
forkWithUnmask
::
((
forall
a
.
IO
a
->
IO
a
)
->
IO
()
)
->
TIOWorker
->
ExceptionChannel
->
STM
(
Awaitable
ThreadId
)
forkWithUnmask
fn
worker
exChan
=
startShortIO
(
forkWithUnmaskShortIO
fn
exChan
)
worker
exChan
forkWithUnmask_
::
((
forall
a
.
IO
a
->
IO
a
)
->
IO
()
)
->
TIOWorker
->
ExceptionChannel
->
STM
()
forkWithUnmask_
fn
worker
exChan
=
void
$
forkWithUnmask
fn
worker
exChan
-- * Fork in ShortIO (with ExceptionChannel)
forkWithUnmaskShortIO
::
((
forall
a
.
IO
a
->
IO
a
)
->
IO
()
)
->
ExceptionChannel
->
ShortIO
ThreadId
forkWithUnmaskShortIO
fn
exChan
=
forkFn
where
forkFn
::
ShortIO
ThreadId
forkFn
=
mask_
$
forkIOWithUnmaskShortIO
wrappedFn
wrappedFn
::
(
forall
a
.
IO
a
->
IO
a
)
->
IO
()
wrappedFn
unmask
=
fn
unmask
`
catchAll
`
\
ex
->
atomically
(
throwToExceptionChannel
exChan
ex
)
forkWithUnmaskShortIO_
::
((
forall
a
.
IO
a
->
IO
a
)
->
IO
()
)
->
ExceptionChannel
->
ShortIO
()
forkWithUnmaskShortIO_
fn
exChan
=
void
$
forkWithUnmaskShortIO
fn
exChan
This diff is collapsed.
Click to expand it.
src/Quasar/Async/STMHelper.hs
+
2
−
24
View file @
5d37a842
module
Quasar.Async.STMHelper
(
-- * Helper to fork from STM
TIOWorker
,
newTIOWorker
,
startShortIO
,
startShortIO_
,
fork
,
fork_
,
forkWithUnmask
,
forkWithUnmask_
,
)
where
import
Control.Concurrent
(
ThreadId
,
forkIO
)
import
Control.Concurrent
(
forkIO
)
import
Control.Concurrent.STM
import
Control.Exception
(
BlockedIndefinitelyOnSTM
)
import
Control.Monad.Catch
...
...
@@ -50,22 +47,3 @@ newTIOWorker = do
(
\
(
_
::
BlockedIndefinitelyOnSTM
)
->
pure
()
)
pure
$
TIOWorker
jobQueue
fork
::
IO
()
->
TIOWorker
->
ExceptionChannel
->
STM
(
Awaitable
ThreadId
)
fork
fn
=
forkWithUnmask
(
\
unmask
->
unmask
fn
)
fork_
::
IO
()
->
TIOWorker
->
ExceptionChannel
->
STM
()
fork_
fn
worker
exChan
=
void
$
fork
fn
worker
exChan
forkWithUnmask
::
((
forall
a
.
IO
a
->
IO
a
)
->
IO
()
)
->
TIOWorker
->
ExceptionChannel
->
STM
(
Awaitable
ThreadId
)
forkWithUnmask
fn
worker
exChan
=
startShortIO
forkFn
worker
exChan
where
forkFn
::
ShortIO
ThreadId
forkFn
=
mask_
$
forkIOWithUnmaskShortIO
wrappedFn
wrappedFn
::
(
forall
a
.
IO
a
->
IO
a
)
->
IO
()
wrappedFn
unmask
=
fn
unmask
`
catchAll
`
\
ex
->
atomically
(
throwToExceptionChannel
exChan
ex
)
forkWithUnmask_
::
((
forall
a
.
IO
a
->
IO
a
)
->
IO
()
)
->
TIOWorker
->
ExceptionChannel
->
STM
()
forkWithUnmask_
fn
worker
exChan
=
void
$
forkWithUnmask
fn
worker
exChan
This diff is collapsed.
Click to expand it.
src/Quasar/Async/V2.hs
+
1
−
0
View file @
5d37a842
...
...
@@ -18,6 +18,7 @@ module Quasar.Async.V2 (
import
Control.Concurrent
(
ThreadId
)
import
Control.Concurrent.STM
import
Control.Monad.Catch
import
Quasar.Async.Fork
import
Quasar.Async.STMHelper
import
Quasar.Awaitable
import
Quasar.Exceptions
...
...
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