Commit 8f57c3c1 authored by simonmar's avatar simonmar
Browse files

[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.
parent 8fb92f95
/* -----------------------------------------------------------------------------
* $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.
......
/* -----------------------------------------------------------------------------
* $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) \
......
......@@ -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) */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment