Skip to content
Tcl Source Code Attachment Details
Login

Attachment Details

Overview

Artifact ID: fe5f41aede0d4653f2c682223af1c44d0965d98c
Ticket: 3065485fffffffffffffffffffffffffffffffff
Date: 2010-09-15 05:23:18
User: andreas_kupries
Artifact Attached: 721f98ea8a0a7a8da6f0717e27338775cb4fc141
Filename:numcpu.c
Description:Incomplete implementation of the C-level function
Content:
/*
 * 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_SYSCONF)
    /* Linux, Solaris, AIX */
    return sysconf( _SC_NPROCESSORS_ONLN );

#elif defined (hpux)
    return mpctl(MPC_GETNUMSPUS, NULL, NULL);

#elif defined (... BSD ...)
    /* OS X (Mach-derived, BSD-derived), FreeBSD, NetBSD, OpenBSD, 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;
#else
     /*
      * General fallback for anything where we have no idea how it
      * works.
      */
     return 1;
#endif
}
/*
 * IRIX: numCPU = sysconf( _SC_NPROC_ONLN );
 */