]> Cypherpunks.ru repositories - gostls13.git/blob - src/runtime/runtime.go
cmd/cc, cmd/ld, runtime: disallow conservative data/bss objects
[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 var tls0 [8]uintptr // available storage for m0's TLS; not necessarily used; opaque to GC
13
14 // Note: Called by runtime/pprof in addition to runtime code.
15 func tickspersecond() int64 {
16         r := int64(atomicload64(&ticks.val))
17         if r != 0 {
18                 return r
19         }
20         lock(&ticks.lock)
21         r = int64(ticks.val)
22         if r == 0 {
23                 t0 := nanotime()
24                 c0 := cputicks()
25                 usleep(100 * 1000)
26                 t1 := nanotime()
27                 c1 := cputicks()
28                 if t1 == t0 {
29                         t1++
30                 }
31                 r = (c1 - c0) * 1000 * 1000 * 1000 / (t1 - t0)
32                 if r == 0 {
33                         r++
34                 }
35                 atomicstore64(&ticks.val, uint64(r))
36         }
37         unlock(&ticks.lock)
38         return r
39 }
40
41 func makeStringSlice(n int) []string {
42         return make([]string, n)
43 }
44
45 // TODO: Move to parfor.go when parfor.c becomes parfor.go.
46 func parforalloc(nthrmax uint32) *parfor {
47         return &parfor{
48                 thr:     &make([]parforthread, nthrmax)[0],
49                 nthrmax: nthrmax,
50         }
51 }
52
53 var envs []string
54 var argslice []string
55
56 // called from syscall
57 func runtime_envs() []string { return envs }
58
59 // called from os
60 func runtime_args() []string { return argslice }