Commit eb48bfbb authored by Rob Pike's avatar Rob Pike

runtime.GOMAXPROCS: hack it to have it return the old value.

R=rsc
CC=golang-dev
https://golang.org/cl/1140041
parent 9088f9f2
...@@ -106,8 +106,10 @@ func LockOSThread() ...@@ -106,8 +106,10 @@ func LockOSThread()
func UnlockOSThread() func UnlockOSThread()
// GOMAXPROCS sets the maximum number of CPUs that can be executing // GOMAXPROCS sets the maximum number of CPUs that can be executing
// simultaneously. This call will go away when the scheduler improves. // simultaneously and returns the previous setting. If n < 1, it does not
func GOMAXPROCS(n int) // 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. // Cgocalls returns the number of cgo calls made by the current process.
func Cgocalls() int64 func Cgocalls() int64
......
...@@ -1136,13 +1136,15 @@ void ...@@ -1136,13 +1136,15 @@ void
} }
// delete when scheduler is stronger // delete when scheduler is stronger
void int32
·GOMAXPROCS(int32 n) gomaxprocsfunc(int32 n)
{ {
if(n < 1) int32 ret;
n = 1;
lock(&sched); lock(&sched);
ret = sched.gomaxprocs;
if (n <= 0)
n = ret;
sched.gomaxprocs = n; sched.gomaxprocs = n;
sched.mcpumax = n; sched.mcpumax = n;
// handle fewer procs? // handle fewer procs?
...@@ -1152,11 +1154,12 @@ void ...@@ -1152,11 +1154,12 @@ void
// we'll only get rescheduled once the // we'll only get rescheduled once the
// number has come down. // number has come down.
gosched(); gosched();
return; return ret;
} }
// handle more procs // handle more procs
matchmg(); matchmg();
unlock(&sched); unlock(&sched);
return ret;
} }
void void
......
...@@ -569,6 +569,7 @@ float64 modf(float64 d, float64 *ip); ...@@ -569,6 +569,7 @@ float64 modf(float64 d, float64 *ip);
void semacquire(uint32*); void semacquire(uint32*);
void semrelease(uint32*); void semrelease(uint32*);
String signame(int32 sig); String signame(int32 sig);
int32 gomaxprocsfunc(int32 n);
void mapassign(Hmap*, byte*, byte*); void mapassign(Hmap*, byte*, byte*);
......
...@@ -9,3 +9,6 @@ func mal(n uint32) (ret *uint8) { ...@@ -9,3 +9,6 @@ func mal(n uint32) (ret *uint8) {
ret = mal(n); ret = mal(n);
} }
func GOMAXPROCS(n int32) (ret int32) {
ret = gomaxprocsfunc(n);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment