@@ -26,7 +26,7 @@ module Control.Monad.IOSim.Internal
26
26
, TimeoutException (.. )
27
27
, EventlogEvent (.. )
28
28
, EventlogMarker (.. )
29
- , ThreadId
29
+ , IOSimThreadId
30
30
, ThreadLabel
31
31
, Labelled (.. )
32
32
, SimTrace
@@ -83,12 +83,12 @@ import Control.Monad.IOSim.Types (SimEvent)
83
83
--
84
84
85
85
data Thread s a = Thread {
86
- threadId :: ! ThreadId ,
86
+ threadId :: ! IOSimThreadId ,
87
87
threadControl :: ! (ThreadControl s a ),
88
88
threadStatus :: ! ThreadStatus ,
89
89
threadMasking :: ! MaskingState ,
90
90
-- other threads blocked in a ThrowTo to us because we are or were masked
91
- threadThrowTo :: ! [(SomeException , Labelled ThreadId )],
91
+ threadThrowTo :: ! [(SomeException , Labelled IOSimThreadId )],
92
92
threadClockId :: ! ClockId ,
93
93
threadLabel :: Maybe ThreadLabel ,
94
94
threadNextTId :: ! Int
@@ -102,7 +102,7 @@ isThreadBlocked t = case threadStatus t of
102
102
labelledTVarId :: TVar s a -> ST s (Labelled TVarId )
103
103
labelledTVarId TVar { tvarId, tvarLabel } = (Labelled tvarId) <$> readSTRef tvarLabel
104
104
105
- labelledThreads :: Map ThreadId (Thread s a ) -> [Labelled ThreadId ]
105
+ labelledThreads :: Map IOSimThreadId (Thread s a ) -> [Labelled IOSimThreadId ]
106
106
labelledThreads threadMap =
107
107
-- @Map.foldr'@ (and alikes) are not strict enough, to not ratain the
108
108
-- original thread map we need to evaluate the spine of the list.
@@ -121,11 +121,11 @@ data TimerCompletionInfo s =
121
121
-- ^ `newTimeout` timer.
122
122
| TimerRegisterDelay ! (TVar s Bool )
123
123
-- ^ `registerDelay` timer.
124
- | TimerThreadDelay ! ThreadId ! TimeoutId
125
- -- ^ `threadDelay` timer run by `ThreadId ` which was assigned the given
124
+ | TimerThreadDelay ! IOSimThreadId ! TimeoutId
125
+ -- ^ `threadDelay` timer run by `IOSimThreadId ` which was assigned the given
126
126
-- `TimeoutId` (only used to report in a trace).
127
- | TimerTimeout ! ThreadId ! TimeoutId ! (TMVar (IOSim s ) ThreadId )
128
- -- ^ `timeout` timer run by `ThreadId ` which was assigned the given
127
+ | TimerTimeout ! IOSimThreadId ! TimeoutId ! (TMVar (IOSim s ) IOSimThreadId )
128
+ -- ^ `timeout` timer run by `IOSimThreadId ` which was assigned the given
129
129
-- `TimeoutId` (only used to report in a trace).
130
130
131
131
@@ -134,10 +134,10 @@ type Timeouts s = OrdPSQ TimeoutId Time (TimerCompletionInfo s)
134
134
-- | Internal state.
135
135
--
136
136
data SimState s a = SimState {
137
- runqueue :: ! (Deque ThreadId ),
137
+ runqueue :: ! (Deque IOSimThreadId ),
138
138
-- | All threads other than the currently running thread: both running
139
139
-- and blocked threads.
140
- threads :: ! (Map ThreadId (Thread s a )),
140
+ threads :: ! (Map IOSimThreadId (Thread s a )),
141
141
-- | current time
142
142
curTime :: ! Time ,
143
143
-- | ordered list of timers and timeouts
@@ -821,7 +821,7 @@ reschedule !simstate@SimState{ threads, timers, curTime = time } =
821
821
timeoutSTMAction TimerThreadDelay {} = return ()
822
822
timeoutSTMAction TimerTimeout {} = return ()
823
823
824
- unblockThreads :: Bool -> [ThreadId ] -> SimState s a -> ([ThreadId ], SimState s a )
824
+ unblockThreads :: Bool -> [IOSimThreadId ] -> SimState s a -> ([IOSimThreadId ], SimState s a )
825
825
unblockThreads ! onlySTM ! wakeup ! simstate@ SimState {runqueue, threads} =
826
826
-- To preserve our invariants (that threadBlocked is correct)
827
827
-- we update the runqueue and threads together here
@@ -863,7 +863,7 @@ unblockThreads !onlySTM !wakeup !simstate@SimState {runqueue, threads} =
863
863
-- receive a 'ThreadKilled' exception.
864
864
--
865
865
forkTimeoutInterruptThreads :: forall s a .
866
- [(ThreadId , TimeoutId , TMVar (IOSim s ) ThreadId )]
866
+ [(IOSimThreadId , TimeoutId , TMVar (IOSim s ) IOSimThreadId )]
867
867
-> SimState s a
868
868
-> ST s (SimState s a )
869
869
forkTimeoutInterruptThreads timeoutExpired simState =
@@ -883,13 +883,13 @@ forkTimeoutInterruptThreads timeoutExpired simState =
883
883
where
884
884
-- we launch a thread responsible for throwing an AsyncCancelled exception
885
885
-- to the thread which timeout expired
886
- throwToThread :: [(Thread s a , TMVar (IOSim s ) ThreadId )]
886
+ throwToThread :: [(Thread s a , TMVar (IOSim s ) IOSimThreadId )]
887
887
888
888
(simState', throwToThread) = List. mapAccumR fn simState timeoutExpired
889
889
where
890
890
fn :: SimState s a
891
- -> (ThreadId , TimeoutId , TMVar (IOSim s ) ThreadId )
892
- -> (SimState s a , (Thread s a , TMVar (IOSim s ) ThreadId ))
891
+ -> (IOSimThreadId , TimeoutId , TMVar (IOSim s ) IOSimThreadId )
892
+ -> (SimState s a , (Thread s a , TMVar (IOSim s ) IOSimThreadId ))
893
893
fn state@ SimState { threads } (tid, tmid, lock) =
894
894
let t = case tid `Map.lookup` threads of
895
895
Just t' -> t'
@@ -1003,13 +1003,13 @@ removeMinimums = \psq ->
1003
1003
| p == p' -> collectAll (k: ks) p (x: xs) psq'
1004
1004
_ -> (reverse ks, p, reverse xs, psq)
1005
1005
1006
- traceMany :: [(Time , ThreadId , Maybe ThreadLabel , SimEventType )]
1006
+ traceMany :: [(Time , IOSimThreadId , Maybe ThreadLabel , SimEventType )]
1007
1007
-> SimTrace a -> SimTrace a
1008
1008
traceMany [] trace = trace
1009
1009
traceMany ((time, tid, tlbl, event): ts) trace =
1010
1010
SimTrace time tid tlbl event (traceMany ts trace)
1011
1011
1012
- lookupThreadLabel :: ThreadId -> Map ThreadId (Thread s a ) -> Maybe ThreadLabel
1012
+ lookupThreadLabel :: IOSimThreadId -> Map IOSimThreadId (Thread s a ) -> Maybe ThreadLabel
1013
1013
lookupThreadLabel tid threads = join (threadLabel <$> Map. lookup tid threads)
1014
1014
1015
1015
@@ -1041,7 +1041,7 @@ runSimTraceST mainAction = schedule mainThread initialState
1041
1041
1042
1042
execAtomically :: forall s a c .
1043
1043
Time
1044
- -> ThreadId
1044
+ -> IOSimThreadId
1045
1045
-> Maybe ThreadLabel
1046
1046
-> TVarId
1047
1047
-> StmA s a
@@ -1341,10 +1341,10 @@ traceTVarST TVar{tvarCurrent, tvarUndo, tvarTrace} new = do
1341
1341
-- Blocking and unblocking on TVars
1342
1342
--
1343
1343
1344
- readTVarBlockedThreads :: TVar s a -> ST s [ThreadId ]
1344
+ readTVarBlockedThreads :: TVar s a -> ST s [IOSimThreadId ]
1345
1345
readTVarBlockedThreads TVar {tvarBlocked} = fst <$> readSTRef tvarBlocked
1346
1346
1347
- blockThreadOnTVar :: ThreadId -> TVar s a -> ST s ()
1347
+ blockThreadOnTVar :: IOSimThreadId -> TVar s a -> ST s ()
1348
1348
blockThreadOnTVar tid TVar {tvarBlocked} = do
1349
1349
(tids, tidsSet) <- readSTRef tvarBlocked
1350
1350
when (tid `Set.notMember` tidsSet) $ do
@@ -1365,7 +1365,7 @@ unblockAllThreadsFromTVar TVar{tvarBlocked} = do
1365
1365
-- the var writes that woke them.
1366
1366
--
1367
1367
threadsUnblockedByWrites :: [SomeTVar s ]
1368
- -> ST s ([ThreadId ], Map ThreadId (Set (Labelled TVarId )))
1368
+ -> ST s ([IOSimThreadId ], Map IOSimThreadId (Set (Labelled TVarId )))
1369
1369
threadsUnblockedByWrites written = do
1370
1370
! tidss <- sequence
1371
1371
[ (,) <$> labelledTVarId tvar <*> readTVarBlockedThreads tvar
0 commit comments