move ThreadAffinity into its own module

This commit is contained in:
Mitchell Rosen 2023-11-27 21:33:23 -05:00
parent 30d26f47ac
commit cc554dd7dc
4 changed files with 18 additions and 11 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.envrc
.ghc.environment.*
.ghcid
Session.vim
dist-newstyle/

View File

@ -93,6 +93,7 @@ library
Ki.Internal.NonblockingSTM
Ki.Internal.Scope
Ki.Internal.Thread
Ki.Internal.ThreadAffinity
test-suite tests
import: component

View File

@ -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.
--
@ -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

View File

@ -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)