1 omniorb/thread: use proper autoconf macros for header inclusion
3 src/lib/omnithread/posix.cc uses sleep() and usleep(), defined in
4 <unistd.h> on numerous platforms, and struct timeval/gettimeofday(),
5 defined in <sys/time.h> on various platforms.
7 Since those header files are not available on all platforms, posix.cc
8 currently uses the following condition:
10 #if (defined(__GLIBC__) && __GLIBC__ >= 2) || defined(__SCO_VERSION__) || defined(__aix__) || defined (__cygwin__) || defined(__darwin__) || defined(__macos__)
12 Unfortunately, this falls short on Linux systems based on the musl C
13 library. Indeed, the musl C library does not define the __GLIBC__
14 symbol, but does have the sleep()/usleep() definitions in <unistd.h>,
15 and the struct timeval/gettimeofday() definitions in <sys/time.h>,
16 like any Linux system. Also, the musl C library does not define any
17 constant like __MUSL__ to distinguish it.
19 Due to this, on musl based systems, <unistd.h> and <sys/time.h> are
20 not included, causing a build failure:
22 posix.cc:864:22: error: '::sleep' has not been declared
23 while ((secs = ::sleep(secs))) ;
25 posix.cc:866:43: error: 'usleep' was not declared in this scope
26 usleep(secs * 1000000 + (nanosecs / 1000));
28 posix.cc: In static member function 'static void omni_thread::get_time(long unsigned int*, long unsigned int*, long unsigned int, long unsigned int)':
29 posix.cc:904:20: error: aggregate 'omni_thread::get_time(long unsigned int*, long unsigned int*, long unsigned int, long unsigned int)::timeval tv' has incomplete type and cannot be defined
32 posix.cc:905:24: error: 'gettimeofday' was not declared in this scope
35 It turns out that the configure.ac already checks for the availability
36 of <unistd.h> and <sys/time.h>. So all what this patch does is use the
37 C defines generated by the configure script to decide whether
38 <unistd.h> and <sys/time.h> can be included or not.
40 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
42 Index: b/src/lib/omnithread/posix.cc
43 ===================================================================
44 --- a/src/lib/omnithread/posix.cc
45 +++ b/src/lib/omnithread/posix.cc
49 #include <omnithread.h>
50 +#include <omniORB4/acconfig.h>
52 -#if (defined(__GLIBC__) && __GLIBC__ >= 2) || defined(__SCO_VERSION__) || defined(__aix__) || defined (__cygwin__) || defined(__darwin__) || defined(__macos__)
53 // typedef of struct timeval and gettimeofday();
54 +#if defined(HAVE_SYS_TIME_H)
58 +#if defined(HAVE_UNISTD_H)