summaryrefslogtreecommitdiffstats
path: root/lib/qtime.c
diff options
context:
space:
mode:
authorChris Hall <chris.hall@highwayman.com>2011-03-29 14:22:37 +0100
committerChris Hall <chris.hall@highwayman.com>2011-03-29 14:22:37 +0100
commit7e666be965b3ac61b05ccdeca2b61902bc26e172 (patch)
treedc4c1b7985b1aa3dfd16b59c70567f62ab535fd6 /lib/qtime.c
parentf9956b9524ddafdb9d0cec042213eaa8229aad8c (diff)
parente20f7ccd9e110fcd5deb945f8d23922efd8b0822 (diff)
downloadquagga-ex16p.tar.bz2
quagga-ex16p.tar.xz
Merge branch 'master' of /git/quagga.euro-ix into pipeworkex16p
This ensures that the two branches are consistent after the merging of the old-Quagga 0.99.18 changes. Release: 0.99.18ex16p. Eliminated some whitespace differences ! Collected RESTRICTED_NODE show_bgp_ipv6_safi_route_cmd and show_bgp_ipv6_safi_prefix_cmd, and one HAVE_IPV6 skip. Also releasing filename in closezlog(). Removed strlen() from lib/qfstring.c for async-signal-safe purposes.
Diffstat (limited to 'lib/qtime.c')
-rw-r--r--lib/qtime.c33
1 files changed, 27 insertions, 6 deletions
diff --git a/lib/qtime.c b/lib/qtime.c
index 789ced1e..d1283198 100644
--- a/lib/qtime.c
+++ b/lib/qtime.c
@@ -72,15 +72,37 @@
* (But seems unlikely that such a system would not support CLOCK_MONOTONIC !)
*
* When clock_t is a 32-bit integer must be at least ready for wrap around.
- * There are two cases:
+ * We take the clock_t signed values and widen to 64-bit signed, so we have
+ * the current sample (this) and the previous one (last), and two cases to
+ * consider:
*
- * * +ve wrap around. new < old value, and new >= 0
+ * * +ve wrap around -- so value is 31-bit unsigned, and wraps from large
+ * +ve value to small +ve value.
*
- * step = (INT32_MAX - old + 1) + new
+ * step = this - last will be -ve
*
- * * -ve wrap around. new < old value, and new < 0 (and old > 0)
+ * 'last' will be some value ((INT32_MAX + 1) - x), and 'this' will be some
+ * (relatively) small value y. The step is x + y, we have:
*
- * step = (INT32_MAX - old + 1) - (INT32_MIN - new)
+ * step = y - ((INT32_MAX + 1) - x) = (x + y) - (INT32_MAX + 1)
+ *
+ * so we correct by adding (INT32_MAX + 1).
+ *
+ * * -ve wrap around -- so value is 32-bit signed, and wraps from a large
+ * +ve value to a very -ve value.
+ *
+ * step = this - last will be -ve
+ *
+ * 'last will' be some value (INT32_MAX + 1) - x, and 'this' will be some
+ * value (y - (INT32_MAX + 1)). The step is x + y, we have:
+ *
+ * step = (y - (INT32_MAX + 1)) - ((INT32_MAX + 1) - x)
+ * = (x + y) - 2 * (INT32_MAX + 1)
+ *
+ * so we correct by adding (INT32_MAX + 1).
+ *
+ * In both cases the wrap around gives an apparently -ve 'step', and that is
+ * corrected by adding (INT32_MAX + 1) until it goes +ve.
*
* In any event, a step > 24 hours is taken to means that something has gone
* very, very badly wrong.
@@ -340,4 +362,3 @@ qt_random(uint32_t seed)
* or the last entry, and have done with it.
*/
-