runtime1.goc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. package runtime
  5. #include "runtime.h"
  6. #include "arch.h"
  7. #include "go-type.h"
  8. func GOMAXPROCS(n int) (ret int) {
  9. ret = runtime_gomaxprocsfunc(n);
  10. }
  11. func NumCPU() (ret int) {
  12. ret = runtime_ncpu;
  13. }
  14. func NumCgoCall() (ret int64) {
  15. M *mp;
  16. ret = 0;
  17. for(mp=runtime_atomicloadp(&runtime_allm); mp; mp=mp->alllink)
  18. ret += mp->ncgocall;
  19. }
  20. func newParFor(nthrmax uint32) (desc *ParFor) {
  21. desc = runtime_parforalloc(nthrmax);
  22. }
  23. func parForSetup(desc *ParFor, nthr uint32, n uint32, ctx *byte, wait bool, body *byte) {
  24. runtime_parforsetup(desc, nthr, n, ctx, wait, *(void(**)(ParFor*, uint32))body);
  25. }
  26. func parForDo(desc *ParFor) {
  27. runtime_parfordo(desc);
  28. }
  29. func parForIters(desc *ParFor, tid uintptr) (start uintptr, end uintptr) {
  30. runtime_parforiters(desc, tid, &start, &end);
  31. }
  32. func typestring(e Eface) (s String) {
  33. s = *e.__type_descriptor->__reflection;
  34. }
  35. func golockedOSThread() (ret bool) {
  36. ret = runtime_lockedOSThread();
  37. }
  38. func NumGoroutine() (ret int) {
  39. ret = runtime_gcount();
  40. }
  41. func getgoroot() (out String) {
  42. const byte *p;
  43. p = runtime_getenv("GOROOT");
  44. out = runtime_gostringnocopy(p);
  45. }
  46. func runtime_pprof.runtime_cyclesPerSecond() (res int64) {
  47. res = runtime_tickspersecond();
  48. }
  49. func sync.runtime_procPin() (p int) {
  50. M *mp;
  51. mp = runtime_m();
  52. // Disable preemption.
  53. mp->locks++;
  54. p = mp->p->id;
  55. }
  56. func sync.runtime_procUnpin() {
  57. runtime_m()->locks--;
  58. }
  59. func sync_atomic.runtime_procPin() (p int) {
  60. M *mp;
  61. mp = runtime_m();
  62. // Disable preemption.
  63. mp->locks++;
  64. p = mp->p->id;
  65. }
  66. func sync_atomic.runtime_procUnpin() {
  67. runtime_m()->locks--;
  68. }