1/* -*- c-basic-offset: 8; -*- */ 2#include <sys/types.h> 3#include <sys/time.h> 4#include <errno.h> 5#include <stddef.h> 6#include "ourhdr.h" 7 8void 9sleep_us(unsigned int nusecs) 10{ 11 struct timeval tval; 12 13 for ( ; ; ) { 14 tval.tv_sec = nusecs / 1000000; 15 tval.tv_usec = nusecs % 1000000; 16 if (select(0, NULL, NULL, NULL, &tval) == 0) 17 break; /* all OK */ 18 /* 19 * Note than on an interrupted system call (i.e, SIGIO) there's not 20 * much we can do, since the timeval{} isn't updated with the time 21 * remaining. We could obtain the clock time before the call, and 22 * then obtain the clock time here, subtracting them to determine 23 * how long select() blocked before it was interrupted, but that 24 * seems like too much work :-) 25 */ 26 if (errno == EINTR) 27 continue; 28 err_sys("sleep_us: select error"); 29 } 30} 31