OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Time-related runtime and pieces of package time. | 5 // Time-related runtime and pieces of package time. |
6 | 6 |
7 package time | 7 package time |
8 | 8 |
9 #include "runtime.h" | 9 #include "runtime.h" |
10 #include "defs_GOOS_GOARCH.h" | 10 #include "defs_GOOS_GOARCH.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 124 } |
125 | 125 |
126 // Delete timer t from the heap. | 126 // Delete timer t from the heap. |
127 // Do not need to update the timerproc: | 127 // Do not need to update the timerproc: |
128 // if it wakes up early, no big deal. | 128 // if it wakes up early, no big deal. |
129 bool | 129 bool |
130 runtime·deltimer(Timer *t) | 130 runtime·deltimer(Timer *t) |
131 { | 131 { |
132 int32 i; | 132 int32 i; |
133 | 133 |
| 134 // Dereference t so that any panic happens before the lock is held. |
| 135 // Discard result, because t might be moving in the heap. |
| 136 i = t->i; |
| 137 USED(i); |
| 138 |
134 runtime·lock(&timers); | 139 runtime·lock(&timers); |
135 | 140 |
136 // t may not be registered anymore and may have | 141 // t may not be registered anymore and may have |
137 // a bogus i (typically 0, if generated by Go). | 142 // a bogus i (typically 0, if generated by Go). |
138 // Verify it before proceeding. | 143 // Verify it before proceeding. |
139 i = t->i; | 144 i = t->i; |
140 if(i < 0 || i >= timers.len || timers.t[i] != t) { | 145 if(i < 0 || i >= timers.len || timers.t[i] != t) { |
141 runtime·unlock(&timers); | 146 runtime·unlock(&timers); |
142 return false; | 147 return false; |
143 } | 148 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 if(t[c]->when >= t[i]->when) | 260 if(t[c]->when >= t[i]->when) |
256 break; | 261 break; |
257 tmp = t[i]; | 262 tmp = t[i]; |
258 t[i] = t[c]; | 263 t[i] = t[c]; |
259 t[c] = tmp; | 264 t[c] = tmp; |
260 t[i]->i = i; | 265 t[i]->i = i; |
261 t[c]->i = c; | 266 t[c]->i = c; |
262 i = c; | 267 i = c; |
263 } | 268 } |
264 } | 269 } |
OLD | NEW |