Browse Source

Make start_timer() and stop_timer() robust against incorrect usage.

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
66a7ed23cb
2 changed files with 12 additions and 2 deletions
  1. 4
    1
      src/include/gpxe/retry.h
  2. 8
    1
      src/net/retry.c

+ 4
- 1
src/include/gpxe/retry.h View File

15
 	struct list_head list;
15
 	struct list_head list;
16
 	/** Timeout value (in ticks) */
16
 	/** Timeout value (in ticks) */
17
 	unsigned long timeout;
17
 	unsigned long timeout;
18
-	/** Start time (in ticks) */
18
+	/** Start time (in ticks)
19
+	 *
20
+	 * A start time of zero indicates a stopped timer.
21
+	 */
19
 	unsigned long start;
22
 	unsigned long start;
20
 	/** Retry count */
23
 	/** Retry count */
21
 	unsigned int count;
24
 	unsigned int count;

+ 8
- 1
src/net/retry.c View File

64
  * be stopped and the timer's callback function will be called.
64
  * be stopped and the timer's callback function will be called.
65
  */
65
  */
66
 void start_timer ( struct retry_timer *timer ) {
66
 void start_timer ( struct retry_timer *timer ) {
67
+	if ( ! timer->start )
68
+		list_add ( &timer->list, &timers );
67
 	timer->start = currticks();
69
 	timer->start = currticks();
68
 	if ( timer->timeout < MIN_TIMEOUT )
70
 	if ( timer->timeout < MIN_TIMEOUT )
69
 		timer->timeout = MIN_TIMEOUT;
71
 		timer->timeout = MIN_TIMEOUT;
70
-	list_add ( &timer->list, &timers );
71
 	DBG2 ( "Timer %p started\n", timer );
72
 	DBG2 ( "Timer %p started\n", timer );
72
 }
73
 }
73
 
74
 
82
 	unsigned long old_timeout = timer->timeout;
83
 	unsigned long old_timeout = timer->timeout;
83
 	unsigned long runtime;
84
 	unsigned long runtime;
84
 
85
 
86
+	/* If timer was already stopped, do nothing */
87
+	if ( ! timer->start )
88
+		return;
89
+
85
 	DBG2 ( "Timer %p stopped\n", timer );
90
 	DBG2 ( "Timer %p stopped\n", timer );
86
 	list_del ( &timer->list );
91
 	list_del ( &timer->list );
87
 	runtime = currticks() - timer->start;
92
 	runtime = currticks() - timer->start;
93
+	timer->start = 0;
88
 
94
 
89
 	/* Update timer.  Variables are:
95
 	/* Update timer.  Variables are:
90
 	 *
96
 	 *
124
 	/* Stop timer without performing RTT calculations */
130
 	/* Stop timer without performing RTT calculations */
125
 	DBG2 ( "Timer %p stopped on expiry\n", timer );
131
 	DBG2 ( "Timer %p stopped on expiry\n", timer );
126
 	list_del ( &timer->list );
132
 	list_del ( &timer->list );
133
+	timer->start = 0;
127
 	timer->count++;
134
 	timer->count++;
128
 
135
 
129
 	/* Back off the timeout value */
136
 	/* Back off the timeout value */

Loading…
Cancel
Save