r6.0.1:abstraction_cpu_count

From liblfds.org
Revision as of 14:07, 4 January 2015 by Admin (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Source Files

/test/src/abstraction_cpu_count.c
/test/src/abstraction.h

Prototype

unsigned int abstraction_cpu_count( void );

Parameters

No parameters.

Return Value

Returns the number of CPUs in the system.

Notes

The test program, when testing, runs a number of thread per CPU. CPUs which support Hyperthreading or similar technologies can usefully run additional threads per CPU, since these threads will be truly be running in parallel in hardware, and so such systems should really return the number of "independent thread-executing units" in the system.

Examples

Under Windows (32-bit and 64-bit), using the Microsoft C compiler, there is a particular function GetSystemInfo which the following prototype;

void WINAPI GetSystemInfo( __out LPSYSTEM_INFO lpSystemInfo );

As such, the implementation of lfds601_abstraction_cpu_count() on all Windows, for all CPUs, using the Microsoft C compiler, looks like this;

#if (defined _WIN32 && defined _MSC_VER)

  /* TRD : any Windows on any CPU with the Microsoft C compiler

           _WIN32    indicates 64-bit or 32-bit Windows
           _MSC_VER  indicates Microsoft C compiler
  */

  unsigned int abstraction_cpu_count()
  {
    SYSTEM_INFO
      si;

    GetSystemInfo( &si );

    return( (unsigned int) si.dwNumberOfProcessors );
  }

#endif

See Also