Skip to content

Instantly share code, notes, and snippets.

@TerrorJack
Created April 14, 2023 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TerrorJack/e3f1231fa65b3d1f5ea63065dd33a87f to your computer and use it in GitHub Desktop.
Save TerrorJack/e3f1231fa65b3d1f5ea63065dd33a87f to your computer and use it in GitHub Desktop.
diff --git a/MutInt.cmm b/MutInt.cmm
index 0c3a209..1a77424 100644
--- a/MutInt.cmm
+++ b/MutInt.cmm
@@ -4,14 +4,13 @@
INFO_TABLE(stg_Counter, 0, 1, PRIM, "Counter", "Counter") ()
{
- return ();
+ foreign "C" barf("stg_Counter entered!", NULL) never returns;
}
stg_newCounterzh (W_ x)
{
P_ c;
- ALLOC_PRIM_ (SIZEOF_StgCounter, stg_newCounterzh);
- c = Hp - SIZEOF_StgCounter + WDS(1);
+ ("ptr" c) = ccall allocate(MyCapability() "ptr", BYTES_TO_WDS(SIZEOF_StgCounter));
SET_HDR(c, stg_Counter_info, CCCS);
W_[c + SIZEOF_StgHeader] = x;
return (c);
diff --git a/src/Control/Concurrent/Counter/Unlifted.hs b/src/Control/Concurrent/Counter/Unlifted.hs
index 7e85ad8..d416a6b 100644
--- a/src/Control/Concurrent/Counter/Unlifted.hs
+++ b/src/Control/Concurrent/Counter/Unlifted.hs
@@ -18,6 +18,7 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE GHCForeignImportPrim #-}
+{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UnliftedFFITypes #-}
@@ -61,7 +62,7 @@ import GHC.Exts
#ifdef USE_CMM
-- | Memory location that supports select few atomic operations.
-newtype Counter s = Counter Any
+newtype Counter s = Counter (Any :: UnliftedType)
{-# INLINE sub #-}
-- | Atomically subtract an amount from the counter and return its old value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment