Skip to content

Commit

Permalink
move ThreadAffinity into its own module
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellwrosen committed Nov 28, 2023
1 parent 30d26f4 commit cc554dd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.envrc
.ghc.environment.*
.ghcid
Session.vim
dist-newstyle/
1 change: 1 addition & 0 deletions ki/ki.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ library
Ki.Internal.NonblockingSTM
Ki.Internal.Scope
Ki.Internal.Thread
Ki.Internal.ThreadAffinity

test-suite tests
import: component
Expand Down
13 changes: 2 additions & 11 deletions ki/src/Ki/Internal/Thread.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import Control.Exception
asyncExceptionToException,
)
import GHC.Conc (STM)
import Ki.Internal.ByteCount
import Ki.Internal.ByteCount (ByteCount)
import Ki.Internal.IO (forkIO, forkOn, tryEitherSTM)
import Ki.Internal.ThreadAffinity (ThreadAffinity (..))

-- | A thread.
--
Expand Down Expand Up @@ -65,16 +66,6 @@ makeThread threadId action =
type Tid =
Int

-- | What, if anything, a thread is bound to.
data ThreadAffinity
= -- | Unbound.
Unbound
| -- | Bound to a capability.
Capability Int
| -- | Bound to an OS thread.
OsThread
deriving stock (Eq, Show)

-- forkIO/forkOn/forkOS, switching on affinity
forkWithAffinity :: ThreadAffinity -> IO () -> IO ThreadId
forkWithAffinity = \case
Expand Down
14 changes: 14 additions & 0 deletions ki/src/Ki/Internal/ThreadAffinity.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Ki.Internal.ThreadAffinity
( ThreadAffinity (..),
)
where

-- | What, if anything, a thread is bound to.
data ThreadAffinity
= -- | Unbound.
Unbound
| -- | Bound to a capability.
Capability Int
| -- | Bound to an OS thread.
OsThread
deriving stock (Eq, Show)

0 comments on commit cc554dd

Please sign in to comment.