Skip to content

Commit

Permalink
add casMutVar#
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmar committed Apr 11, 2011
1 parent 169dadd commit 521b792
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions compiler/prelude/primops.txt.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions includes/stg/MiscClosures.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion includes/stg/SMP.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions rts/Linker.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
19 changes: 19 additions & 0 deletions rts/PrimOps.cmm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 521b792

Please sign in to comment.