History

tools/nolibc: Implement msleep()

Allow users to implement shorter delays than a full second by implementing msleep().

Mark Brown committed 5 years ago

Commit f916d771 parent 9a83f9a1 file · +13 −0Browse files

Showing the changes to tools/include (1 of 1 file). Show all

Unified · Split

tools/include/nolibc/nolibc.h+13−0
@@ -2243,6 +2243,19 @@ unsigned int sleep(unsigned int seconds) · 2242 unmodified lines
22432243 return 0;
22442244 }
22452245
2246+static __attribute__((unused))
2247+int msleep(unsigned int msecs)
2248+{
2249+ struct timeval my_timeval = { msecs / 1000, (msecs % 1000) * 1000 };
2250+
2251+ if (sys_select(0, 0, 0, 0, &my_timeval) < 0)
2252+ return (my_timeval.tv_sec * 1000) +
2253+ (my_timeval.tv_usec / 1000) +
2254+ !!(my_timeval.tv_usec % 1000);
2255+ else
2256+ return 0;
2257+}
2258+
22462259 static __attribute__((unused))
22472260 int stat(const char *path, struct stat *buf)
22482261 {