Overview
| Artifact ID: | c0e634457e7006fcf4df2348ac6590ddf454b32b |
|---|---|
| Ticket: | 3065485fffffffffffffffffffffffffffffffff |
| Date: | 2010-09-17 02:57:54 |
| User: | andreas_kupries |
| Artifact Attached: | 5bccb003b9f4c6c3a8a91127a400a7a69d1c77ff |
| Filename: | numcpu.c |
| Description: | Updated implementation. |
Content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65/* * TODO: * = Extend tcl.m4 with check for 'sysconf()'. * = Find a proper define for BSD and/or OSX. * Or provide our own through tcl.m4/configure. */ int Tcl_GetNumberOfProcessors (int flags) { #ifdef _WIN /* Windows */ SYSTEM_INFO sysinfo; GetSystemInfo( &sysinfo ); return sysinfo.dwNumberOfProcessors; #elif defined (HAVE_SYSCTL) /* OS X (Mach-derived, BSD-derived), FreeBSD, NetBSD, OpenBSD, Linux, etc. */ int numCPU; nt mib[4]; size_t len; /* set the mib for hw.ncpu */ mib[0] = CTL_HW; mib[1] = HW_AVAILCPU; /* alternatively, try HW_NCPU */ /* get the number of CPUs from the system */ sysctl(mib, 2, &numCPU, &len, NULL, 0); if (numCPU < 1) { mib[1] = HW_NCPU; sysctl( mib, 2, &numCPU, &len, NULL, 0 ); if (numCPU < 1) { numCPU = 1; } return numCPU; #elif defined (HAVE_SYSCONF) /* * Linux, Solaris, AIX. * Note: This is a non-standard extension of the POSIX call. * Because of this the sysctl() is prefered. */ return sysconf( _SC_NPROCESSORS_ONLN ); #elif defined (hpux) return mpctl(MPC_GETNUMSPUS, NULL, NULL); #else /* * General fallback for anything where we have no idea how it * works. */ return 1; #endif } /* * IRIX: numCPU = sysconf( _SC_NPROC_ONLN ); */
