X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Frts%2FOSThreads.c;h=5d3c8c9caffc27d1709f43deb3ba767414e0fff3;hb=f59e2cececddab7c7004db636704a9a510d84c6b;hp=739090d56ac91b8d3fa82f2592e01d95f34bf7ec;hpb=79ff5ead125b16bebb4aac763e703f3847c9b657;p=ghc-hetmet.git diff --git a/ghc/rts/OSThreads.c b/ghc/rts/OSThreads.c index 739090d..5d3c8c9 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 STG_UNUSED ) +{ + return -1; +} + +#endif /* !defined(RTS_SUPPORTS_THREADS) */ +