Re: [PATCH] replace usleep()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Monday 17 August 2009 15:34:33 Daniel Mierswa wrote:
> --- /dev/null
> +++ b/include/usleep.h
> @@ -0,0 +1,14 @@
> +#ifndef UTIL_LINUX_USLEEP_H
> +#define UTIL_LINUX_USLEEP_H
> +
> +#ifdef HAVE_NANOSLEEP
> +# define my_usleep(x) \
> +       struct timespec xsleep; \
> +       xsleep.tv_sec = x / 1000 / 1000; \
> +       xsleep.tv_nsec = (x - xsleep.tv_sec * 1000 * 1000) * 1000; \
> +       nanosleep(&xsleep, NULL);
> +#else
> +# define my_usleep usleep
> +#endif

issues:
 - there should be comments in this file explaining why it exists (i.e. your 
deprecation info)
 - since it is included last (at least after system headers), you should 
simply define usleep rather than creating a new macro that people are going to 
constantly forget about
 - better to invert the logic to use nanosleep only if the C library doesnt 
provide usleep
 - the nanosleep version needs to be a proper complex macro (do {... } while 
(0))-- there are too many problems this one will cause to bother listing
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux