From cc554dd7dc9942f3d887b2e31f692c90df1ca637 Mon Sep 17 00:00:00 2001 From: Mitchell Rosen Date: Mon, 27 Nov 2023 21:33:23 -0500 Subject: [PATCH] move ThreadAffinity into its own module --- .gitignore | 1 + ki/ki.cabal | 1 + ki/src/Ki/Internal/Thread.hs | 13 ++----------- ki/src/Ki/Internal/ThreadAffinity.hs | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 ki/src/Ki/Internal/ThreadAffinity.hs diff --git a/.gitignore b/.gitignore index fb87c15..f4991b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .envrc .ghc.environment.* .ghcid +Session.vim dist-newstyle/ diff --git a/ki/ki.cabal b/ki/ki.cabal index 2ed6cd1..9339db8 100644 --- a/ki/ki.cabal +++ b/ki/ki.cabal @@ -93,6 +93,7 @@ library Ki.Internal.NonblockingSTM Ki.Internal.Scope Ki.Internal.Thread + Ki.Internal.ThreadAffinity test-suite tests import: component diff --git a/ki/src/Ki/Internal/Thread.hs b/ki/src/Ki/Internal/Thread.hs index 7b4b5fd..4d82eb0 100644 --- a/ki/src/Ki/Internal/Thread.hs +++ b/ki/src/Ki/Internal/Thread.hs @@ -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 diff --git a/ki/src/Ki/Internal/ThreadAffinity.hs b/ki/src/Ki/Internal/ThreadAffinity.hs new file mode 100644 index 0000000..fb0e19e --- /dev/null +++ b/ki/src/Ki/Internal/ThreadAffinity.hs @@ -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)