diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-11-05 14:29:33 +0100 |
---|---|---|
committer | Sylvain Henry <sylvain@haskus.fr> | 2021-01-05 15:02:58 +0100 |
commit | 6c771aafa30e261f6822b3ddddbe66f8a55f307c (patch) | |
tree | 0db9f845e28c38d5eaf618735f9be3ab892aa7f9 /compiler/cbits | |
parent | 26a928b8fdb1b4ccb75e8edb620b8cf12cb38621 (diff) | |
download | haskell-6c771aafa30e261f6822b3ddddbe66f8a55f307c.tar.gz |
Implement Unique supply with Addr# atomic primop
Before this patch the compiler depended on the RTS way (threaded or not)
to use atomic incrementation or not. This is wrong because the RTS is
supposed to be switchable at link time, without recompilation.
Now we always use atomic incrementation of the unique counter.
Diffstat (limited to 'compiler/cbits')
-rw-r--r-- | compiler/cbits/genSym.c | 32 |
1 files changed, 5 insertions, 27 deletions
diff --git a/compiler/cbits/genSym.c b/compiler/cbits/genSym.c index ecb318d5a8..8a47d77f27 100644 --- a/compiler/cbits/genSym.c +++ b/compiler/cbits/genSym.c @@ -2,39 +2,17 @@ #include <assert.h> #include "Unique.h" -static HsInt GenSymCounter = 0; -static HsInt GenSymInc = 1; +HsInt ghc_unique_counter = 0; +HsInt ghc_unique_inc = 1; #define UNIQUE_BITS (sizeof (HsInt) * 8 - UNIQUE_TAG_BITS) #define UNIQUE_MASK ((1ULL << UNIQUE_BITS) - 1) -STATIC_INLINE void checkUniqueRange(HsInt u STG_UNUSED) { +HsInt genSym(void) { + HsInt u = atomic_inc((StgWord *)&ghc_unique_counter, ghc_unique_inc) & UNIQUE_MASK; #if DEBUG // Uh oh! We will overflow next time a unique is requested. assert(u != UNIQUE_MASK); #endif -} - -HsInt genSym(void) { -#if defined(THREADED_RTS) - if (n_capabilities == 1) { - GenSymCounter = (GenSymCounter + GenSymInc) & UNIQUE_MASK; - checkUniqueRange(GenSymCounter); - return GenSymCounter; - } else { - HsInt n = atomic_inc((StgWord *)&GenSymCounter, GenSymInc) - & UNIQUE_MASK; - checkUniqueRange(n); - return n; - } -#else - GenSymCounter = (GenSymCounter + GenSymInc) & UNIQUE_MASK; - checkUniqueRange(GenSymCounter); - return GenSymCounter; -#endif -} - -void initGenSym(HsInt NewGenSymCounter, HsInt NewGenSymInc) { - GenSymCounter = NewGenSymCounter; - GenSymInc = NewGenSymInc; + return u; } |