summaryrefslogtreecommitdiff
path: root/db-4.8.30/os/os_cpu.c
blob: 71387b04ce507439fec7d175ed1373fe57172a61 (plain)
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
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 1997-2009 Oracle.  All rights reserved.
 *
 * $Id$
 */

#include "db_config.h"

#include "db_int.h"

#ifdef HAVE_SYSTEM_INCLUDE_FILES
#if defined(HAVE_PSTAT_GETDYNAMIC)
#include <sys/pstat.h>
#endif
#endif

/*
 * __os_cpu_count --
 *	Return the number of CPUs.
 *
 * PUBLIC: u_int32_t __os_cpu_count __P((void));
 */
u_int32_t
__os_cpu_count()
{
#if defined(HAVE_PSTAT_GETDYNAMIC)
	/*
	 * HP/UX.
	 */
	struct pst_dynamic psd;

	return ((u_int32_t)pstat_getdynamic(&psd,
	    sizeof(psd), (size_t)1, 0) == -1 ? 1 : psd.psd_proc_cnt);
#elif defined(HAVE_SYSCONF) && defined(_SC_NPROCESSORS_ONLN)
	/*
	 * Solaris, Linux.
	 */
	long nproc;

	nproc = sysconf(_SC_NPROCESSORS_ONLN);
	return ((u_int32_t)(nproc > 1 ? nproc : 1));
#else
	return (1);
#endif
}