[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Correct "advance-time" logic



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv14237/src/or

Modified Files:
	rephist.c 
Log Message:
Correct "advance-time" logic

Index: rephist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/rephist.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- rephist.c	20 Jul 2004 20:57:46 -0000	1.15
+++ rephist.c	20 Jul 2004 23:25:00 -0000	1.16
@@ -378,10 +378,15 @@
 /** Add 'n' bytes to the number of bytes in b for second 'when'.
  */
 static INLINE void add_obs(bw_array_t *b, time_t when, int n) {
-  /* If we're currently adding observations for an earlier second than 'when',
-   * advance 'when' by an appropriate number of seconds. */
-  while (when<b->cur_obs_time)
+  /* Don't record data in the past. */
+  if (when<b->cur_obs_time)
+    return;
+  /* If we're currently adding observations for an earlier second than
+   * 'when', advance b->cur_obs_time and b->cur_obs_idx by an
+   * appropriate number of seconds, and do all the other housekeeping */
+  while (when>b->cur_obs_time)
     advance_obs(b);
+
   b->obs[b->cur_obs_idx] += n;
 }