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
2243 return 0;2243 return 0;
2244}2244}
2245 2245
2246static __attribute__((unused))
2247int 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
2246static __attribute__((unused))2259static __attribute__((unused))
2247int stat(const char *path, struct stat *buf)2260int stat(const char *path, struct stat *buf)
2248{2261{