Re: [PATCH] replace usleep()

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

 



On Mon, Aug 17, 2009 at 10:50:26PM +0200, Daniel Mierswa wrote:
> 
> This function is marked obsolete in POSIX.1-2001 and removed in
> POSIX.1-2008.
> 
> Replaced with nanosleep().

 [...]

> diff --git a/hwclock/kd.c b/hwclock/kd.c
> index 3b5708a..3e718e2 100644
> --- a/hwclock/kd.c
> +++ b/hwclock/kd.c
> @@ -17,6 +17,7 @@ probe_for_kd_clock() {
>  #include <sys/ioctl.h>
>  
>  #include "nls.h"
> +#include "usleep.h"
>  
>  static int con_fd = -1;		/* opened by probe_for_kd_clock() */
>  				/* never closed */
> @@ -66,12 +67,7 @@ synchronize_to_clock_tick_kd(void) {
>      /* Christian T. Steigies: 1 instead of 1000000 is still sufficient
>         to keep the machine from freezing. */
>  
> -#ifdef HAVE_NANOSLEEP
> -    struct timespec xsleep = { 0, 1 };

 Uf, ... this is strange code. It seems like pretty expensive busy
 wait. It would be better to implement this by gettimeofday() (like in
 busywait_for_rtc_clock_tick()). I'll fix it tomorrow.

> -    nanosleep( &xsleep, NULL );
> -#else
> -    usleep(1);
> -#endif
> +	usleep(1);

 [...]

> +++ b/include/usleep.h
> @@ -0,0 +1,18 @@
> +#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) \

 What about:

 static inline usleep(unsigned it usec) 
 {

> +	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 */
> diff --git a/login-utils/shutdown.c b/login-utils/shutdown.c
> index 58600b9..ae9c35a 100644
> --- a/login-utils/shutdown.c
> +++ b/login-utils/shutdown.c
> @@ -76,6 +76,7 @@
>  #include "pathnames.h"
>  #include "xstrncpy.h"
>  #include "nls.h"
> +#include "usleep.h"
>  
>  static void usage(void), int_handler(int), write_user(struct utmp *);
>  static void wall(void), write_wtmp(void), unmount_disks(void);
> @@ -391,7 +392,7 @@ main(int argc, char *argv[])
>  	stop_finalprog ();
>  	sleep (1);                    /*  Time for saves to start           */
>  	kill (1, SIGTERM);            /*  Tell init to kill spawned gettys  */
> -	usleep (100000);              /*  Wait for gettys to die            */
> +	usleep (100000);

 This is unwanted change, right? ;-)

    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[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