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.
This commit is contained in:
Kim Woelders 2015-01-16 06:49:35 +01:00
parent eedd3f6789
commit cd095e1637
5 changed files with 21 additions and 6 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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

View File

@ -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))
;
}

View File

@ -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_ */