changeset 39382:3a6f09820061

pthread: Fix compilation error on Android. * lib/pthread.in.h: Use _GL_ALREADY_INCLUDING_PTHREAD_H to shortcut recursive inclusion of this file.
author Bruno Haible <bruno@clisp.org>
date Mon, 14 May 2018 01:02:02 +0200
parents 3af3840c8fa8
children 05d6ec4cd807
files ChangeLog lib/pthread.in.h
diffstat 2 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Mon May 14 00:27:43 2018 +0200
+++ b/ChangeLog	Mon May 14 01:02:02 2018 +0200
@@ -1,3 +1,9 @@
+2018-05-13  Bruno Haible  <bruno@clisp.org>
+
+	pthread: Fix compilation error on Android.
+	* lib/pthread.in.h: Use _GL_ALREADY_INCLUDING_PTHREAD_H to shortcut
+	recursive inclusion of this file.
+
 2018-05-13  Bruno Haible  <bruno@clisp.org>
 
 	posix_spawn: Fix compilation error on Android.
--- a/lib/pthread.in.h	Mon May 14 00:27:43 2018 +0200
+++ b/lib/pthread.in.h	Mon May 14 01:02:02 2018 +0200
@@ -17,16 +17,35 @@
 
 /* Written by Paul Eggert and Glen Lenker.  */
 
-#ifndef _@GUARD_PREFIX@_PTHREAD_H_
-
 #if __GNUC__ >= 3
 @PRAGMA_SYSTEM_HEADER@
 #endif
 @PRAGMA_COLUMNS@
 
-/* The include_next requires a split double-inclusion guard.  */
+#if defined _GL_ALREADY_INCLUDING_PTHREAD_H
+/* Special invocation convention:
+   On Android, we have a sequence of nested includes
+   <pthread.h> -> <time.h> -> <sys/time.h> -> <sys/select.h> ->
+   <signal.h> -> <pthread.h>.
+   In this situation, PTHREAD_COND_INITIALIZER is not yet defined,
+   therefore we should not attempt to define PTHREAD_MUTEX_NORMAL etc.  */
+
+#@INCLUDE_NEXT@ @NEXT_PTHREAD_H@
+
+#else
+/* Normal invocation convention.  */
+
+#ifndef _@GUARD_PREFIX@_PTHREAD_H_
+
 #if @HAVE_PTHREAD_H@
+
+# define _GL_ALREADY_INCLUDING_PTHREAD_H
+
+/* The include_next requires a split double-inclusion guard.  */
 # @INCLUDE_NEXT@ @NEXT_PTHREAD_H@
+
+# undef _GL_ALREADY_INCLUDING_PTHREAD_H
+
 #endif
 
 #ifndef _@GUARD_PREFIX@_PTHREAD_H_
@@ -293,3 +312,4 @@
 
 #endif /* _@GUARD_PREFIX@_PTHREAD_H_ */
 #endif /* _@GUARD_PREFIX@_PTHREAD_H_ */
+#endif