From cf66174cf95ec2628400730cfea3cb5953a42bde Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Tue, 27 Sep 2022 20:28:29 +0800 Subject: [PATCH] add function fc_sleep_us --- HISTORY | 3 +++ src/shared_func.h | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/HISTORY b/HISTORY index b0f2d31..81f0bda 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,7 @@ +Version 1.62 2022-09-27 + * add function fc_sleep_us + Version 1.61 2022-09-21 * get_base_path_from_conf_file_ex support parameter: noent_log_level * add function common_blocked_queue_push_chain diff --git a/src/shared_func.h b/src/shared_func.h index 7756d52..5f93cf3 100644 --- a/src/shared_func.h +++ b/src/shared_func.h @@ -1176,6 +1176,23 @@ bool fc_path_contains(const string_t *path, const string_t *needle, int *result); +/** sleep in microseconds + * parameters: + * microseconds: microseconds to sleep + * return: 0 for success, != 0 for fail +*/ +static inline int fc_sleep_us(const int microseconds) +{ + struct timespec ts; + ts.tv_sec = microseconds / (1000 * 1000); + ts.tv_nsec = (microseconds % (1000 * 1000)) * 1000; + if (nanosleep(&ts, NULL) == 0) { + return 0; + } else { + return errno != 0 ? errno : EINVAL; + } +} + /** sleep in milliseconds * parameters: * milliseconds: milliseconds to sleep