diff options
Diffstat (limited to 'shared/nm-glib-aux/nm-time-utils.c')
-rw-r--r-- | shared/nm-glib-aux/nm-time-utils.c | 82 |
1 files changed, 41 insertions, 41 deletions
diff --git a/shared/nm-glib-aux/nm-time-utils.c b/shared/nm-glib-aux/nm-time-utils.c index 20d663bc02..6afaf05aa3 100644 --- a/shared/nm-glib-aux/nm-time-utils.c +++ b/shared/nm-glib-aux/nm-time-utils.c @@ -40,19 +40,19 @@ _t_init_global_state (void) /* The only failure we tolerate is that CLOCK_BOOTTIME is not supported. * Other than that, we rely on kernel to not fail on this. */ g_assert (r == 0); - g_assert (tp.tv_nsec >= 0 && tp.tv_nsec < NM_UTILS_NS_PER_SECOND); + g_assert (tp.tv_nsec >= 0 && tp.tv_nsec < NM_UTILS_NSEC_PER_SEC); /* Calculate an offset for the time stamp. * * We always want positive values, because then we can initialize * a timestamp with 0 and be sure, that it will be less then any * value nm_utils_get_monotonic_timestamp_*() might return. - * For this to be true also for nm_utils_get_monotonic_timestamp_s() at + * For this to be true also for nm_utils_get_monotonic_timestamp_sec() at * early boot, we have to shift the timestamp to start counting at * least from 1 second onward. * * Another advantage of shifting is, that this way we make use of the whole 31 bit - * range of signed int, before the time stamp for nm_utils_get_monotonic_timestamp_s() + * range of signed int, before the time stamp for nm_utils_get_monotonic_timestamp_sec() * wraps (~68 years). **/ offset_sec = (- ((gint64) tp.tv_sec)) + 1; @@ -96,7 +96,7 @@ _t_init_global_state (void) _r = clock_gettime (_p2->clk_id, _tp); \ \ nm_assert (_r == 0); \ - nm_assert (_tp->tv_nsec >= 0 && _tp->tv_nsec < NM_UTILS_NS_PER_SECOND); \ + nm_assert (_tp->tv_nsec >= 0 && _tp->tv_nsec < NM_UTILS_NSEC_PER_SEC); \ \ _p2; \ }) @@ -107,7 +107,7 @@ _t_init_global_state (void) /*****************************************************************************/ /** - * nm_utils_get_monotonic_timestamp_ns: + * nm_utils_get_monotonic_timestamp_nsec: * * Returns: a monotonically increasing time stamp in nanoseconds, * starting at an unspecified offset. See clock_gettime(), %CLOCK_BOOTTIME. @@ -115,11 +115,11 @@ _t_init_global_state (void) * 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 + * All the nm_utils_get_monotonic_timestamp_*sec functions return the same * timestamp but in different scales (nsec, usec, msec, sec). **/ gint64 -nm_utils_get_monotonic_timestamp_ns (void) +nm_utils_get_monotonic_timestamp_nsec (void) { const GlobalState *p; struct timespec tp; @@ -130,12 +130,12 @@ nm_utils_get_monotonic_timestamp_ns (void) * integer, which makes it easier to calculate time differences (when * you want to subtract signed values). **/ - return (((gint64) tp.tv_sec) + p->offset_sec) * NM_UTILS_NS_PER_SECOND + + return (((gint64) tp.tv_sec) + p->offset_sec) * NM_UTILS_NSEC_PER_SEC + tp.tv_nsec; } /** - * nm_utils_get_monotonic_timestamp_us: + * nm_utils_get_monotonic_timestamp_usec: * * Returns: a monotonically increasing time stamp in microseconds, * starting at an unspecified offset. See clock_gettime(), %CLOCK_BOOTTIME. @@ -143,11 +143,11 @@ nm_utils_get_monotonic_timestamp_ns (void) * 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 + * All the nm_utils_get_monotonic_timestamp_*sec functions return the same * timestamp but in different scales (nsec, usec, msec, sec). **/ gint64 -nm_utils_get_monotonic_timestamp_us (void) +nm_utils_get_monotonic_timestamp_usec (void) { const GlobalState *p; struct timespec tp; @@ -159,11 +159,11 @@ nm_utils_get_monotonic_timestamp_us (void) * you want to subtract signed values). **/ return (((gint64) tp.tv_sec) + p->offset_sec) * ((gint64) G_USEC_PER_SEC) + - (tp.tv_nsec / (NM_UTILS_NS_PER_SECOND/G_USEC_PER_SEC)); + (tp.tv_nsec / (NM_UTILS_NSEC_PER_SEC/G_USEC_PER_SEC)); } /** - * nm_utils_get_monotonic_timestamp_ms: + * nm_utils_get_monotonic_timestamp_msec: * * Returns: a monotonically increasing time stamp in milliseconds, * starting at an unspecified offset. See clock_gettime(), %CLOCK_BOOTTIME. @@ -171,11 +171,11 @@ nm_utils_get_monotonic_timestamp_us (void) * 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 + * All the nm_utils_get_monotonic_timestamp_*sec functions return the same * timestamp but in different scales (nsec, usec, msec, sec). **/ gint64 -nm_utils_get_monotonic_timestamp_ms (void) +nm_utils_get_monotonic_timestamp_msec (void) { const GlobalState *p; struct timespec tp; @@ -187,23 +187,23 @@ nm_utils_get_monotonic_timestamp_ms (void) * you want to subtract signed values). **/ return (((gint64) tp.tv_sec) + p->offset_sec) * ((gint64) 1000) + - (tp.tv_nsec / (NM_UTILS_NS_PER_SECOND/1000)); + (tp.tv_nsec / (NM_UTILS_NSEC_PER_SEC/1000)); } /** - * nm_utils_get_monotonic_timestamp_s: + * nm_utils_get_monotonic_timestamp_sec: * - * Returns: nm_utils_get_monotonic_timestamp_ms() in seconds (throwing + * Returns: nm_utils_get_monotonic_timestamp_msec() in seconds (throwing * away sub second parts). The returned value will always be positive. * * This value wraps after roughly 68 years which should be fine for any * practical purpose. * - * All the nm_utils_get_monotonic_timestamp_*s functions return the same + * All the nm_utils_get_monotonic_timestamp_*sec functions return the same * timestamp but in different scales (nsec, usec, msec, sec). **/ gint32 -nm_utils_get_monotonic_timestamp_s (void) +nm_utils_get_monotonic_timestamp_sec (void) { const GlobalState *p; struct timespec tp; @@ -216,13 +216,13 @@ nm_utils_get_monotonic_timestamp_s (void) /** * nm_utils_monotonic_timestamp_as_boottime: * @timestamp: the monotonic-timestamp that should be converted into CLOCK_BOOTTIME. - * @timestamp_ns_per_tick: How many nanoseconds make one unit of @timestamp? E.g. if - * @timestamp is in unit seconds, pass %NM_UTILS_NS_PER_SECOND; if @timestamp is - * in nanoseconds, pass 1; if @timestamp is in milliseconds, pass %NM_UTILS_NS_PER_SECOND/1000. - * This must be a multiple of 10, and between 1 and %NM_UTILS_NS_PER_SECOND. + * @timestamp_nsec_per_tick: How many nanoseconds make one unit of @timestamp? E.g. if + * @timestamp is in unit seconds, pass %NM_UTILS_NSEC_PER_SEC; if @timestamp is + * in nanoseconds, pass 1; if @timestamp is in milliseconds, pass %NM_UTILS_NSEC_PER_SEC/1000. + * This must be a multiple of 10, and between 1 and %NM_UTILS_NSEC_PER_SEC. * * Returns: the monotonic-timestamp as CLOCK_BOOTTIME, as returned by clock_gettime(). - * The unit is the same as the passed in @timestamp based on @timestamp_ns_per_tick. + * The unit is the same as the passed in @timestamp based on @timestamp_nsec_per_tick. * E.g. if you passed @timestamp in as seconds, it will return boottime in seconds. * * Note that valid monotonic-timestamps are always positive numbers (counting roughly since @@ -234,16 +234,16 @@ nm_utils_get_monotonic_timestamp_s (void) * On older kernels that don't support CLOCK_BOOTTIME, the returned time is instead CLOCK_MONOTONIC. **/ gint64 -nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ns_per_tick) +nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_nsec_per_tick) { const GlobalState *p; gint64 offset; - /* only support ns-per-tick being a multiple of 10. */ - g_return_val_if_fail (timestamp_ns_per_tick == 1 - || (timestamp_ns_per_tick > 0 && - timestamp_ns_per_tick <= NM_UTILS_NS_PER_SECOND && - timestamp_ns_per_tick % 10 == 0), + /* only support nsec-per-tick being a multiple of 10. */ + g_return_val_if_fail ( timestamp_nsec_per_tick == 1 + || (timestamp_nsec_per_tick > 0 && + timestamp_nsec_per_tick <= NM_UTILS_NSEC_PER_SEC && + timestamp_nsec_per_tick % 10 == 0), -1); /* if the caller didn't yet ever fetch a monotonic-timestamp, he cannot pass any meaningful @@ -255,7 +255,7 @@ nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ns_ nm_assert (p->offset_sec <= 0); /* calculate the offset of monotonic-timestamp to boottime. offset_s is <= 1. */ - offset = p->offset_sec * (NM_UTILS_NS_PER_SECOND / timestamp_ns_per_tick); + offset = p->offset_sec * (NM_UTILS_NSEC_PER_SEC / timestamp_nsec_per_tick); nm_assert (offset <= 0 && offset > G_MININT64); @@ -270,9 +270,9 @@ nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ns_ * @boottime: the timestamp from CLOCK_BOOTTIME (or CLOCK_MONOTONIC, if * kernel does not support CLOCK_BOOTTIME and monotonic timestamps are based * on CLOCK_MONOTONIC). - * @timestamp_ns_per_tick: the scale in which @boottime is. If @boottime is in + * @timestamp_nsec_per_tick: the scale in which @boottime is. If @boottime is in * nano seconds, this should be 1. If it is in milli seconds, this should be - * %NM_UTILS_NS_PER_SECOND/1000, etc. + * %NM_UTILS_NSEC_PER_SEC/1000, etc. * * Returns: the same timestamp in monotonic timestamp scale. * @@ -284,16 +284,16 @@ nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ns_ * This is the inverse of nm_utils_monotonic_timestamp_as_boottime(). */ gint64 -nm_utils_monotonic_timestamp_from_boottime (guint64 boottime, gint64 timestamp_ns_per_tick) +nm_utils_monotonic_timestamp_from_boottime (guint64 boottime, gint64 timestamp_nsec_per_tick) { const GlobalState *p; gint64 offset; - /* only support ns-per-tick being a multiple of 10. */ - g_return_val_if_fail (timestamp_ns_per_tick == 1 - || (timestamp_ns_per_tick > 0 && - timestamp_ns_per_tick <= NM_UTILS_NS_PER_SECOND && - timestamp_ns_per_tick % 10 == 0), + /* only support nsec-per-tick being a multiple of 10. */ + g_return_val_if_fail ( timestamp_nsec_per_tick == 1 + || (timestamp_nsec_per_tick > 0 && + timestamp_nsec_per_tick <= NM_UTILS_NSEC_PER_SEC && + timestamp_nsec_per_tick % 10 == 0), -1); p = _t_get_global_state (); @@ -301,7 +301,7 @@ nm_utils_monotonic_timestamp_from_boottime (guint64 boottime, gint64 timestamp_n nm_assert (p->offset_sec <= 0); /* calculate the offset of monotonic-timestamp to boottime. offset_s is <= 1. */ - offset = p->offset_sec * (NM_UTILS_NS_PER_SECOND / timestamp_ns_per_tick); + offset = p->offset_sec * (NM_UTILS_NSEC_PER_SEC / timestamp_nsec_per_tick); nm_assert (offset <= 0 && offset > G_MININT64); |