]> Cypherpunks.ru repositories - gostls13.git/blob - src/runtime/runtime.go
runtime: remove a few untyped allocations
[gostls13.git] / src / runtime / runtime.go
1 // Copyright 2009 The Go Authors.  All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package runtime
6
7 var ticks struct {
8         lock mutex
9         val  uint64
10 }
11
12 // Note: Called by runtime/pprof in addition to runtime code.
13 func tickspersecond() int64 {
14         r := int64(atomicload64(&ticks.val))
15         if r != 0 {
16                 return r
17         }
18         lock(&ticks.lock)
19         r = int64(ticks.val)
20         if r == 0 {
21                 t0 := nanotime()
22                 c0 := cputicks()
23                 usleep(100 * 1000)
24                 t1 := nanotime()
25                 c1 := cputicks()
26                 if t1 == t0 {
27                         t1++
28                 }
29                 r = (c1 - c0) * 1000 * 1000 * 1000 / (t1 - t0)
30                 if r == 0 {
31                         r++
32                 }
33                 atomicstore64(&ticks.val, uint64(r))
34         }
35         unlock(&ticks.lock)
36         return r
37 }
38
39 func makeStringSlice(n int) []string {
40         return make([]string, n)
41 }