Eq and Ord instances for ThreadId.
/* -----------------------------------------------------------------------------
- * $Id: PrimOps.h,v 1.35 1999/08/24 09:36:41 simonmar Exp $
+ * $Id: PrimOps.h,v 1.36 1999/08/25 10:23:51 simonmar Exp $
*
* (c) The GHC Team, 1998-1999
*
#define myThreadIdzh(t) (t = CurrentTSO)
+extern int cmp_thread(const StgTSO *tso1, const StgTSO *tso2);
+
/* Hmm, I'll think about these later. */
/* -----------------------------------------------------------------------------
Pointer equality
import PrelPack ( packString )
import PrelIOBase ( unsafePerformIO , unsafeInterleaveIO )
import PrelBase ( fork# )
+import PrelGHC ( Addr#, unsafeCoerce# )
infixr 0 `fork`
\end{code}
+Thread Ids, specifically the instances of Eq and Ord for these things.
+The ThreadId type itself is defined in std/PrelConc.lhs.
+
+Rather than define a new primitve, we use a little helper function
+cmp_thread in the RTS.
+
+\begin{code}
+foreign import ccall "cmp_thread" unsafe cmp_thread :: Addr# -> Addr# -> Int
+-- Returns -1, 0, 1
+
+cmpThread :: ThreadId -> ThreadId -> Ordering
+cmpThread (ThreadId t1) (ThreadId t2) =
+ case cmp_thread (unsafeCoerce# t1) (unsafeCoerce# t2) of
+ -1 -> LT
+ 0 -> EQ
+ 1 -> GT
+
+instance Eq ThreadId where
+ t1 == t2 =
+ case t1 `cmpThread` t2 of
+ EQ -> True
+ _ -> False
+
+instance Ord ThreadId where
+ compare = cmpThread
+\end{code}
+
\begin{code}
forkIO :: IO () -> IO ThreadId
forkIO action = IO $ \ s ->
/* -----------------------------------------------------------------------------
- * $Id: Schedule.c,v 1.22 1999/06/25 09:17:58 simonmar Exp $
+ * $Id: Schedule.c,v 1.23 1999/08/25 10:23:53 simonmar Exp $
*
* (c) The GHC Team, 1998-1999
*
static void unblockThread(StgTSO *tso);
/* -----------------------------------------------------------------------------
+ * Comparing Thread ids.
+ *
+ * This is used from STG land in the implementation of the
+ * instances of Eq/Ord for ThreadIds.
+ * -------------------------------------------------------------------------- */
+
+int cmp_thread(const StgTSO *tso1, const StgTSO *tso2)
+{
+ StgThreadID id1 = tso1->id;
+ StgThreadID id2 = tso2->id;
+
+ if (id1 < id2) return (-1);
+ if (id1 > id2) return 1;
+ return 0;
+}
+
+/* -----------------------------------------------------------------------------
Create a new thread.
The new thread starts with the given stack size. Before the