Permalink
Browse files

add casMutVar#

  • Loading branch information...
1 parent 169dadd commit 521b792553bacbdb0eec138b150ab0626ea6f36b @simonmar simonmar committed Feb 15, 2011
Showing with 29 additions and 1 deletion.
  1. +6 −0 compiler/prelude/primops.txt.pp
  2. +1 −0 includes/stg/MiscClosures.h
  3. +2 −1 includes/stg/SMP.h
  4. +1 −0 rts/Linker.c
  5. +19 −0 rts/PrimOps.cmm
@@ -1121,6 +1121,12 @@
out_of_line = True
has_side_effects = True
+primop CasMutVarOp "casMutVar#" GenPrimOp
+ MutVar# s a -> a -> a -> State# s -> (# State# s, Int#, a #)
+ with
+ out_of_line = True
+ has_side_effects = True
+
------------------------------------------------------------------------
section "Exceptions"
------------------------------------------------------------------------
@@ -383,6 +383,7 @@ RTS_FUN_DECL(stg_newArrayzh);
RTS_FUN_DECL(stg_newMutVarzh);
RTS_FUN_DECL(stg_atomicModifyMutVarzh);
+RTS_FUN_DECL(stg_casMutVarzh);
RTS_FUN_DECL(stg_isEmptyMVarzh);
RTS_FUN_DECL(stg_newMVarzh);
View
@@ -314,7 +314,8 @@ xchg(StgPtr p, StgWord w)
return old;
}
-STATIC_INLINE StgWord
+EXTERN_INLINE StgWord cas(StgVolatilePtr p, StgWord o, StgWord n);
+EXTERN_INLINE StgWord
cas(StgVolatilePtr p, StgWord o, StgWord n)
{
StgWord result;
View
@@ -832,6 +832,7 @@ typedef struct _RtsSymbolVal {
SymI_HasProto(stg_newTVarzh) \
SymI_HasProto(stg_noDuplicatezh) \
SymI_HasProto(stg_atomicModifyMutVarzh) \
+ SymI_HasProto(stg_casMutVarzh) \
SymI_HasProto(stg_newPinnedByteArrayzh) \
SymI_HasProto(stg_newAlignedPinnedByteArrayzh) \
SymI_HasProto(newSpark) \
View
@@ -230,6 +230,25 @@ stg_newMutVarzh
RET_P(mv);
}
+stg_casMutVarzh
+ /* MutVar# s a -> a -> a -> State# s -> (# State#, Int#, a #) */
+{
+ W_ mv, old, new, h;
+
+ mv = R1;
+ old = R2;
+ new = R3;
+
+ (h) = foreign "C" cas(mv + SIZEOF_StgHeader + OFFSET_StgMutVar_var,
+ old, new) [];
+ if (h != old) {
+ RET_NP(1,h);
+ } else {
+ RET_NP(0,h);
+ }
+}
+
+
stg_atomicModifyMutVarzh
{
W_ mv, f, z, x, y, r, h;

0 comments on commit 521b792

Please sign in to comment.