On Monday 22 October 2012 04:06:24 Karel Zak wrote: > On Mon, Oct 22, 2012 at 02:01:01AM -0400, Mike Frysinger wrote: > > On Thursday 18 October 2012 16:06:28 Sami Kerola wrote: > > > On Mon, Oct 15, 2012 at 3:14 AM, Mike Frysinger wrote: > > > > On Sunday 14 October 2012 16:20:59 Sami Kerola wrote: > > > >> POSIX.1-2001 declares usleep is obsolete. > > > > > > > > this is true, but it seems like a better answer would be to add a > > > > usleep test to configure and provide a local fallback using nanosleep > > > > if it doesn't exist. > > > > > > Is that necessary? There has been for example in old mount since March > > > 2007[1] nanosleep() call, and I cannot remember anyone complaining it > > > causing problems. > > > > > > [1] commit dc8fdc57cd3ba0658cf4ab05031695c2d2965f93 > > > > i think you misinterpreted my objection. i don't have a problem with > > calling nanosleep() -- when it makes sense. replacing a simple call to > > a function that, while no longer part of the latest standard, was > > mandated for many many years, and will most likely never be removed from > > C libraries that have already been providing it (since it'd be an ABI > > break), with a more complicated call for no real reason is pointless > > imo. further, you'd be fighting a losing battle: developers will most > > likely be working & testing on a glibc system where usleep does exist > > and works fine, so they won't notice if it were added again. > > > > hence i suggested a trivial middle ground that is future proof and > > doesn't penalize systems that do include usleep (i.e. glibc i.e. what > > the majority of people run): if you actually have a system that lacks > > usleep, then add usleep to the AC_CHECK_FUNCS tests in configure.ac, and > > then add the simple replacement to include/c.h: > > #ifndef HAVE_USLEEP > > static inline int usleep(useconds_t usec) > > { > > > > struct timespec waittime; > > waittime.tv_sec = usec / 1000000L; > > waittime.tv_nsec = (usec % 1000000L) * 1000; > > return nanosleep(&waittime, NULL); > > > > } > > #endif > > > > now everything should "just work". > > Exactly this solution we use for now (since 2009): heh. too fast! > $ cat include/usleep.h > > #ifndef UTIL_LINUX_USLEEP_H > #define UTIL_LINUX_USLEEP_H > > #ifndef HAVE_USLEEP > /* > * This function is marked obsolete in POSIX.1-2001 and removed in > * POSIX.1-2008. It is replaced with nanosleep(). > */ > # define usleep(x) \ > do { \ > struct timespec xsleep; \ > xsleep.tv_sec = x / 1000 / 1000; \ > xsleep.tv_nsec = (x - xsleep.tv_sec * 1000 * 1000) * 1000; \ > nanosleep(&xsleep, NULL); \ > } while (0) > #endif > > #endif /* UTIL_LINUX_USLEEP_H */ if you were to do something like: int foo = 10; usleep(foo++); this define macro would misbehave because it expands x twice. not that the current code base does. > ... so I don't think we have to check change anything. indeed -mike
Attachment:
signature.asc
Description: This is a digitally signed message part.