diff options
author | Roland Zumkeller <Roland.Zumkeller@gmail.com> | 2019-06-22 19:35:07 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-11-19 20:39:19 -0500 |
commit | d1f3c63701b7f0fd675f792af7f33c5b11eaff83 (patch) | |
tree | 077460cd5f8cf6525908c08cc4a6f4e3ade441a6 /rts | |
parent | e57b7cc6d8b1222e0939d19c265b51d2c3c2b4c0 (diff) | |
download | haskell-d1f3c63701b7f0fd675f792af7f33c5b11eaff83.tar.gz |
Use pointer equality in Eq/Ord for ThreadId
Changes (==) to use only pointer equality. This is safe because two
threads are the same iff they have the same id.
Changes `compare` to check pointer equality first and fall back on ids
only in case of inequality.
See discussion in #16761.
Diffstat (limited to 'rts')
-rw-r--r-- | rts/RtsSymbols.c | 1 | ||||
-rw-r--r-- | rts/Threads.c | 25 |
2 files changed, 21 insertions, 5 deletions
diff --git a/rts/RtsSymbols.c b/rts/RtsSymbols.c index b2f90a892d..aef49606b3 100644 --- a/rts/RtsSymbols.c +++ b/rts/RtsSymbols.c @@ -606,6 +606,7 @@ SymI_HasProto(stg_compactFixupPointerszh) \ SymI_HasProto(stg_compactSizzezh) \ SymI_HasProto(closure_flags) \ + SymI_HasProto(eq_thread) \ SymI_HasProto(cmp_thread) \ SymI_HasProto(createAdjustor) \ SymI_HasProto(stg_decodeDoublezu2Intzh) \ diff --git a/rts/Threads.c b/rts/Threads.c index cce32ca2b3..22d58bb48b 100644 --- a/rts/Threads.c +++ b/rts/Threads.c @@ -139,21 +139,36 @@ createThread(Capability *cap, W_ size) } /* --------------------------------------------------------------------------- + * Equality on Thread ids. + * + * This is used from STG land in the implementation of the Eq instance + * for ThreadIds. + * ------------------------------------------------------------------------ */ + +bool +eq_thread(StgPtr tso1, StgPtr tso2) +{ + return tso1 == tso2; +} + +/* --------------------------------------------------------------------------- * Comparing Thread ids. * - * This is used from STG land in the implementation of the - * instances of Eq/Ord for ThreadIds. + * This is used from STG land in the implementation of the Ord instance + * for ThreadIds. * ------------------------------------------------------------------------ */ int cmp_thread(StgPtr tso1, StgPtr tso2) { + if (tso1 == tso2) return 0; + StgThreadID id1 = ((StgTSO *)tso1)->id; StgThreadID id2 = ((StgTSO *)tso2)->id; - if (id1 < id2) return (-1); - if (id1 > id2) return 1; - return 0; + ASSERT(id1 != id2); + + return id1 < id2 ? -1 : 1; } /* --------------------------------------------------------------------------- |