]> Cypherpunks repositories - gostls13.git/commitdiff
runtime.GOMAXPROCS: hack it to have it return the old value.
authorRob Pike <r@golang.org>
Thu, 6 May 2010 18:50:47 +0000 (11:50 -0700)
committerRob Pike <r@golang.org>
Thu, 6 May 2010 18:50:47 +0000 (11:50 -0700)
R=rsc
CC=golang-dev
https://golang.org/cl/1140041

src/pkg/runtime/extern.go
src/pkg/runtime/proc.c
src/pkg/runtime/runtime.h
src/pkg/runtime/runtime1.goc

index 1e284e8d711dd751d804b75537240df4f2117a17..72b43ae9bd7f77d0407041dd168d97914dca6c44 100644 (file)
@@ -106,8 +106,10 @@ func LockOSThread()
 func UnlockOSThread()
 
 // GOMAXPROCS sets the maximum number of CPUs that can be executing
-// simultaneously.   This call will go away when the scheduler improves.
-func GOMAXPROCS(n int)
+// simultaneously and returns the previous setting.  If n < 1, it does not
+// change the current setting.
+// This call will go away when the scheduler improves.
+func GOMAXPROCS(n int) int
 
 // Cgocalls returns the number of cgo calls made by the current process.
 func Cgocalls() int64
index acbb3afa156fb110d2d2df2e621a9c3442e8f3e3..0fef16aa6e5a0cdb0b9681b6a0fae424124db98b 100644 (file)
@@ -1136,13 +1136,15 @@ void
 }
 
 // delete when scheduler is stronger
-void
-·GOMAXPROCS(int32 n)
+int32
+gomaxprocsfunc(int32 n)
 {
-       if(n < 1)
-               n = 1;
+       int32 ret;
 
        lock(&sched);
+       ret = sched.gomaxprocs;
+       if (n <= 0)
+               n = ret;
        sched.gomaxprocs = n;
        sched.mcpumax = n;
        // handle fewer procs?
@@ -1152,11 +1154,12 @@ void
                // we'll only get rescheduled once the
                // number has come down.
                gosched();
-               return;
+               return ret;
        }
        // handle more procs
        matchmg();
        unlock(&sched);
+       return ret;
 }
 
 void
index 4c9f52e85c0ce9d27dc89d90cf6ca5044e5c505b..9c08796ed36093da2e29d0d23188c2eb2fc8faf1 100644 (file)
@@ -569,6 +569,7 @@ float64     modf(float64 d, float64 *ip);
 void   semacquire(uint32*);
 void   semrelease(uint32*);
 String signame(int32 sig);
+int32  gomaxprocsfunc(int32 n);
 
 
 void   mapassign(Hmap*, byte*, byte*);
index 7e5f323c12bca6df939016654e73a12057009f47..64178e98c9b861f064fd0af71f311da031f25cee 100644 (file)
@@ -9,3 +9,6 @@ func mal(n uint32) (ret *uint8) {
        ret = mal(n);
 }
 
+func GOMAXPROCS(n int32) (ret int32) {
+       ret = gomaxprocsfunc(n);
+}