Open MPI logo

Hardware Locality Development Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Hardware Locality Development mailing list

Subject: [hwloc-devel] sched.h and _GNU_SOURCE vs hwloc/glibc-sched.h mess
From: Brice Goglin (Brice.Goglin_at_[hidden])
Date: 2011-02-17 11:30:02


Most of our helper headers include the relevant upstream headers: for
instance hwloc/cuda.h includes cuda.h. The only exception is
hwloc/glibc-sched.h which doesn't include sched.h. The reason is that
sched.h is needed with _GNU_SOURCE defined. So if somebody includes
sched.h without _GNU_SOURCE and then includes hwloc/glibc-sched.h, it

Until now glibc-sched.h just complains with #error if sched.h wasn't
included earlier or _GNU_SOURCE isn't defined. I am tempted to apply the
following patch, so that people don't see the warning when they didn't
explicitly include sched.h without _GNU_SOURCE: we would include sched.h
with _GNU_SOURCE if not done already.

However, it gets funnier when you find out that hwloc.h ends up
including sched.h (through hwloc/config.h and pthread.h). And
_GNU_SOURCE doesn't get defined there. So the patch below would likely
not help anyway.

I guess we can't #define _GNU_SOURCE in hwloc.h. Any comments or better
idea ?


--- a/include/hwloc/glibc-sched.h
+++ b/include/hwloc/glibc-sched.h
@@ -20,8 +20,13 @@
 #include <hwloc/helper.h>
 #include <assert.h>
-#if !defined _GNU_SOURCE || !defined _SCHED_H
-#error sched.h must be included with _GNU_SOURCE defined
+#if defined _SCHED_H
+# if !defined _GNU_SOURCE
+# error you must define _GNU_SOURCE before including <sched.h>
+# endif
+# define _GNU_SOURCE
+# include <sched.h>