[project @ 2000-08-21 15:27:18 by simonmar]
[ghc-hetmet.git] / ghc / rts / PrimOps.hc
index 27f6f84..015e34a 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: PrimOps.hc,v 1.50 2000/04/11 20:44:19 panne Exp $
+ * $Id: PrimOps.hc,v 1.53 2000/08/07 23:37:23 qrczak Exp $
  *
  * (c) The GHC Team, 1998-2000
  *
@@ -263,13 +263,14 @@ W_ GHC_ZCCReturnable_static_info[0];
    FE_                                                 \
  }
 
-newByteArray(Char,   sizeof(C_))
-newByteArray(Int,    sizeof(I_));
-newByteArray(Word,   sizeof(W_));
-newByteArray(Addr,   sizeof(P_));
-newByteArray(Float,  sizeof(StgFloat));
-newByteArray(Double, sizeof(StgDouble));
-newByteArray(StablePtr, sizeof(StgStablePtr));
+newByteArray(Char,   1)
+/* Char arrays really contain only 8-bit bytes for compatibility. */
+newByteArray(Int,    sizeof(I_))
+newByteArray(Word,   sizeof(W_))
+newByteArray(Addr,   sizeof(P_))
+newByteArray(Float,  sizeof(StgFloat))
+newByteArray(Double, sizeof(StgDouble))
+newByteArray(StablePtr, sizeof(StgStablePtr))
 
 FN_(newArrayzh_fast)
 {
@@ -888,6 +889,47 @@ FN_(takeMVarzh_fast)
   FE_
 }
 
+FN_(tryTakeMVarzh_fast)
+{
+  StgMVar *mvar;
+  StgClosure *val;
+  const StgInfoTable *info;
+
+  FB_
+  /* args: R1 = MVar closure */
+
+  mvar = (StgMVar *)R1.p;
+
+#ifdef SMP
+  info = LOCK_CLOSURE(mvar);
+#else
+  info = GET_INFO(mvar);
+#endif
+
+  if (info == &EMPTY_MVAR_info) {
+
+#ifdef SMP
+    /* unlock the MVar */
+    mvar->header.info = &EMPTY_MVAR_info;
+#endif
+
+    /* HACK: we need a pointer to pass back, so we abuse NO_FINALIZER_closure */
+    RET_NP(0, &NO_FINALIZER_closure);
+  }
+
+  val = mvar->value;
+  mvar->value = (StgClosure *)&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,&EMPTY_MVAR_info);
+
+  TICK_RET_UNBOXED_TUP(1);
+  RET_NP(1,val);
+  FE_
+}
+
 FN_(putMVarzh_fast)
 {
   StgMVar *mvar;