X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2Fposix%2FOSThreads.c;h=29cb23eb6d700dc5e3494550004194f8ededad07;hb=HEAD;hp=a813eebf9ee8924437bb76e8f03f48964c81fc89;hpb=a2a67cd520b9841114d69a87a423dabcb3b4368e;p=ghc-hetmet.git diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c index a813eeb..29cb23e 100644 --- a/rts/posix/OSThreads.c +++ b/rts/posix/OSThreads.c @@ -7,13 +7,20 @@ * * --------------------------------------------------------------------------*/ -#if defined(__linux__) +#if defined(__linux__) || defined(__GLIBC__) /* We want GNU extensions in DEBUG mode for mutex error checking */ /* We also want the affinity API, which requires _GNU_SOURCE */ #define _GNU_SOURCE #endif #include "PosixSource.h" + +#if defined(freebsd_HOST_OS) +/* Inclusion of system headers usually requires __BSD_VISIBLE on FreeBSD, + * because of some specific types, like u_char, u_int, etc. */ +#define __BSD_VISIBLE 1 +#endif + #include "Rts.h" #if defined(THREADED_RTS) @@ -24,7 +31,7 @@ #include #endif -#if defined(darwin_HOST_OS) +#if defined(darwin_HOST_OS) || defined(freebsd_HOST_OS) #include #include #endif @@ -37,6 +44,11 @@ #include #endif +#if defined(HAVE_SYS_CPUSET_H) +#include +#include +#endif + #ifdef HAVE_UNISTD_H #include #endif @@ -45,6 +57,10 @@ #include #endif +#ifdef HAVE_SIGNAL_H +# include +#endif + /* * This (allegedly) OS threads independent layer was initially * abstracted away from code that used Pthreads, so the functions @@ -208,7 +224,7 @@ getNumberOfProcessors (void) nproc = sysconf(_SC_NPROCESSORS_ONLN); #elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_CONF) nproc = sysconf(_SC_NPROCESSORS_CONF); -#elif defined(darwin_HOST_OS) +#elif defined(darwin_HOST_OS) || defined(freebsd_HOST_OS) size_t size = sizeof(nat); if(0 != sysctlbyname("hw.ncpu",&nproc,&size,NULL,0)) nproc = 1; @@ -253,6 +269,23 @@ setThreadAffinity (nat n, nat m GNUC3_ATTRIBUTE(__unused__)) THREAD_AFFINITY_POLICY_COUNT); } +#elif defined(HAVE_SYS_CPUSET_H) /* FreeBSD 7.1+ */ +void +setThreadAffinity(nat n, nat m) +{ + nat nproc; + cpuset_t cs; + nat i; + + nproc = getNumberOfProcessors(); + CPU_ZERO(&cs); + + for (i = n; i < nproc; i += m) + CPU_SET(i, &cs); + + cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), &cs); +} + #else void setThreadAffinity (nat n GNUC3_ATTRIBUTE(__unused__), @@ -261,6 +294,12 @@ setThreadAffinity (nat n GNUC3_ATTRIBUTE(__unused__), } #endif +void +interruptOSThread (OSThreadId id) +{ + pthread_kill(id, SIGPIPE); +} + #else /* !defined(THREADED_RTS) */ int