mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-08 21:42:06 -04:00
Merge branch '2819-cache-the-isc_os_ncpu-result' into 'main'
Cache the isc_os_ncpu() result Closes #2819 See merge request isc-projects/bind9!5263
This commit is contained in:
commit
ef467a5a7c
2 changed files with 18 additions and 6 deletions
|
|
@ -14,6 +14,7 @@
|
|||
#include <isc/bind9.h>
|
||||
#include <isc/lib.h>
|
||||
#include <isc/mem.h>
|
||||
#include <isc/os.h>
|
||||
#include <isc/tls.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
|
|
@ -45,6 +46,7 @@ isc__initialize(void) {
|
|||
isc__mem_initialize();
|
||||
isc__tls_initialize();
|
||||
isc__trampoline_initialize();
|
||||
(void)isc_os_ncpus();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
22
lib/isc/os.c
22
lib/isc/os.c
|
|
@ -9,7 +9,12 @@
|
|||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
#include <isc/once.h>
|
||||
#include <isc/os.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
static isc_once_t ncpus_once = ISC_ONCE_INIT;
|
||||
static unsigned int ncpus = 0;
|
||||
|
||||
#ifdef HAVE_SYSCONF
|
||||
|
||||
|
|
@ -46,10 +51,8 @@ sysctl_ncpus(void) {
|
|||
}
|
||||
#endif /* if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME) */
|
||||
|
||||
unsigned int
|
||||
isc_os_ncpus(void) {
|
||||
long ncpus = 0;
|
||||
|
||||
static void
|
||||
ncpus_initialize(void) {
|
||||
#if defined(HAVE_SYSCONF)
|
||||
ncpus = sysconf_ncpus();
|
||||
#endif /* if defined(HAVE_SYSCONF) */
|
||||
|
|
@ -61,6 +64,13 @@ isc_os_ncpus(void) {
|
|||
if (ncpus <= 0) {
|
||||
ncpus = 1;
|
||||
}
|
||||
|
||||
return ((unsigned int)ncpus);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
isc_os_ncpus(void) {
|
||||
isc_result_t result = isc_once_do(&ncpus_once, ncpus_initialize);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS);
|
||||
INSIST(ncpus > 0);
|
||||
|
||||
return (ncpus);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue