W_ mv, z, x, y, r;
/* Args: R1 :: MutVar#, R2 :: a -> (a,b) */
-#if defined(SMP)
- foreign "C" ACQUIRE_LOCK(sm_mutex "ptr");
-#endif
-
/* If x is the current contents of the MutVar#, then
We want to make the new contents point to
HP_CHK_GEN_TICKY(SIZE, R1_PTR & R2_PTR, atomicModifyMutVarzh_fast);
+#if defined(SMP)
+ foreign "C" ACQUIRE_LOCK(sm_mutex "ptr");
+#endif
+
x = StgMutVar_var(R1);
TICK_ALLOC_THUNK_2();
StgWeak_link(w) = W_[weak_ptr_list];
W_[weak_ptr_list] = w;
- IF_DEBUG(weak, foreign "C" fprintf(W_[stderr] "ptr",stg_weak_msg,w));
+ IF_DEBUG(weak, foreign "C" debugBelch(stg_weak_msg,w));
RET_P(w);
}
{
W_ mvar, val, info, tso;
+#if defined(SMP)
+ foreign "C" ACQUIRE_LOCK(sm_mutex "ptr");
+#endif
+
/* args: R1 = MVar closure */
mvar = R1;
StgTSO_block_info(CurrentTSO) = mvar;
StgMVar_tail(mvar) = CurrentTSO;
+#if defined(SMP)
+ foreign "C" RELEASE_LOCK(sm_mutex "ptr");
+#endif
+
jump stg_block_takemvar;
}
if (StgMVar_head(mvar) == stg_END_TSO_QUEUE_closure) {
StgMVar_tail(mvar) = stg_END_TSO_QUEUE_closure;
}
+
+#if defined(SMP)
+ foreign "C" RELEASE_LOCK(sm_mutex "ptr");
+#endif
+
RET_P(val);
}
else
*/
SET_INFO(mvar,stg_EMPTY_MVAR_info);
StgMVar_value(mvar) = stg_END_TSO_QUEUE_closure;
+
+#if defined(SMP)
+ foreign "C" RELEASE_LOCK(sm_mutex "ptr");
+#endif
+
RET_P(val);
}
}
{
W_ mvar, val, info, tso;
+#if defined(SMP)
+ foreign "C" ACQUIRE_LOCK(sm_mutex "ptr");
+#endif
+
/* args: R1 = MVar closure */
mvar = R1;
/* HACK: we need a pointer to pass back,
* so we abuse NO_FINALIZER_closure
*/
+#if defined(SMP)
+ foreign "C" RELEASE_LOCK(sm_mutex "ptr");
+#endif
RET_NP(0, stg_NO_FINALIZER_closure);
}
{
/* No further putMVars, MVar is now empty */
StgMVar_value(mvar) = stg_END_TSO_QUEUE_closure;
-
- /* do this last... we might have locked the MVar in the SMP case,
- * and writing the info pointer will unlock it.
- */
SET_INFO(mvar,stg_EMPTY_MVAR_info);
}
+#if defined(SMP)
+ foreign "C" RELEASE_LOCK(sm_mutex "ptr");
+#endif
+
RET_NP(1, val);
}
{
W_ mvar, info, tso;
+#if defined(SMP)
+ foreign "C" ACQUIRE_LOCK(sm_mutex "ptr");
+#endif
+
/* args: R1 = MVar, R2 = value */
mvar = R1;
StgTSO_block_info(CurrentTSO) = mvar;
StgMVar_tail(mvar) = CurrentTSO;
+#if defined(SMP)
+ foreign "C" RELEASE_LOCK(sm_mutex "ptr");
+#endif
jump stg_block_putmvar;
}
StgMVar_tail(mvar) = stg_END_TSO_QUEUE_closure;
}
+#if defined(SMP)
+ foreign "C" RELEASE_LOCK(sm_mutex "ptr");
+#endif
jump %ENTRY_CODE(Sp(0));
}
else
StgMVar_value(mvar) = R2;
/* unlocks the MVar in the SMP case */
SET_INFO(mvar,stg_FULL_MVAR_info);
+
+#if defined(SMP)
+ foreign "C" RELEASE_LOCK(sm_mutex "ptr");
+#endif
jump %ENTRY_CODE(Sp(0));
}
{
W_ mvar, info, tso;
+#if defined(SMP)
+ foreign "C" ACQUIRE_LOCK(sm_mutex "ptr");
+#endif
+
/* args: R1 = MVar, R2 = value */
mvar = R1;
info = GET_INFO(mvar);
if (info == stg_FULL_MVAR_info) {
+#if defined(SMP)
+ foreign "C" RELEASE_LOCK(sm_mutex "ptr");
+#endif
RET_N(0);
}
StgMVar_tail(mvar) = stg_END_TSO_QUEUE_closure;
}
+#if defined(SMP)
+ foreign "C" RELEASE_LOCK(sm_mutex "ptr");
+#endif
jump %ENTRY_CODE(Sp(0));
}
else
StgMVar_value(mvar) = R2;
/* unlocks the MVar in the SMP case */
SET_INFO(mvar,stg_FULL_MVAR_info);
+#if defined(SMP)
+ foreign "C" RELEASE_LOCK(sm_mutex "ptr");
+#endif
jump %ENTRY_CODE(Sp(0));
}