From: simonmar Date: Wed, 24 Sep 2003 11:06:54 +0000 (+0000) Subject: [project @ 2003-09-24 11:06:51 by simonmar] X-Git-Tag: Approx_11550_changesets_converted~415 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=8f57c3c1812681ef2a57f7982b81c3123e90a2ca [project @ 2003-09-24 11:06:51 by simonmar] 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. --- diff --git a/ghc/includes/PrimOps.h b/ghc/includes/PrimOps.h index 9576f24..373ef92 100644 --- a/ghc/includes/PrimOps.h +++ b/ghc/includes/PrimOps.h @@ -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. diff --git a/ghc/rts/Linker.c b/ghc/rts/Linker.c index 6753876..7bcf149 100644 --- a/ghc/rts/Linker.c +++ b/ghc/rts/Linker.c @@ -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) \ diff --git a/ghc/rts/OSThreads.c b/ghc/rts/OSThreads.c index 739090d..06b905a 100644 --- a/ghc/rts/OSThreads.c +++ b/ghc/rts/OSThreads.c @@ -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 /* 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) */ +