[libc++] Avoid including <semaphore.h> on Apple
authorLouis Dionne <ldionne@apple.com>
Tue, 25 Feb 2020 22:52:34 +0000 (17:52 -0500)
committerLouis Dionne <ldionne@apple.com>
Tue, 25 Feb 2020 22:52:34 +0000 (17:52 -0500)
It turns out that <semaphore.h> is not well-behaved, as it transitively
includes <sys/param.h>, and that one defines several non-reserved macros
that clash with some downstream projects in modular builds. For the time
being, using <sys/semaphore.h> instead gives us the declarations we need
without the macros.

rdar://59744472

libcxx/include/__threading_support

index d2ee0c693a15c4c79b005188645de2a633103e30..8dc6f11782d72481d8a8251bdfc477e9ad73d431 100644 (file)
 #if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
 # include <pthread.h>
 # include <sched.h>
+// FIXME: On Apple, <semaphore.h> transitively includes <sys/param.h>, which
+//        is not well behaved because it defines several macros. This causes
+//        name collisions in some downstream projects. Instead, <sys/semaphore.h>
+//        gives us the declarations we need without the bad stuff.
+#ifdef __APPLE__
+# include <sys/semaphore.h>
+#else
 # include <semaphore.h>
+#endif
 # ifdef __APPLE__
 #  define _LIBCPP_NO_NATIVE_SEMAPHORES
 # endif