core: add nm_utils_get_monotonic_timestamp_ns() function
Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
@@ -1050,6 +1050,33 @@ monotonic_timestamp_get (struct timespec *tp)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_get_monotonic_timestamp_ns:
|
||||
*
|
||||
* Returns: a monotonically increasing time stamp in nanoseconds,
|
||||
* starting at an unspecified offset. See clock_gettime(), %CLOCK_BOOTTIME.
|
||||
*
|
||||
* The returned value will start counting at an undefined point
|
||||
* in the past and will always be positive.
|
||||
*
|
||||
* All the nm_utils_get_monotonic_timestamp_*s functions return the same
|
||||
* timestamp but in different scales (nsec, usec, msec, sec).
|
||||
**/
|
||||
gint64
|
||||
nm_utils_get_monotonic_timestamp_ns (void)
|
||||
{
|
||||
struct timespec tp;
|
||||
|
||||
monotonic_timestamp_get (&tp);
|
||||
|
||||
/* Although the result will always be positive, we return a signed
|
||||
* integer, which makes it easier to calculate time differences (when
|
||||
* you want to subtract signed values).
|
||||
**/
|
||||
return (((gint64) tp.tv_sec) + monotonic_timestamp_offset_sec) * NM_UTILS_NS_PER_SECOND +
|
||||
tp.tv_nsec;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_utils_get_monotonic_timestamp_us:
|
||||
*
|
||||
|
@@ -104,6 +104,7 @@ NMConnection *nm_utils_match_connection (GSList *connections,
|
||||
gint64 nm_utils_ascii_str_to_int64 (const char *str, guint base, gint64 min, gint64 max, gint64 fallback);
|
||||
|
||||
#define NM_UTILS_NS_PER_SECOND ((gint64) 1000000000)
|
||||
gint64 nm_utils_get_monotonic_timestamp_ns (void);
|
||||
gint64 nm_utils_get_monotonic_timestamp_us (void);
|
||||
gint64 nm_utils_get_monotonic_timestamp_ms (void);
|
||||
gint32 nm_utils_get_monotonic_timestamp_s (void);
|
||||
|
Reference in New Issue
Block a user