2017-03-02 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libgo / go / runtime / runtime.go
blobe63130b1496a0e9297333e67043b952db67aab31
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.
5 package runtime
7 import (
8 "runtime/internal/atomic"
9 _ "unsafe" // for go:linkname
12 //go:generate go run wincallback.go
13 //go:generate go run mkduff.go
14 //go:generate go run mkfastlog2table.go
16 // For gccgo, while we still have C runtime code, use go:linkname to
17 // rename some functions to themselves, so that the compiler will
18 // export them.
20 //go:linkname tickspersecond runtime.tickspersecond
22 var ticks struct {
23 lock mutex
24 pad uint32 // ensure 8-byte alignment of val on 386
25 val uint64
28 // Note: Called by runtime/pprof in addition to runtime code.
29 func tickspersecond() int64 {
30 r := int64(atomic.Load64(&ticks.val))
31 if r != 0 {
32 return r
34 lock(&ticks.lock)
35 r = int64(ticks.val)
36 if r == 0 {
37 t0 := nanotime()
38 c0 := cputicks()
39 usleep(100 * 1000)
40 t1 := nanotime()
41 c1 := cputicks()
42 if t1 == t0 {
43 t1++
45 r = (c1 - c0) * 1000 * 1000 * 1000 / (t1 - t0)
46 if r == 0 {
47 r++
49 atomic.Store64(&ticks.val, uint64(r))
51 unlock(&ticks.lock)
52 return r
55 var envs []string
56 var argslice []string
58 //go:linkname syscall_runtime_envs syscall.runtime_envs
59 func syscall_runtime_envs() []string { return append([]string{}, envs...) }
61 //go:linkname syscall_Getpagesize syscall.Getpagesize
62 func syscall_Getpagesize() int { return int(physPageSize) }
64 //go:linkname os_runtime_args os.runtime_args
65 func os_runtime_args() []string { return append([]string{}, argslice...) }
67 // Temporary, for the gccgo runtime code written in C.
68 //go:linkname get_envs runtime_get_envs
69 func get_envs() []string { return envs }
71 //go:linkname get_args runtime_get_args
72 func get_args() []string { return argslice }