[project @ 2003-09-24 11:06:51 by simonmar]
authorsimonmar <unknown>
Wed, 24 Sep 2003 11:06:54 +0000 (11:06 +0000)
committersimonmar <unknown>
Wed, 24 Sep 2003 11:06:54 +0000 (11:06 +0000)
Move forkOS_createThread into the RTS so its implementation can be
dependent on RTS_SUPPORTS_THREADS, which means we can provide a stub
implementation in the !RTS_SUPPORTS_THREADS case, and hence not depend
on pthread_create, which requires -lpthread.  The upshot is that GHCi
now works again when !RTS_SUPPORTS_THREADS.

ghc/includes/PrimOps.h
ghc/rts/Linker.c
ghc/rts/OSThreads.c

index 9576f24..373ef92 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: PrimOps.h,v 1.104 2003/09/21 22:20:52 wolfgang Exp $
+ * $Id: PrimOps.h,v 1.105 2003/09/24 11:06:51 simonmar Exp $
  *
  * (c) The GHC Team, 1998-2000
  *
@@ -285,6 +285,7 @@ EXTFUN_RTS(isCurrentThreadBoundzh_fast);
 
 extern int cmp_thread(StgPtr tso1, StgPtr tso2);
 extern int rts_getThreadId(StgPtr tso);
+extern int forkOS_createThread ( HsStablePtr entry );
 
 /* -----------------------------------------------------------------------------
    Weak Pointer PrimOps.
index 6753876..7bcf149 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Linker.c,v 1.130 2003/09/21 22:20:54 wolfgang Exp $
+ * $Id: Linker.c,v 1.131 2003/09/24 11:06:53 simonmar Exp $
  *
  * (c) The GHC Team, 2000-2003
  *
@@ -370,6 +370,7 @@ typedef struct _RtsSymbolVal {
       SymX(divModIntegerzh_fast)               \
       SymX(forkzh_fast)                                \
       SymX(forkProcesszh_fast)                  \
+      SymX(forkOS_createThread)                        \
       SymX(freeHaskellFunctionPtr)             \
       SymX(freeStablePtr)                      \
       SymX(gcdIntegerzh_fast)                  \
index 739090d..06b905a 100644 (file)
@@ -97,7 +97,31 @@ initMutex(Mutex* pMut)
   return;
 }
 
+static void *
+forkOS_createThreadWrapper ( void * entry )
+{
+    rts_lock();
+    rts_evalStableIO((HsStablePtr) entry, NULL);
+    rts_unlock();
+    return NULL;
+}
+
+int
+forkOS_createThread ( HsStablePtr entry )
+{
+    pthread_t tid;
+    int result = pthread_create(&tid, NULL,
+                               forkOS_createThreadWrapper, (void*)entry);
+    if(!result)
+        pthread_detach(tid);
+    return result;
+}
+
 #elif defined(HAVE_WINDOWS_H)
+/* For reasons not yet clear, the entire contents of process.h is protected 
+ * by __STRICT_ANSI__ not being defined.
+ */
+#undef __STRICT_ANSI__
 #include <process.h>
 
 /* Win32 threads and synchronisation objects */
@@ -209,6 +233,36 @@ initMutex (Mutex* pMut)
   return;
 }
 
+static unsigned __stdcall
+forkOS_createThreadWrapper ( void * entry )
+{
+    rts_lock();
+    rts_evalStableIO((HsStablePtr) entry, NULL);
+    rts_unlock();
+    return 0;
+}
+
+int
+forkOS_createThread ( HsStablePtr entry )
+{
+    unsigned long pId;
+    return (_beginthreadex ( NULL,  /* default security attributes */
+                          0,
+                          forkOS_createThreadWrapper,
+                          (void*)entry,
+                          0,
+                          (unsigned*)&pId) == 0);
+}
+
 #endif /* defined(HAVE_PTHREAD_H) */
 
-#endif /* defined(RTS_SUPPORTS_THREADS) */
+#else /* !defined(RTS_SUPPORTS_THREADS) */
+
+int
+forkOS_createThread ( HsStablePtr entry )
+{
+    return -1;
+}
+
+#endif /* !defined(RTS_SUPPORTS_THREADS) */
+