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