core: add nm_utils_get_monotonic_timestamp_ns_cached() helper

Add a helper function to cache the current timestamp and return
it. The caching is a performance optimization, but it serves a
much more important purpose: repeatedly getting the timestamp
likely will yield different timings. So, commonly, within a
certain context we want to get the current time once, and stick
to that as "now".
This commit is contained in:
Thomas Haller 2018-04-10 15:11:10 +02:00
parent 43dee5f192
commit 4417b8bf3e

View file

@ -239,6 +239,13 @@ gint64 nm_utils_get_monotonic_timestamp_ms (void);
gint32 nm_utils_get_monotonic_timestamp_s (void);
gint64 nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ticks_per_ns);
static inline gint64
nm_utils_get_monotonic_timestamp_ns_cached (gint64 *cache_now)
{
return (*cache_now)
?: (*cache_now = nm_utils_get_monotonic_timestamp_ns ());
}
gboolean nm_utils_is_valid_path_component (const char *name);
const char *NM_ASSERT_VALID_PATH_COMPONENT (const char *name);