@@ -92,9 +92,11 @@ typedef BOOL (__stdcall* PGetVersionExW)(LPOSVERSIONINFOW lpVersionInformation);
9292
9393static bool win_enable_large_os_pages (size_t * large_page_size )
9494{
95- static bool large_initialized = false;
96- if (large_initialized ) return (_mi_os_large_page_size () > 0 );
97- large_initialized = true;
95+ static mi_atomic_once_t large_initialized ;
96+ if (!mi_atomic_once (& large_initialized )) {
97+ return (_mi_os_large_page_size () > 0 );
98+ }
99+
98100 if (pGetLargePageMinimum == NULL ) return false; // no large page support (xbox etc.)
99101
100102 // Try to see if large OS pages are supported
@@ -417,8 +419,8 @@ static void* _mi_prim_alloc_huge_os_pagesx(void* hint_addr, size_t size, int num
417419
418420 MI_MEM_EXTENDED_PARAMETER params [3 ] = { {{0 ,0 },{0 }},{{0 ,0 },{0 }},{{0 ,0 },{0 }} };
419421 // on modern Windows try use NtAllocateVirtualMemoryEx for 1GiB huge pages
420- static bool mi_huge_pages_available = true ;
421- if (pNtAllocateVirtualMemoryEx != NULL && mi_huge_pages_available ) {
422+ static _Atomic ( size_t ) mi_huge_pages_available = ATOMIC_VAR_INIT ( 1 ) ;
423+ if (pNtAllocateVirtualMemoryEx != NULL && mi_atomic_load_acquire ( & mi_huge_pages_available ) != 0 ) {
422424 params [0 ].Type .Type = MiMemExtendedParameterAttributeFlags ;
423425 params [0 ].Arg .ULong64 = MI_MEM_EXTENDED_PARAMETER_NONPAGED_HUGE ;
424426 ULONG param_count = 1 ;
@@ -435,7 +437,7 @@ static void* _mi_prim_alloc_huge_os_pagesx(void* hint_addr, size_t size, int num
435437 }
436438 else {
437439 // fall back to regular large pages
438- mi_huge_pages_available = false ; // don't try further huge pages
440+ mi_atomic_store_release ( & mi_huge_pages_available , 0 ) ; // don't try further huge pages
439441 _mi_warning_message ("unable to allocate using huge (1GiB) pages, trying large (2MiB) pages instead (status 0x%lx)\n" , err );
440442 }
441443 }
0 commit comments