import pthread_mutex_lock;
import pthread_mutex_unlock;
#endif
-import base_ControlziException_nestedAtomically_closure;
+import base_ControlziExceptionziBase_nestedAtomically_closure;
import EnterCriticalSection;
import LeaveCriticalSection;
+import ghczmprim_GHCziBool_False_closure;
/*-----------------------------------------------------------------------------
Array Primitives
atomicModifyMutVarzh_fast
{
- W_ mv, z, x, y, r;
+ W_ mv, f, z, x, y, r, h;
/* Args: R1 :: MutVar#, R2 :: a -> (a,b) */
/* If x is the current contents of the MutVar#, then
HP_CHK_GEN_TICKY(SIZE, R1_PTR & R2_PTR, atomicModifyMutVarzh_fast);
-#if defined(THREADED_RTS)
- ACQUIRE_LOCK(atomic_modify_mutvar_mutex "ptr") [R1,R2];
-#endif
-
- x = StgMutVar_var(R1);
+ mv = R1;
+ f = R2;
TICK_ALLOC_THUNK_2();
CCCS_ALLOC(THUNK_2_SIZE);
z = Hp - THUNK_2_SIZE + WDS(1);
SET_HDR(z, stg_ap_2_upd_info, W_[CCCS]);
LDV_RECORD_CREATE(z);
- StgThunk_payload(z,0) = R2;
- StgThunk_payload(z,1) = x;
+ StgThunk_payload(z,0) = f;
TICK_ALLOC_THUNK_1();
CCCS_ALLOC(THUNK_1_SIZE);
LDV_RECORD_CREATE(y);
StgThunk_payload(y,0) = z;
- StgMutVar_var(R1) = y;
- foreign "C" dirty_MUT_VAR(BaseReg "ptr", R1 "ptr") [R1];
-
TICK_ALLOC_THUNK_1();
CCCS_ALLOC(THUNK_1_SIZE);
r = y - THUNK_1_SIZE;
LDV_RECORD_CREATE(r);
StgThunk_payload(r,0) = z;
-#if defined(THREADED_RTS)
- RELEASE_LOCK(atomic_modify_mutvar_mutex "ptr") [];
+ retry:
+ x = StgMutVar_var(mv);
+ StgThunk_payload(z,1) = x;
+#ifdef THREADED_RTS
+ (h) = foreign "C" cas(mv + SIZEOF_StgHeader + OFFSET_StgMutVar_var, x, y) [];
+ if (h != x) { goto retry; }
+#else
+ StgMutVar_var(mv) = y;
#endif
+ if (GET_INFO(mv) == stg_MUT_VAR_CLEAN_info) {
+ foreign "C" dirty_MUT_VAR(BaseReg "ptr", mv "ptr") [];
+ }
+
RET_P(r);
}
foreign "C" scheduleThread(MyCapability() "ptr", threadid "ptr") [];
// switch at the earliest opportunity
- CInt[context_switch] = 1 :: CInt;
+ Capability_context_switch(MyCapability()) = 1 :: CInt;
RET_P(threadid);
}
foreign "C" scheduleThreadOn(MyCapability() "ptr", cpu, threadid "ptr") [];
// switch at the earliest opportunity
- CInt[context_switch] = 1 :: CInt;
+ Capability_context_switch(MyCapability()) = 1 :: CInt;
RET_P(threadid);
}
#if defined(PROFILING)
W_ unused1, W_ unused2,
#endif
- W_ unused3, "ptr" W_ unused4, "ptr" W_ unused5)
+ W_ unused3, P_ unused4, P_ unused5)
{
W_ r, frame, trec, outer;
#if defined(PROFILING)
W_ unused1, W_ unused2,
#endif
- "ptr" W_ unused3, "ptr" W_ unused4)
+ P_ unused3, P_ unused4)
{
W_ frame, trec, valid, next_invariant, q, outer;
#if defined(PROFILING)
W_ unused1, W_ unused2,
#endif
- "ptr" W_ unused3, "ptr" W_ unused4)
+ P_ unused3, P_ unused4)
{
W_ frame, trec, valid;
#if defined(PROFILING)
W_ unused1, W_ unused2,
#endif
- "ptr" W_ unused3, "ptr" W_ unused4)
+ P_ unused3, P_ unused4)
{
W_ r, frame, trec, outer;
frame = Sp;
/* Nested transactions are not allowed; raise an exception */
if (old_trec != NO_TREC) {
- R1 = base_ControlziException_nestedAtomically_closure;
+ R1 = base_ControlziExceptionziBase_nestedAtomically_closure;
jump raisezh_fast;
}
RET_P(result);
}
+readTVarIOzh_fast
+{
+ W_ result;
+
+again:
+ result = StgTVar_current_value(R1);
+ if (%INFO_PTR(result) == stg_TREC_HEADER_info) {
+ goto again;
+ }
+ RET_P(result);
+}
writeTVarzh_fast
{
}
RET_NP(ok,val);
}
+
+getSparkzh_fast
+{
+ W_ spark;
+
+#ifndef THREADED_RTS
+ RET_NP(0,ghczmprim_GHCziBool_False_closure);
+#else
+ (spark) = foreign "C" findSpark(MyCapability());
+ if (spark != 0) {
+ RET_NP(1,spark);
+ } else {
+ RET_NP(0,ghczmprim_GHCziBool_False_closure);
+ }
+#endif
+}