kwo pushed a commit to branch master.

http://git.enlightenment.org/e16/e16.git/commit/?id=cd095e16370e45687d943c98c2463e2fb046afeb

commit cd095e16370e45687d943c98c2463e2fb046afeb
Author: Kim Woelders <k...@woelders.dk>
Date:   Fri Jan 16 06:49:35 2015 +0100

    Eliminate deprecated usleep().
    
    SleepUs() will even sleep the correct amount of time when interrupted by
    a signal.
    There shouldn't be any significant cases where this could be a problem
    though.
---
 src/alert.c      |  8 ++++----
 src/extinitwin.c |  2 +-
 src/iconify.c    |  2 +-
 src/time.c       | 13 +++++++++++++
 src/util.h       |  2 ++
 5 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/alert.c b/src/alert.c
index 1708ccc..c934b91 100644
--- a/src/alert.c
+++ b/src/alert.c
@@ -332,7 +332,7 @@ ShowAlert(const char *title,
        XMoveResizeWindow(dd, win, x, y, w, h);
        DRAW_BOX_OUT(dd, gc, win, 0, 0, w, h);
        XSync(dd, False);
-       usleep(20000);
+       SleepUs(20000);
      }
    x = (wid - ww) >> 1;
    y = (hih - hh) >> 1;
@@ -393,7 +393,7 @@ ShowAlert(const char *title,
               {
                  DRAW_BOX_IN(dd, gc, b1, 0, 0, bw, bh);
                  XSync(dd, False);
-                 usleep(500000);
+                 SleepUs(500000);
                  DRAW_BOX_OUT(dd, gc, b1, 0, 0, bw, bh);
                  button = 1;
                  goto do_sync;
@@ -403,7 +403,7 @@ ShowAlert(const char *title,
               {
                  DRAW_BOX_IN(dd, gc, b2, 0, 0, bw, bh);
                  XSync(dd, False);
-                 usleep(500000);
+                 SleepUs(500000);
                  DRAW_BOX_OUT(dd, gc, b2, 0, 0, bw, bh);
                  button = 2;
                  goto do_sync;
@@ -413,7 +413,7 @@ ShowAlert(const char *title,
               {
                  DRAW_BOX_IN(dd, gc, b3, 0, 0, bw, bh);
                  XSync(dd, False);
-                 usleep(500000);
+                 SleepUs(500000);
                  DRAW_BOX_OUT(dd, gc, b3, 0, 0, bw, bh);
                  button = 3;
                  goto do_sync;
diff --git a/src/extinitwin.c b/src/extinitwin.c
index 12ba87f..e72f972 100644
--- a/src/extinitwin.c
+++ b/src/extinitwin.c
@@ -231,7 +231,7 @@ ExtInitWinMain(void)
                EImageFree(im);
             }
           ESync(0);
-          usleep(50000);
+          SleepUs(50000);
 
           /* If we still are here after 5 sec something is wrong. */
           if (loop > 100)
diff --git a/src/iconify.c b/src/iconify.c
index 9fbef93..018921e 100644
--- a/src/iconify.c
+++ b/src/iconify.c
@@ -59,7 +59,7 @@ IB_Animate_Sleep(unsigned int t0, float a)
    dt = 1e-3 * (t - a * IB_ANIM_TIME);
    dt = 1e-3 * IB_ANIM_STEP - dt;
    if (dt > 0)
-      usleep((unsigned long)(1e6 * dt));
+      SleepUs((unsigned long)(1e6 * dt));
 }
 
 static void
diff --git a/src/time.c b/src/time.c
index ca27300..1d0e4ff 100644
--- a/src/time.c
+++ b/src/time.c
@@ -65,3 +65,16 @@ GetTimeUs(void)
    return (unsigned int)(timev.tv_sec * 1000000 + timev.tv_usec);
 #endif
 }
+
+void
+SleepUs(unsigned int tus)
+{
+   struct timespec     ts;
+
+   ts.tv_sec = tus / 1000000;
+   tus -= ts.tv_sec * 1000000;
+   ts.tv_nsec = tus * 1000;
+
+   while (nanosleep(&ts, &ts))
+      ;
+}
diff --git a/src/util.h b/src/util.h
index e6337bd..82030df 100644
--- a/src/util.h
+++ b/src/util.h
@@ -129,4 +129,6 @@ const void         *ModLoadSym(const char *lib, const char 
*sym,
 unsigned int        GetTimeMs(void);
 unsigned int        GetTimeUs(void);
 
+void                SleepUs(unsigned int tus);
+
 #endif /* _UTIL_H_ */

-- 


Reply via email to