[commit: ghc] atomics: Eliminate atomic_inc_by and instead medofiy atomic_inc. (25ad015)

git at git.haskell.org git at git.haskell.org
Wed Aug 21 14:05:00 CEST 2013


Repository : ssh://git@git.haskell.org/ghc

On branch  : atomics
Link       : http://ghc.haskell.org/trac/ghc/changeset/25ad01533aaaf1ccf69e1b7216e66de025b8131b/ghc

>---------------------------------------------------------------

commit 25ad01533aaaf1ccf69e1b7216e66de025b8131b
Author: Ryan Newton <rrnewton at gmail.com>
Date:   Sun Aug 4 19:18:26 2013 -0400

    Eliminate atomic_inc_by and instead medofiy atomic_inc.


>---------------------------------------------------------------

25ad01533aaaf1ccf69e1b7216e66de025b8131b
 includes/stg/SMP.h |   35 ++++++++---------------------------
 rts/PrimOps.cmm    |    2 +-
 rts/Timer.c        |    2 +-
 rts/sm/GC.c        |    2 +-
 4 files changed, 11 insertions(+), 30 deletions(-)

diff --git a/includes/stg/SMP.h b/includes/stg/SMP.h
index bdcaf55..be28911 100644
--- a/includes/stg/SMP.h
+++ b/includes/stg/SMP.h
@@ -52,22 +52,13 @@ EXTERN_INLINE StgWord xchg(StgPtr p, StgWord w);
 EXTERN_INLINE StgWord cas(StgVolatilePtr p, StgWord o, StgWord n);
 
 /*
- * Atomic increment
- *
- * atomic_inc(p) {
- *   return ++(*p);
- * }
- */
-EXTERN_INLINE StgWord atomic_inc(StgVolatilePtr p);
-
-/*
  * Atomic addition by the provided quantity
  *
- * atomic_inc_by(p, n) {
+ * atomic_inc(p, n) {
  *   return ((*p) += n);
  * }
  */
-EXTERN_INLINE StgWord atomic_inc_by(StgVolatilePtr p, StgWord n);
+EXTERN_INLINE StgWord atomic_inc(StgVolatilePtr p, StgWord n);
 
 
 /*
@@ -246,9 +237,10 @@ cas(StgVolatilePtr p, StgWord o, StgWord n)
 #endif
 }
 
-// RRN: Added to enable general fetch-and-add in Haskell code (fetchAddIntArray#).
+// RRN: Generalized to arbitrary increments to enable fetch-and-add in
+// Haskell code (fetchAddIntArray#).
 EXTERN_INLINE StgWord
-atomic_inc_by(StgVolatilePtr p, StgWord incr)
+atomic_inc(StgVolatilePtr p, StgWord incr)
 {
 #if defined(i386_HOST_ARCH) || defined(x86_64_HOST_ARCH)
     StgWord r;
@@ -269,12 +261,6 @@ atomic_inc_by(StgVolatilePtr p, StgWord incr)
 }
 
 EXTERN_INLINE StgWord
-atomic_inc(StgVolatilePtr p)
-{
-  return atomic_inc_by(p, 1);
-}
-
-EXTERN_INLINE StgWord
 atomic_dec(StgVolatilePtr p)
 {
 #if defined(i386_HOST_ARCH) || defined(x86_64_HOST_ARCH)
@@ -407,14 +393,9 @@ cas(StgVolatilePtr p, StgWord o, StgWord n)
     return result;
 }
 
-INLINE_HEADER StgWord
-atomic_inc(StgVolatilePtr p)
-{
-    return ++(*p);
-}
-
-INLINE_HEADER StgWord
-atomic_inc_by(StgVolatilePtr p, StgWord incr)
+EXTERN_INLINE StgWord atomic_inc(StgVolatilePtr p, StgWord incr);
+EXTERN_INLINE StgWord
+atomic_inc(StgVolatilePtr p, StgWord incr)
 {
     return ((*p) += incr);
 }
diff --git a/rts/PrimOps.cmm b/rts/PrimOps.cmm
index b7177ca..a07c1de 100644
--- a/rts/PrimOps.cmm
+++ b/rts/PrimOps.cmm
@@ -157,7 +157,7 @@ stg_fetchAddIntArrayzh( gcptr arr, W_ ind, W_ incr )
     gcptr p, h;
 
     p = arr + SIZEOF_StgArrWords + WDS(ind);
-    (h) = ccall atomic_inc_by(p, incr);
+    (h) = ccall atomic_inc(p, incr);
 
     return(h);
 }
diff --git a/rts/Timer.c b/rts/Timer.c
index aa4b8d8..b7762f9 100644
--- a/rts/Timer.c
+++ b/rts/Timer.c
@@ -119,7 +119,7 @@ startTimer(void)
 void
 stopTimer(void)
 {
-    if (atomic_inc(&timer_disabled) == 1) {
+    if (atomic_inc(&timer_disabled, 1) == 1) {
         if (RtsFlags.MiscFlags.tickInterval != 0) {
             stopTicker();
         }
diff --git a/rts/sm/GC.c b/rts/sm/GC.c
index 28593f5..d044628 100644
--- a/rts/sm/GC.c
+++ b/rts/sm/GC.c
@@ -919,7 +919,7 @@ static StgWord
 inc_running (void)
 {
     StgWord new;
-    new = atomic_inc(&gc_running_threads);
+    new = atomic_inc(&gc_running_threads, 1);
     ASSERT(new <= n_gc_threads);
     return new;
 }





More information about the ghc-commits mailing list