[project @ 2000-04-14 15:18:05 by sewardj]
[ghc-hetmet.git] / ghc / rts / PrimOps.hc
index ff672a0..1c548f4 100644 (file)
@@ -1,7 +1,7 @@
 /* -----------------------------------------------------------------------------
- * $Id: PrimOps.hc,v 1.44 2000/03/13 10:53:56 simonmar Exp $
+ * $Id: PrimOps.hc,v 1.51 2000/04/12 17:11:38 simonmar Exp $
  *
- * (c) The GHC Team, 1998-1999
+ * (c) The GHC Team, 1998-2000
  *
  * Primitive functions / data
  *
@@ -19,6 +19,7 @@
 #include "StablePriv.h"
 #include "HeapStackCheck.h"
 #include "StgRun.h"
+#include "Itimer.h"
 #include "Prelude.h"
 
 /* ** temporary **
@@ -323,14 +324,14 @@ FN_(newMutVarzh_fast)
    -------------------------------------------------------------------------- */
 
 #ifndef PAR
-FN_(makeForeignObjzh_fast)
+FN_(mkForeignObjzh_fast)
 {
   /* R1.p = ptr to foreign object,
   */
   StgForeignObj *result;
   FB_
 
-  HP_CHK_GEN_TICKY(sizeofW(StgForeignObj), NO_PTRS, makeForeignObjzh_fast,);
+  HP_CHK_GEN_TICKY(sizeofW(StgForeignObj), NO_PTRS, mkForeignObjzh_fast,);
   TICK_ALLOC_PRIM(sizeofW(StgHeader),
                  sizeofW(StgForeignObj)-sizeofW(StgHeader), 0);
   CCS_ALLOC(CCCS,sizeofW(StgForeignObj)); /* ccs prof */
@@ -887,6 +888,47 @@ FN_(takeMVarzh_fast)
   FE_
 }
 
+FN_(takeMaybeMVarzh_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;
@@ -904,8 +946,13 @@ FN_(putMVarzh_fast)
 #endif
 
   if (info == &FULL_MVAR_info) {
-    R1.cl = (StgClosure *)&PutFullMVar_closure;
+#ifdef INTERPRETER
+    fprintf(stderr, "fatal: put on a full MVar in Hugs; aborting\n" );
+    exit(1);
+#else
+    R1.cl = (StgClosure *)PutFullMVar_closure;
     JMP_(raisezh_fast);
+#endif
   }
   
   mvar->value = R2.cl;
@@ -1011,7 +1058,11 @@ FN_(delayzh_fast)
     /* Add on ticks_since_select, since these will be subtracted at
      * the next awaitEvent call.
      */
+#if defined(HAVE_SETITIMER) || defined(mingw32_TARGET_OS)
     CurrentTSO->block_info.delay = R1.i + ticks_since_select;
+#else
+    CurrentTSO->block_info.target = R1.i + getourtimeofday();
+#endif
 
     APPEND_TO_BLOCKED_QUEUE(CurrentTSO);