Skip to content

Commit 1d79baa

Browse files
authored
Merge pull request #249 from ldorau/Cache_page_size_in_ba_os_get_page_size
Cache page size in ba_os_get_page_size()
2 parents 68836be + 2a22311 commit 1d79baa

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/base_alloc/base_alloc_linux.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
#include "base_alloc.h"
1515
#include "base_alloc_global.h"
16+
#include "utils_concurrency.h"
17+
18+
static UTIL_ONCE_FLAG Page_size_is_initialized = UTIL_ONCE_FLAG_INIT;
19+
static size_t Page_size;
1620

1721
// The highest possible priority (101) is used, because the constructor should be called
1822
// as the first one and the destructor as the last one in order to avoid use-after-free.
@@ -33,4 +37,9 @@ void ba_os_free(void *ptr, size_t size) {
3337
(void)ret; // unused
3438
}
3539

36-
size_t ba_os_get_page_size(void) { return sysconf(_SC_PAGE_SIZE); }
40+
static void _ba_os_init_page_size(void) { Page_size = sysconf(_SC_PAGE_SIZE); }
41+
42+
size_t ba_os_get_page_size(void) {
43+
util_init_once(&Page_size_is_initialized, _ba_os_init_page_size);
44+
return Page_size;
45+
}

0 commit comments

Comments
 (0)