From c6712ee2b29a9cb861e34102c5a3a9d43ffaba28 Mon Sep 17 00:00:00 2001 From: Zhao Zhili Date: Wed, 4 Sep 2024 21:50:56 +0800 Subject: [PATCH] make try_initialize_global_cpu_info thread safe --- src/cpu.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/cpu.cpp b/src/cpu.cpp index f9e64a1cc75b..b6a3e37913ee 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -1932,15 +1932,10 @@ static void initialize_global_cpu_info() #endif // defined __ANDROID__ || defined __linux__ } -static int g_cpu_info_initialized = 0; - static inline void try_initialize_global_cpu_info() { - if (!g_cpu_info_initialized) - { - initialize_global_cpu_info(); - g_cpu_info_initialized = 1; - } + static ncnn::OnceFlag flag = OnceFlagInit; + ncnn::CallOnce(flag, &initialize_global_cpu_info); } namespace ncnn {