From: Bruno Haible <bruno@clisp.org>
Date: Mon, 9 Jan 2023 18:12:49 +0000 (+0100)
Subject: threads-h: Fix compilation errors in C++ mode on Android.
X-Git-Tag: v1.0~1871
X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=ede58b7442f9ff1e63cb5e6c391a039d8f00dc79;p=gnulib.git

threads-h: Fix compilation errors in C++ mode on Android.

* lib/threads.in.h (_GL_ALREADY_INCLUDING_THREADS_H): New macro.
---

diff --git a/ChangeLog b/ChangeLog
index 7554f5ba03..84226bb5e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2023-01-09  Bruno Haible  <bruno@clisp.org>
+
+	threads-h: Fix compilation errors in C++ mode on Android.
+	* lib/threads.in.h (_GL_ALREADY_INCLUDING_THREADS_H): New macro.
+
 2023-01-09  Bruno Haible  <bruno@clisp.org>
 
 	aligned-malloc: Don't disturb the module aligned_alloc.
diff --git a/lib/threads.in.h b/lib/threads.in.h
index b1e213fd2c..5786101d82 100644
--- a/lib/threads.in.h
+++ b/lib/threads.in.h
@@ -20,13 +20,30 @@
 #endif
 @PRAGMA_COLUMNS@
 
+#if defined _GL_ALREADY_INCLUDING_THREADS_H
+/* Special invocation convention:
+   - On Android we have a sequence of nested includes
+     <threads.h> -> <android/legacy_threads_inlines.h>
+     -> <bits/threads_inlines.h> -> "threads.h"
+     In this situation, the functions are not yet declared, therefore we cannot
+     provide the C++ aliases.  */
+
+#@INCLUDE_NEXT@ @NEXT_THREADS_H@
+
+#else
+/* Normal invocation convention.  */
+
 #ifndef _@GUARD_PREFIX@_THREADS_H
 
+#define _GL_ALREADY_INCLUDING_THREADS_H
+
 /* The include_next requires a split double-inclusion guard.  */
 #if @HAVE_THREADS_H@
 # @INCLUDE_NEXT@ @NEXT_THREADS_H@
 #endif
 
+#undef _GL_ALREADY_INCLUDING_THREADS_H
+
 #ifndef _@GUARD_PREFIX@_THREADS_H
 #define _@GUARD_PREFIX@_THREADS_H
 
@@ -662,3 +679,4 @@ _GL_WARN_ON_USE (tss_delete, "tss_delete is unportable - "
 
 #endif /* _@GUARD_PREFIX@_THREADS_H */
 #endif /* _@GUARD_PREFIX@_THREADS_H */
+#endif