ソースを参照

[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 15年前
コミット
f945d6d201
2個のファイルの変更12行の追加9行の削除
  1. 4
    5
      src/include/gpxe/retry.h
  2. 8
    4
      src/net/retry.c

+ 4
- 5
src/include/gpxe/retry.h ファイルの表示

@@ -19,6 +19,8 @@
19 19
 struct retry_timer {
20 20
 	/** List of active timers */
21 21
 	struct list_head list;
22
+	/** Timer is currently running */
23
+	unsigned int running;
22 24
 	/** Timeout value (in ticks) */
23 25
 	unsigned long timeout;
24 26
 	/** Minimum timeout value (in ticks)
@@ -31,10 +33,7 @@ struct retry_timer {
31 33
 	 * A value of zero means "use default timeout."
32 34
 	 */
33 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 37
 	unsigned long start;
39 38
 	/** Retry count */
40 39
 	unsigned int count;
@@ -74,7 +73,7 @@ static inline void start_timer_nodelay ( struct retry_timer *timer ) {
74 73
  */
75 74
 static inline __attribute__ (( always_inline )) unsigned long
76 75
 timer_running ( struct retry_timer *timer ) {
77
-	return ( timer->start );
76
+	return ( timer->running );
78 77
 }
79 78
 
80 79
 #endif /* _GPXE_RETRY_H */

+ 8
- 4
src/net/retry.c ファイルの表示

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

読み込み中…
キャンセル
保存