]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
ggml : make ggml_time_init idempotent (#24422)
authorAn Long <redacted>
Tue, 7 Jul 2026 07:29:17 +0000 (16:29 +0900)
committerGitHub <redacted>
Tue, 7 Jul 2026 07:29:17 +0000 (10:29 +0300)
ggml/src/ggml.c

index 0f682fd1856c55fb1c94f6ec1f18262382fc277b..440095f805a9cfb59f46cf42fc60b199bbcacea7 100644 (file)
@@ -525,7 +525,11 @@ const char * ggml_commit(void) {
 
 #if defined(_MSC_VER) || defined(__MINGW32__)
 static int64_t timer_freq, timer_start;
-void ggml_time_init(void) {
+static BOOL CALLBACK ggml_time_init_once(PINIT_ONCE once, PVOID param, PVOID *ctx) {
+    UNUSED(once);
+    UNUSED(param);
+    UNUSED(ctx);
+
     LARGE_INTEGER t;
     QueryPerformanceFrequency(&t);
     timer_freq = t.QuadPart;
@@ -535,6 +539,12 @@ void ggml_time_init(void) {
     // We subtract the program start time to reduce the likelihood of that happening.
     QueryPerformanceCounter(&t);
     timer_start = t.QuadPart;
+
+    return TRUE;
+}
+void ggml_time_init(void) {
+    static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
+    InitOnceExecuteOnce(&once, ggml_time_init_once, NULL, NULL);
 }
 int64_t ggml_time_ms(void) {
     LARGE_INTEGER t;