1// Copyright 2010 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
5package runtime
6#include "runtime.h"
7#include "arch.h"
8#include "go-type.h"
9
10func GOMAXPROCS(n int) (ret int) {
11	ret = runtime_gomaxprocsfunc(n);
12}
13
14func NumCPU() (ret int) {
15	ret = runtime_ncpu;
16}
17
18func NumCgoCall() (ret int64) {
19	M *mp;
20
21	ret = 0;
22	for(mp=runtime_atomicloadp(&runtime_allm); mp; mp=mp->alllink)
23		ret += mp->ncgocall;
24}
25
26func newParFor(nthrmax uint32) (desc *ParFor) {
27	desc = runtime_parforalloc(nthrmax);
28}
29
30func parForSetup(desc *ParFor, nthr uint32, n uint32, wait bool, body *byte) {
31	runtime_parforsetup(desc, nthr, n, wait, (const FuncVal*) body);
32}
33
34func parForDo(desc *ParFor) {
35	runtime_parfordo(desc);
36}
37
38func parForIters(desc *ParFor, tid uintptr) (start uintptr, end uintptr) {
39	runtime_parforiters(desc, tid, &start, &end);
40}
41
42func typestring(e Eface) (s String) {
43	s = *e.__type_descriptor->__reflection;
44}
45
46func golockedOSThread() (ret bool) {
47	ret = runtime_lockedOSThread();
48}
49
50func NumGoroutine() (ret int) {
51	ret = runtime_gcount();
52}
53
54func getgoroot() (out String) {
55	out = runtime_getenv("GOROOT");
56}
57
58func runtime_pprof.runtime_cyclesPerSecond() (res int64) {
59	res = runtime_tickspersecond();
60}
61
62func sync.runtime_procPin() (p int) {
63	M *mp;
64
65	mp = runtime_m();
66	// Disable preemption.
67	mp->locks++;
68	p = mp->p->id;
69}
70
71func sync.runtime_procUnpin() {
72	runtime_m()->locks--;
73}
74
75func sync_atomic.runtime_procPin() (p int) {
76	M *mp;
77
78	mp = runtime_m();
79	// Disable preemption.
80	mp->locks++;
81	p = mp->p->id;
82}
83
84func sync_atomic.runtime_procUnpin() {
85	runtime_m()->locks--;
86}
87
88extern Slice envs;
89
90func envs() (s Slice) {
91	s = envs;
92}
93
94func setenvs(e Slice) {
95	envs = e;
96}
97