From c076c52a323584d6d00ca7079072cbc0dd88cb43 Mon Sep 17 00:00:00 2001
From: Dave Airlie <airlied@redhat.com>
Date: Fri, 7 Nov 2025 13:14:56 +1000
Subject: [PATCH] c11/threads: fix build on c23

C23/glibc is now including once_init in stdlib.h

https://patchwork.sourceware.org/project/glibc/patch/78061085-f04a-0c45-107b-5a8a15521083@redhat.com/#213088

Just fix up our use of it.

Upstream-Status: Submitted [https://gitlab.freedesktop.org/virgl/virglrenderer/-/merge_requests/1567]
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 src/mesa/compat/c11/threads_posix.h | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/mesa/compat/c11/threads_posix.h b/src/mesa/compat/c11/threads_posix.h
index 45cb6075..071faf79 100644
--- a/src/mesa/compat/c11/threads_posix.h
+++ b/src/mesa/compat/c11/threads_posix.h
@@ -51,7 +51,9 @@ Configuration macro:
 #include <pthread.h>
 
 /*---------------------------- macros ----------------------------*/
+#ifndef __once_flag_defined
 #define ONCE_FLAG_INIT PTHREAD_ONCE_INIT
+#endif
 #ifdef INIT_ONCE_STATIC_INIT
 #define TSS_DTOR_ITERATIONS PTHREAD_DESTRUCTOR_ITERATIONS
 #else
@@ -66,8 +68,9 @@ typedef pthread_cond_t  cnd_t;
 typedef pthread_t       thrd_t;
 typedef pthread_key_t   tss_t;
 typedef pthread_mutex_t mtx_t;
+#ifndef __once_flag_defined
 typedef pthread_once_t  once_flag;
-
+#endif
 
 /*
 Implementation limits:
@@ -90,12 +93,13 @@ impl_thrd_routine(void *p)
 
 /*--------------- 7.25.2 Initialization functions ---------------*/
 // 7.25.2.1
+#ifndef __once_flag_defined
 static inline void
 call_once(once_flag *flag, void (*func)(void))
 {
     pthread_once(flag, func);
 }
-
+#endif
 
 /*------------- 7.25.3 Condition variable functions -------------*/
 // 7.25.3.1
