changeset 30497:b4411a8b3c85

Make the 'sched' module work on platforms where <sched.h> is incomplete.
author Bruno Haible <bruno@clisp.org>
date Sat, 15 Nov 2008 13:06:41 +0100
parents cf0fca2891c6
children 7860a6147b84
files ChangeLog doc/posix-headers/sched.texi lib/sched.in.h m4/sched_h.m4 modules/sched
diffstat 5 files changed, 75 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Nov 13 08:11:30 2008 -0800
+++ b/ChangeLog	Sat Nov 15 13:06:41 2008 +0100
@@ -1,3 +1,17 @@
+2008-11-15  Bruno Haible  <bruno@clisp.org>
+
+	Make the 'sched' module work on platforms where <sched.h> exists but
+	is incomplete (such as Haiku).
+	* lib/sched.in.h; Include the system's <sched.h> if it exists.
+	(SCHED_FIFO, SCHED_RR, SCHED_OTHER): New macros.
+	* m4/sched_h.m4 (gl_SCHED_H): Test whether <sched.h> exists and also
+	defines SCHED_FIFO, SCHED_RR, SCHED_OTHER. Set HAVE_SCHED_H,
+	HAVE_STRUCT_SCHED_PARAM.
+	* modules/sched (Depends-on): Add include_next.
+	(Makefile.am): Substitute HAVE_SCHED_H, INCLUDE_NEXT,
+	PRAGMA_SYSTEM_HEADER, NEXT_SCHED_H, HAVE_STRUCT_SCHED_PARAM.
+	* doc/posix-headers/sched.texi: Document the issue.
+
 2008-11-13  Jim Meyering  <meyering@redhat.com>
 
 	test-argp-2: avoid test failure when PACKAGE_BUGREPORT is defined
--- a/doc/posix-headers/sched.texi	Thu Nov 13 08:11:30 2008 -0800
+++ b/doc/posix-headers/sched.texi	Sat Nov 15 13:06:41 2008 +0100
@@ -10,6 +10,13 @@
 @item
 This header file is missing on some platforms:
 mingw, BeOS.
+@item
+@code{struct sched_param} is not defined on some platforms:
+Haiku.
+@item
+@code{SCHED_FIFO}, @code{SCHED_RR}, @code{SCHED_OTHER} are not defined on
+some platforms:
+Haiku.
 @end itemize
 
 Portability problems not fixed by Gnulib:
--- a/lib/sched.in.h	Thu Nov 13 08:11:30 2008 -0800
+++ b/lib/sched.in.h	Sat Nov 15 13:06:41 2008 +0100
@@ -15,11 +15,33 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #ifndef _GL_SCHED_H
+
+#if __GNUC__ >= 3
+@PRAGMA_SYSTEM_HEADER@
+#endif
+
+/* The include_next requires a split double-inclusion guard.  */
+#if @HAVE_SCHED_H@
+# @INCLUDE_NEXT@ @NEXT_SCHED_H@
+#endif
+
+#ifndef _GL_SCHED_H
 #define _GL_SCHED_H
 
+#if !@HAVE_STRUCT_SCHED_PARAM@
+
 struct sched_param
 {
   int sched_priority;
 };
 
+#endif
+
+#if !(defined SCHED_FIFO && defined SCHED_RR && defined SCHED_OTHER)
+# define SCHED_FIFO   1
+# define SCHED_RR     2
+# define SCHED_OTHER  0
+#endif
+
 #endif /* _GL_SCHED_H */
+#endif /* _GL_SCHED_H */
--- a/m4/sched_h.m4	Thu Nov 13 08:11:30 2008 -0800
+++ b/m4/sched_h.m4	Sat Nov 15 13:06:41 2008 +0100
@@ -1,4 +1,4 @@
-# sched_h.m4 serial 1
+# sched_h.m4 serial 2
 dnl Copyright (C) 2008 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -8,11 +8,29 @@
 
 AC_DEFUN([gl_SCHED_H],
 [
-  AC_CHECK_HEADERS_ONCE([sched.h])
-  if test $ac_cv_header_sched_h = yes; then
-    SCHED_H=''
-  else
-    SCHED_H='sched.h'
-  fi
+  AC_COMPILE_IFELSE(
+    [AC_LANG_PROGRAM([[
+       #include <sched.h>
+       struct sched_param a;
+       int b[] = { SCHED_FIFO, SCHED_RR, SCHED_OTHER };
+     ]])],
+    [SCHED_H=''],
+    [SCHED_H='sched.h'
+
+     gl_CHECK_NEXT_HEADERS([sched.h])
+
+     AC_CHECK_HEADERS_ONCE([sched.h])
+     if test $ac_cv_header_sched_h = yes; then
+       HAVE_SCHED_H=1
+     else
+       HAVE_SCHED_H=0
+     fi
+     AC_SUBST([HAVE_SCHED_H])
+
+     AC_CHECK_TYPE([struct sched_param],
+       [HAVE_STRUCT_SCHED_PARAM=1], [HAVE_STRUCT_SCHED_PARAM=0],
+       [#include <sched.h>])
+     AC_SUBST([HAVE_STRUCT_SCHED_PARAM])
+    ])
   AC_SUBST([SCHED_H])
 ])
--- a/modules/sched	Thu Nov 13 08:11:30 2008 -0800
+++ b/modules/sched	Sat Nov 15 13:06:41 2008 +0100
@@ -6,6 +6,7 @@
 m4/sched_h.m4
 
 Depends-on:
+include_next
 
 configure.ac:
 gl_SCHED_H
@@ -18,7 +19,12 @@
 sched.h: sched.in.h
 	rm -f $@-t $@
 	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
-	  cat < $(srcdir)/sched.in.h; \
+	  sed -e 's|@''HAVE_SCHED_H''@|$(HAVE_SCHED_H)|g' \
+	      -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
+	      -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
+	      -e 's|@''NEXT_SCHED_H''@|$(NEXT_SCHED_H)|g' \
+	      -e 's|@''HAVE_STRUCT_SCHED_PARAM''@|$(HAVE_STRUCT_SCHED_PARAM)|g' \
+	      < $(srcdir)/sched.in.h; \
 	} > $@-t
 	mv $@-t $@
 MOSTLYCLEANFILES += sched.h sched.h-t