File: threads.c

package info (click to toggle)
validns 0.8%2Bgit20160720-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,120 kB
  • ctags: 786
  • sloc: ansic: 7,241; perl: 283; makefile: 160
file content (33 lines) | stat: -rw-r--r-- 786 bytes parent folder | download | duplicates (4)
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
#include <stdlib.h>
#include <stdio.h>
#ifdef __GLIBC__
#include <sys/sysinfo.h>
#elif defined(__APPLE__) || defined(__FreeBSD__)
#include <sys/types.h>
#include <sys/sysctl.h>
#endif

/*	supposedly,
	#if defined(PTW32_VERSION) || defined(__hpux)
		return pthread_num_processors_np();
	but I cannot verify that at the moment
*/

#if defined(__GLIBC__)
int ncpus(void) { return get_nprocs(); }
#elif defined(__APPLE__) || defined(__FreeBSD__)
int ncpus(void)
{
	int count;
	size_t size=sizeof(count);
	return sysctlbyname("hw.ncpu",&count,&size,NULL,0) ? 0 : count;
}
#else
int ncpus(void) { return 0; }  /* "Don't know */
#endif

/*	Supposedly, sysconf() can also be used in some cases:
	#include <unistd.h>
	int const count=sysconf(_SC_NPROCESSORS_ONLN);
	return (count>0)?count:0;
*/