Browse Source

[retry] Use a separate flag to indicate that a retry timer is running

Using start==0 to indicate a stopped timer is dangerous, because 0 is a
valid value for the current tick counter.
tags/v0.9.6
Michael Brown 16 years ago
parent
commit
f945d6d201
2 changed files with 12 additions and 9 deletions
  1. 4
    5
      src/include/gpxe/retry.h
  2. 8
    4
      src/net/retry.c

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

19
 struct retry_timer {
19
 struct retry_timer {
20
 	/** List of active timers */
20
 	/** List of active timers */
21
 	struct list_head list;
21
 	struct list_head list;
22
+	/** Timer is currently running */
23
+	unsigned int running;
22
 	/** Timeout value (in ticks) */
24
 	/** Timeout value (in ticks) */
23
 	unsigned long timeout;
25
 	unsigned long timeout;
24
 	/** Minimum timeout value (in ticks)
26
 	/** Minimum timeout value (in ticks)
31
 	 * A value of zero means "use default timeout."
33
 	 * A value of zero means "use default timeout."
32
 	 */
34
 	 */
33
 	unsigned long max_timeout;
35
 	unsigned long max_timeout;
34
-	/** Start time (in ticks)
35
-	 *
36
-	 * A start time of zero indicates a stopped timer.
37
-	 */
36
+	/** Start time (in ticks) */
38
 	unsigned long start;
37
 	unsigned long start;
39
 	/** Retry count */
38
 	/** Retry count */
40
 	unsigned int count;
39
 	unsigned int count;
74
  */
73
  */
75
 static inline __attribute__ (( always_inline )) unsigned long
74
 static inline __attribute__ (( always_inline )) unsigned long
76
 timer_running ( struct retry_timer *timer ) {
75
 timer_running ( struct retry_timer *timer ) {
77
-	return ( timer->start );
76
+	return ( timer->running );
78
 }
77
 }
79
 
78
 
80
 #endif /* _GPXE_RETRY_H */
79
 #endif /* _GPXE_RETRY_H */

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

55
  * be stopped and the timer's callback function will be called.
55
  * be stopped and the timer's callback function will be called.
56
  */
56
  */
57
 void start_timer ( struct retry_timer *timer ) {
57
 void start_timer ( struct retry_timer *timer ) {
58
-	if ( ! timer_running ( timer ) )
58
+	if ( ! timer->running )
59
 		list_add ( &timer->list, &timers );
59
 		list_add ( &timer->list, &timers );
60
 	timer->start = currticks();
60
 	timer->start = currticks();
61
+	timer->running = 1;
61
 
62
 
62
 	/* 0 means "use default timeout" */
63
 	/* 0 means "use default timeout" */
63
 	if ( timer->min_timeout == 0 )
64
 	if ( timer->min_timeout == 0 )
82
 void start_timer_fixed ( struct retry_timer *timer, unsigned long timeout ) {
83
 void start_timer_fixed ( struct retry_timer *timer, unsigned long timeout ) {
83
 	start_timer ( timer );
84
 	start_timer ( timer );
84
 	timer->timeout = timeout;
85
 	timer->timeout = timeout;
86
+	DBG2 ( "Timer %p expiry time changed to %ld\n",
87
+	       timer, ( timer->start + timer->timeout ) );
85
 }
88
 }
86
 
89
 
87
 /**
90
 /**
97
 	unsigned long runtime;
100
 	unsigned long runtime;
98
 
101
 
99
 	/* If timer was already stopped, do nothing */
102
 	/* If timer was already stopped, do nothing */
100
-	if ( ! timer_running ( timer ) )
103
+	if ( ! timer->running )
101
 		return;
104
 		return;
102
 
105
 
103
 	list_del ( &timer->list );
106
 	list_del ( &timer->list );
104
 	runtime = ( now - timer->start );
107
 	runtime = ( now - timer->start );
105
-	timer->start = 0;
108
+	timer->running = 0;
106
 	DBG2 ( "Timer %p stopped at time %ld (ran for %ld)\n",
109
 	DBG2 ( "Timer %p stopped at time %ld (ran for %ld)\n",
107
 	       timer, now, runtime );
110
 	       timer, now, runtime );
108
 
111
 
144
 	/* Stop timer without performing RTT calculations */
147
 	/* Stop timer without performing RTT calculations */
145
 	DBG2 ( "Timer %p stopped at time %ld on expiry\n",
148
 	DBG2 ( "Timer %p stopped at time %ld on expiry\n",
146
 	       timer, currticks() );
149
 	       timer, currticks() );
150
+	assert ( timer->running );
147
 	list_del ( &timer->list );
151
 	list_del ( &timer->list );
148
-	timer->start = 0;
152
+	timer->running = 0;
149
 	timer->count++;
153
 	timer->count++;
150
 
154
 
151
 	/* Back off the timeout value */
155
 	/* Back off the timeout value */

Loading…
Cancel
Save