OSDN Git Service

sleep: tiny code shrink
authorDenys Vlasenko <dvlasenk@redhat.com>
Fri, 22 Oct 2010 13:46:04 +0000 (15:46 +0200)
committerDenys Vlasenko <dvlasenk@redhat.com>
Fri, 22 Oct 2010 13:46:04 +0000 (15:46 +0200)
...or rather, it WILL BE code shrink when gcc become clever enough
to not emit a second, useless XORing of ebx:

31 db                  xor    %ebx,%ebx
85 c0                  test   %eax,%eax
74 11                  je     73 <__GI_sleep+0x73>
31 db                  xor    %ebx,%ebx    <=== ?!

Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
libc/unistd/sleep.c

index 438f5e2..6a237e3 100644 (file)
@@ -82,6 +82,10 @@ unsigned int sleep (unsigned int seconds)
 
     /* Run nanosleep, with SIGCHLD blocked if SIGCHLD is SIG_IGNed.  */
     result = nanosleep (&ts, &ts);
+    if (result != 0) {
+       /* Got EINTR. Return remaining time.  */
+       result = (unsigned int) ts.tv_sec + (ts.tv_nsec >= 500000000L);
+    }
 
     if (!__sigismember (&set, SIGCHLD)) {
        /* We did block SIGCHLD, and old mask had no SIGCHLD bit.
@@ -91,10 +95,6 @@ unsigned int sleep (unsigned int seconds)
        sigprocmask (SIG_SETMASK, &set, NULL); /* never fails */
     }
 
-    if (result != 0)
-       /* Round remaining time.  */
-       result = (unsigned int) ts.tv_sec + (ts.tv_nsec >= 500000000L);
-
     return result;
 }
 #endif