From df6fc2a1ce9f3a1778e9c8e14c800cd2ad96e96e Mon Sep 17 00:00:00 2001 From: Saya Sugiura Date: Tue, 8 Jan 2019 16:45:04 +0900 Subject: POSIX: Replace usleep with nanosleep Signed-off-by: Saya Sugiura --- examples/example1/example1.c | 6 +++++- examples/example2/example2.c | 5 ++++- examples/example3/example3.c | 5 ++++- examples/example4/example4.c | 5 ++++- 4 files changed, 17 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/example1/example1.c b/examples/example1/example1.c index 2784a82..9248ecb 100644 --- a/examples/example1/example1.c +++ b/examples/example1/example1.c @@ -54,13 +54,17 @@ DLT_DECLARE_CONTEXT(con_exa1); int main() { + struct timespec ts; + DLT_REGISTER_APP("EXA1", "First Example"); DLT_REGISTER_CONTEXT(con_exa1, "CON", "First context"); DLT_LOG(con_exa1, DLT_LOG_INFO, DLT_STRING("Hello world!")); - usleep(1000); + ts.tv_sec = 0; + ts.tv_nsec = 1000000; + nanosleep(&ts, NULL); DLT_UNREGISTER_CONTEXT(con_exa1); diff --git a/examples/example2/example2.c b/examples/example2/example2.c index 445f60a..7a25353 100644 --- a/examples/example2/example2.c +++ b/examples/example2/example2.c @@ -57,6 +57,7 @@ DLT_DECLARE_CONTEXT(con_exa2); int main() { int num; + struct timespec ts; DLT_REGISTER_APP("EXA2", "Third Example"); DLT_REGISTER_CONTEXT(con_exa2, "CON", "First context"); @@ -67,7 +68,9 @@ int main() DLT_LOG_ID(con_exa2, DLT_LOG_INFO, DLT_EXA2_CON_EXA2_ID1, DLT_INT32(12345678), DLT_STRING("Hello world 1!")); DLT_LOG_ID(con_exa2, DLT_LOG_ERROR, DLT_EXA2_CON_EXA2_ID2, DLT_INT32(87654321), DLT_STRING("Hello world 2!")); DLT_LOG_ID(con_exa2, DLT_LOG_WARN, DLT_EXA2_CON_EXA2_ID3, DLT_INT32(11223344), DLT_STRING("Hello world 3!")); - usleep(1000); + ts.tv_sec = 0; + ts.tv_nsec = 1000000; + nanosleep(&ts, NULL); } DLT_UNREGISTER_CONTEXT(con_exa2); diff --git a/examples/example3/example3.c b/examples/example3/example3.c index d686ec1..5a74ef1 100644 --- a/examples/example3/example3.c +++ b/examples/example3/example3.c @@ -57,6 +57,7 @@ DLT_DECLARE_CONTEXT(con_exa3); int main() { int num; + struct timespec ts; DLT_REGISTER_APP("EXA3", "Third Example"); DLT_REGISTER_CONTEXT(con_exa3, "CON", "First context"); @@ -67,7 +68,9 @@ int main() DLT_LOG_ID(con_exa3, DLT_LOG_INFO, DLT_EXA3_CON_EXA3_ID1, DLT_INT32(12345678), DLT_CSTRING("Hello world 1!")); DLT_LOG_ID(con_exa3, DLT_LOG_ERROR, DLT_EXA3_CON_EXA3_ID2, DLT_INT32(87654321), DLT_CSTRING("Hello world 2!")); DLT_LOG_ID(con_exa3, DLT_LOG_WARN, DLT_EXA3_CON_EXA3_ID3, DLT_INT32(11223344), DLT_CSTRING("Hello world 3!")); - usleep(1000); + ts.tv_sec = 0; + ts.tv_nsec = 1000000; + nanosleep(&ts, NULL); } DLT_UNREGISTER_CONTEXT(con_exa3); diff --git a/examples/example4/example4.c b/examples/example4/example4.c index 59aef18..afaffe3 100644 --- a/examples/example4/example4.c +++ b/examples/example4/example4.c @@ -56,6 +56,7 @@ int main() { unsigned char buffer[256]; int num; + struct timespec ts; DLT_REGISTER_APP("EXA4", "Fourth Example"); @@ -98,7 +99,9 @@ int main() DLT_LOG(con_exa1, DLT_LOG_INFO, DLT_STRING("DLT_BIN16")); DLT_LOG(con_exa1, DLT_LOG_INFO, DLT_BIN16(bin16data)); - usleep(1000); + ts.tv_sec = 0; + ts.tv_nsec = 1000000; + nanosleep(&ts, NULL); DLT_UNREGISTER_CONTEXT(con_exa1); -- cgit v1.2.1