github.com/prattmic/llgo-embedded@v0.0.0-20150820070356-41cfecea0e1e/third_party/gofrontend/libgo/runtime/runtime1.goc (about) 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 5 package runtime 6 #include "runtime.h" 7 #include "arch.h" 8 #include "go-type.h" 9 10 func GOMAXPROCS(n int) (ret int) { 11 ret = runtime_gomaxprocsfunc(n); 12 } 13 14 func NumCPU() (ret int) { 15 ret = runtime_ncpu; 16 } 17 18 func 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 26 func newParFor(nthrmax uint32) (desc *ParFor) { 27 desc = runtime_parforalloc(nthrmax); 28 } 29 30 func parForSetup(desc *ParFor, nthr uint32, n uint32, ctx *byte, wait bool, body *byte) { 31 runtime_parforsetup(desc, nthr, n, ctx, wait, *(void(**)(ParFor*, uint32))body); 32 } 33 34 func parForDo(desc *ParFor) { 35 runtime_parfordo(desc); 36 } 37 38 func parForIters(desc *ParFor, tid uintptr) (start uintptr, end uintptr) { 39 runtime_parforiters(desc, tid, &start, &end); 40 } 41 42 func typestring(e Eface) (s String) { 43 s = *e.__type_descriptor->__reflection; 44 } 45 46 func golockedOSThread() (ret bool) { 47 ret = runtime_lockedOSThread(); 48 } 49 50 func NumGoroutine() (ret int) { 51 ret = runtime_gcount(); 52 } 53 54 func getgoroot() (out String) { 55 const byte *p; 56 57 p = runtime_getenv("GOROOT"); 58 out = runtime_gostringnocopy(p); 59 } 60 61 func runtime_pprof.runtime_cyclesPerSecond() (res int64) { 62 res = runtime_tickspersecond(); 63 } 64 65 func sync.runtime_procPin() (p int) { 66 M *mp; 67 68 mp = runtime_m(); 69 // Disable preemption. 70 mp->locks++; 71 p = mp->p->id; 72 } 73 74 func sync.runtime_procUnpin() { 75 runtime_m()->locks--; 76 } 77 78 func sync_atomic.runtime_procPin() (p int) { 79 M *mp; 80 81 mp = runtime_m(); 82 // Disable preemption. 83 mp->locks++; 84 p = mp->p->id; 85 } 86 87 func sync_atomic.runtime_procUnpin() { 88 runtime_m()->locks--; 89 }