summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorSaya Sugiura <ssugiura@jp.adit-jv.com>2019-01-08 16:45:04 +0900
committerSaya Sugiura <ssugiura@jp.adit-jv.com>2019-05-06 15:55:01 +0900
commitdf6fc2a1ce9f3a1778e9c8e14c800cd2ad96e96e (patch)
tree6356575d4f9e6461769f7b40b72829366feb37b4 /src/examples
parent4fe69b0927f4c5d0cb3b3ae4fa64500db22b13d0 (diff)
downloadDLT-daemon-df6fc2a1ce9f3a1778e9c8e14c800cd2ad96e96e.tar.gz
POSIX: Replace usleep with nanosleep
Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/dlt-example-user-common-api.c12
-rw-r--r--src/examples/dlt-example-user-func.c12
-rw-r--r--src/examples/dlt-example-user.c12
3 files changed, 24 insertions, 12 deletions
diff --git a/src/examples/dlt-example-user-common-api.c b/src/examples/dlt-example-user-common-api.c
index 880ea97..65f3b3c 100644
--- a/src/examples/dlt-example-user-common-api.c
+++ b/src/examples/dlt-example-user-common-api.c
@@ -112,6 +112,7 @@ int main(int argc, char *argv[])
char *text;
int num, maxnum;
int delay;
+ struct timespec ts;
int state = -1, newstate;
@@ -199,9 +200,9 @@ int main(int argc, char *argv[])
maxnum = 10;
if (dvalue)
- delay = atoi(dvalue) * 1000;
+ delay = atoi(dvalue) * 1000000;
else
- delay = 500 * 1000;
+ delay = 500 * 1000000;
if (gflag) {
/* DLT messages to test Fibex non-verbose description: dlt-example-non-verbose.xml */
@@ -258,8 +259,11 @@ int main(int argc, char *argv[])
/* Verbose mode */
DLT_LOG2(mycontext, DLT_LOG_WARN, DLT_INT(num), DLT_STRING(text));
- if (delay > 0)
- usleep(delay);
+ if (delay > 0) {
+ ts.tv_sec = delay / 1000000000;
+ ts.tv_nsec = delay % 1000000000;
+ nanosleep(&ts, NULL);
+ }
}
sleep(1);
diff --git a/src/examples/dlt-example-user-func.c b/src/examples/dlt-example-user-func.c
index b29ff9f..96f98c5 100644
--- a/src/examples/dlt-example-user-func.c
+++ b/src/examples/dlt-example-user-func.c
@@ -118,6 +118,7 @@ int main(int argc, char *argv[])
char *text;
int num, maxnum;
int delay;
+ struct timespec ts;
opterr = 0;
@@ -206,9 +207,9 @@ int main(int argc, char *argv[])
maxnum = 10;
if (dvalue)
- delay = atoi(dvalue) * 1000;
+ delay = atoi(dvalue) * 1000000;
else
- delay = 500 * 1000;
+ delay = 500 * 1000000;
if (gflag) {
/* DLT messages to test Fibex non-verbose description: dlt-example-non-verbose.xml */
@@ -257,8 +258,11 @@ int main(int argc, char *argv[])
dlt_user_log_write_finish(&mycontextdata);
}
- if (delay > 0)
- usleep(delay);
+ if (delay > 0) {
+ ts.tv_sec = delay / 1000000000;
+ ts.tv_nsec = delay % 1000000000;
+ nanosleep(&ts, NULL);
+ }
}
dlt_unregister_context(&mycontext);
diff --git a/src/examples/dlt-example-user.c b/src/examples/dlt-example-user.c
index 19cf73f..45b9561 100644
--- a/src/examples/dlt-example-user.c
+++ b/src/examples/dlt-example-user.c
@@ -142,6 +142,7 @@ int main(int argc, char *argv[])
char *text;
int num, maxnum;
int delay;
+ struct timespec ts;
int state = -1, newstate;
@@ -311,9 +312,9 @@ int main(int argc, char *argv[])
maxnum = 10;
if (dvalue)
- delay = atoi(dvalue) * 1000;
+ delay = atoi(dvalue) * 1000000;
else
- delay = 500 * 1000;
+ delay = 500 * 1000000;
if (tvalue)
dlt_set_resend_timeout_atexit(atoi(tvalue));
@@ -378,8 +379,11 @@ int main(int argc, char *argv[])
DLT_LOG(mycontext1, lvalue, DLT_RAW(text, rvalue));
}
- if (delay > 0)
- usleep(delay);
+ if (delay > 0) {
+ ts.tv_sec = delay / 1000000000;
+ ts.tv_nsec = delay % 1000000000;
+ nanosleep(&ts, NULL);
+ }
}
sleep(1);