diff options
| author | simonmar <unknown> | 2003-09-24 11:06:54 +0000 |
|---|---|---|
| committer | simonmar <unknown> | 2003-09-24 11:06:54 +0000 |
| commit | 8f57c3c1812681ef2a57f7982b81c3123e90a2ca (patch) | |
| tree | 019a295ccbf918e9c1ebb60709c54bc22d431a0e | |
| parent | 8fb92f95a80f57c9e6737755881bd08c701a42eb (diff) | |
| download | haskell-8f57c3c1812681ef2a57f7982b81c3123e90a2ca.tar.gz | |
[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.
| -rw-r--r-- | ghc/includes/PrimOps.h | 3 | ||||
| -rw-r--r-- | ghc/rts/Linker.c | 3 | ||||
| -rw-r--r-- | ghc/rts/OSThreads.c | 56 |
3 files changed, 59 insertions, 3 deletions
diff --git a/ghc/includes/PrimOps.h b/ghc/includes/PrimOps.h index 9576f248f3..373ef92456 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 67538765b6..7bcf149458 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 739090d56a..06b905af16 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 <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) */ + |
