Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(786)

Delta Between Two Patch Sets: src/pkg/runtime/time.goc

Issue 10373047: code review 10373047: runtime: prevent a panic from leaving the timer mutex held (Closed)
Left Patch Set: diff -r 29818ed2e3f7 http://code.google.com/p/go Created 10 years, 9 months ago
Right Patch Set: diff -r 166d946fa77f http://code.google.com/p/go Created 10 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/time/sleep_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 123 }
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
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);
133 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;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b