File tree Expand file tree Collapse file tree 3 files changed +50
-10
lines changed Expand file tree Collapse file tree 3 files changed +50
-10
lines changed Original file line number Diff line number Diff line change @@ -183,8 +183,7 @@ func findSigpanic() *runtime.Func {
183
183
func () int {
184
184
defer func () {
185
185
if p := recover (); p != nil {
186
- pcs := pcStackPool .Get ().([]uintptr )
187
- pcs = pcs [:cap (pcs )]
186
+ pcs := getUintptrs ()
188
187
n := runtime .Callers (2 , pcs )
189
188
for _ , pc := range pcs [:n ] {
190
189
f := runtime .FuncForPC (pc )
@@ -193,7 +192,7 @@ func findSigpanic() *runtime.Func {
193
192
break
194
193
}
195
194
}
196
- pcStackPool . Put (pcs )
195
+ putUintptrs (pcs )
197
196
}
198
197
}()
199
198
// intentional division by zero fault
@@ -208,19 +207,14 @@ var (
208
207
spOnce sync.Once
209
208
)
210
209
211
- var pcStackPool = sync.Pool {
212
- New : func () interface {} { return make ([]uintptr , 1000 ) },
213
- }
214
-
215
210
// Trace returns a CallStack for the current goroutine with element 0
216
211
// identifying the calling function.
217
212
func Trace () CallStack {
218
213
spOnce .Do (func () {
219
214
sigpanic = findSigpanic ()
220
215
})
221
216
222
- pcs := pcStackPool .Get ().([]uintptr )
223
- pcs = pcs [:cap (pcs )]
217
+ pcs := getUintptrs ()
224
218
225
219
n := runtime .Callers (2 , pcs )
226
220
cs := make ([]Call , n )
@@ -236,7 +230,7 @@ func Trace() CallStack {
236
230
}
237
231
}
238
232
239
- pcStackPool . Put (pcs )
233
+ putUintptrs (pcs )
240
234
241
235
return cs
242
236
}
Original file line number Diff line number Diff line change
1
+ // +build !go1.3
2
+
3
+ package stack
4
+
5
+ import (
6
+ "runtime"
7
+ )
8
+
9
+ func getUintptrs () []uintptr {
10
+ select {
11
+ case s := <- pcStackPool :
12
+ return s [:cap (s )]
13
+ default :
14
+ return make ([]uintptr , 1000 )
15
+ }
16
+ }
17
+
18
+ func putUintptrs (s []uintptr ) {
19
+ select {
20
+ case pcStackPool <- s :
21
+ default :
22
+ }
23
+ }
24
+
25
+ var pcStackPool = make (chan []uintptr , runtime .GOMAXPROCS (n ))
Original file line number Diff line number Diff line change
1
+ // +build go1.3
2
+
3
+ package stack
4
+
5
+ import (
6
+ "sync"
7
+ )
8
+
9
+ func getUintptrs () []uintptr {
10
+ s := pcStackPool .Get ().([]uintptr )
11
+ s = s [:cap (s )]
12
+ return s
13
+ }
14
+
15
+ func putUintptrs (s []uintptr ) {
16
+ pcStackPool .Put (s )
17
+ }
18
+
19
+ var pcStackPool = sync.Pool {
20
+ New : func () interface {} { return make ([]uintptr , 1000 ) },
21
+ }
You can’t perform that action at this time.
0 commit comments