diff options
author | Saya Sugiura <ssugiura@jp.adit-jv.com> | 2019-01-08 16:45:04 +0900 |
---|---|---|
committer | Saya Sugiura <ssugiura@jp.adit-jv.com> | 2019-05-06 15:55:01 +0900 |
commit | df6fc2a1ce9f3a1778e9c8e14c800cd2ad96e96e (patch) | |
tree | 6356575d4f9e6461769f7b40b72829366feb37b4 /src/lib | |
parent | 4fe69b0927f4c5d0cb3b3ae4fa64500db22b13d0 (diff) | |
download | DLT-daemon-df6fc2a1ce9f3a1778e9c8e14c800cd2ad96e96e.tar.gz |
POSIX: Replace usleep with nanosleep
Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/dlt_filetransfer.c | 8 | ||||
-rw-r--r-- | src/lib/dlt_user.c | 17 | ||||
-rw-r--r-- | src/lib/dlt_user_cfg.h | 8 |
3 files changed, 25 insertions, 8 deletions
diff --git a/src/lib/dlt_filetransfer.c b/src/lib/dlt_filetransfer.c index 7844de2..736a7d6 100644 --- a/src/lib/dlt_filetransfer.c +++ b/src/lib/dlt_filetransfer.c @@ -68,6 +68,9 @@ #define DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES INT_MAX +#define NANOSEC_PER_MILLISEC 1000000 +#define NANOSEC_PER_SEC 1000000000 + /*!Buffer for dlt file transfer. The size is defined by BUFFER_SIZE */ unsigned char buffer[BUFFER_SIZE]; @@ -194,7 +197,10 @@ int isFile (const char *file) */ void doTimeout(int timeout) { - usleep(timeout * 1000); + struct timespec ts; + ts.tv_sec = (timeout * NANOSEC_PER_MILLISEC) / NANOSEC_PER_SEC; + ts.tv_nsec = (timeout * NANOSEC_PER_MILLISEC) % NANOSEC_PER_SEC; + nanosleep(&ts, NULL); } /*!Checks free space of the user buffer */ diff --git a/src/lib/dlt_user.c b/src/lib/dlt_user.c index 1c1bbd8..1bddcfa 100644 --- a/src/lib/dlt_user.c +++ b/src/lib/dlt_user.c @@ -733,6 +733,7 @@ int dlt_user_atexit_blow_out_user_buffer(void) { int count, ret; + struct timespec ts; uint32_t exitTime = dlt_uptime() + dlt_user.timeout_at_exit_handler; @@ -770,7 +771,9 @@ int dlt_user_atexit_blow_out_user_buffer(void) } } - usleep(DLT_USER_ATEXIT_RESEND_BUFFER_SLEEP); + ts.tv_sec = 0; + ts.tv_nsec = DLT_USER_ATEXIT_RESEND_BUFFER_SLEEP; + nanosleep(&ts, NULL); } DLT_SEM_LOCK(); @@ -2786,6 +2789,7 @@ DltReturnValue dlt_user_trace_network_segmented_segment(uint32_t id, void *payload) { int ret = DLT_RETURN_ERROR; + struct timespec ts; if ((nw_trace_type < DLT_NW_TRACE_IPC) || (nw_trace_type >= DLT_NW_TRACE_MAX)) { dlt_vlog(LOG_ERR, "Network trace type %d is outside valid range", nw_trace_type); @@ -2793,7 +2797,10 @@ DltReturnValue dlt_user_trace_network_segmented_segment(uint32_t id, } while (check_buffer() < 0) { - usleep(1000 * 50); /* Wait 50ms */ + /* Wait 50ms */ + ts.tv_sec = 0; + ts.tv_nsec = 1000000*50; + nanosleep(&ts, NULL); dlt_user_log_resend_buffer(); } @@ -3478,6 +3485,7 @@ DltReturnValue dlt_disable_local_print(void) void dlt_user_receiverthread_function(__attribute__((unused)) void *ptr) { + struct timespec ts; #ifdef linux prctl(PR_SET_NAME, "dlt_receiver", 0, 0, 0); #endif @@ -3488,7 +3496,10 @@ void dlt_user_receiverthread_function(__attribute__((unused)) void *ptr) /* Critical error */ dlt_log(LOG_CRIT, "Receiver thread encountered error condition\n"); - usleep(DLT_USER_RECEIVE_DELAY); /* delay */ + /* delay */ + ts.tv_sec = 0; + ts.tv_nsec = DLT_USER_RECEIVE_NDELAY; + nanosleep(&ts, NULL); } } diff --git a/src/lib/dlt_user_cfg.h b/src/lib/dlt_user_cfg.h index 5e43ee0..6d27ea0 100644 --- a/src/lib/dlt_user_cfg.h +++ b/src/lib/dlt_user_cfg.h @@ -128,8 +128,8 @@ /* default message id for non-verbose mode, if no message id was provided */ #define DLT_USER_DEFAULT_MSGID 0xffff -/* delay in receiver routine in usec (100000 usec = 100ms) */ -#define DLT_USER_RECEIVE_DELAY 100000 +/* delay for receiver thread (nsec) */ +#define DLT_USER_RECEIVE_NDELAY (100000000) /* Name of environment variable for local print mode */ #define DLT_USER_ENV_LOCAL_PRINT_MODE "DLT_LOCAL_PRINT_MODE" @@ -137,8 +137,8 @@ /* Timeout offset for resending user buffer at exit in 10th milliseconds (10000 = 1s)*/ #define DLT_USER_ATEXIT_RESEND_BUFFER_EXIT_TIMEOUT 100000 -/* Sleeps between resending user buffer at exit in usec (1000 usec = 1ms)*/ -#define DLT_USER_ATEXIT_RESEND_BUFFER_SLEEP 100000 +/* Sleeps between resending user buffer at exit in nsec (1000000 nsec = 1ms)*/ +#define DLT_USER_ATEXIT_RESEND_BUFFER_SLEEP 100000000 /* Retry interval for mq error in usec */ #define DLT_USER_MQ_ERROR_RETRY_INTERVAL 100000 |