Commit db8d4a34 authored by Edward Z. Yang's avatar Edward Z. Yang

Implement tryAtomicReadMVar#.

Signed-off-by: Edward Z. Yang's avatarEdward Z. Yang <ezyang@mit.edu>
parent 190d34a6
......@@ -1726,6 +1726,14 @@ primop AtomicReadMVarOp "atomicReadMVar#" GenPrimOp
out_of_line = True
has_side_effects = True
primop TryAtomicReadMVarOp "tryAtomicReadMVar#" GenPrimOp
MVar# s a -> State# s -> (# State# s, Int#, a #)
{If {\tt MVar\#} is empty, immediately return with integer 0 and value undefined.
Otherwise, return wtih integer 1 and contents of {\tt MVar\#}.}
with
out_of_line = True
has_side_effects = True
primop SameMVarOp "sameMVar#" GenPrimOp
MVar# s a -> MVar# s a -> Bool
......
......@@ -381,6 +381,7 @@ RTS_FUN_DECL(stg_putMVarzh);
RTS_FUN_DECL(stg_atomicReadMVarzh);
RTS_FUN_DECL(stg_tryTakeMVarzh);
RTS_FUN_DECL(stg_tryPutMVarzh);
RTS_FUN_DECL(stg_tryAtomicReadMVarzh);
RTS_FUN_DECL(stg_waitReadzh);
RTS_FUN_DECL(stg_waitWritezh);
......
......@@ -1319,6 +1319,7 @@ typedef struct _RtsSymbolVal {
SymI_HasProto(stg_threadStatuszh) \
SymI_HasProto(stg_tryPutMVarzh) \
SymI_HasProto(stg_tryTakeMVarzh) \
SymI_HasProto(stg_tryAtomicReadMVarzh) \
SymI_HasProto(stg_unmaskAsyncExceptionszh) \
SymI_HasProto(unloadObj) \
SymI_HasProto(stg_unsafeThawArrayzh) \
......
......@@ -1567,6 +1567,22 @@ stg_atomicReadMVarzh ( P_ mvar, /* :: MVar a */ )
return (val);
}
stg_tryAtomicReadMVarzh ( P_ mvar, /* :: MVar a */ )
{
W_ val, info, tso, q;
LOCK_CLOSURE(mvar, info);
if (StgMVar_value(mvar) == stg_END_TSO_QUEUE_closure) {
return (0, stg_NO_FINALIZER_closure);
}
val = StgMVar_value(mvar);
unlockClosure(mvar, stg_MVAR_DIRTY_info);
return (1, val);
}
/* -----------------------------------------------------------------------------
Stable pointer primitives
------------------------------------------------------------------------- */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment