|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [UNIKRAFT/APPHELLOWORLD PATCH 2/6] Use nanosleep
Introduces `millisleep()` in order to enable shorter sleep times than in
seconds.
Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
main.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/main.c b/main.c
index a0d6a73..4d4210e 100644
--- a/main.c
+++ b/main.c
@@ -1,11 +1,13 @@
#include <stdio.h>
-#include <unistd.h>
#include <uk/essentials.h>
/* Import user configuration: */
#include <uk/config.h>
#if CONFIG_APPHELLOWORLD_SPINNER
+#include <time.h>
+#include <errno.h>
+
static const char *spinner[] = {
">))'> ",
" >))'> ",
@@ -20,6 +22,18 @@ static const char *spinner[] = {
" <'((< ",
"<'((< ",
};
+
+static void millisleep(unsigned int millisec)
+{
+ struct timespec ts;
+ int ret;
+
+ ts.tv_sec = millisec / 1000;
+ ts.tv_nsec = (millisec % 1000) * 1000000;
+ do
+ ret = nanosleep(&ts, &ts);
+ while (ret && errno == EINTR);
+}
#endif /* CONFIG_APPHELLOWORLD_SPINNER */
int main(int argc, char *argv[])
@@ -43,7 +57,7 @@ int main(int argc, char *argv[])
while (1) {
i %= ARRAY_SIZE(spinner);
printf("\r%s", spinner[i++]);
- sleep(1);
+ millisleep(1000);
}
#endif /* CONFIG_APPHELLOWORLD_SPINNER */
}
--
2.20.1
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |