diff options
| author | Rob Pike <r@golang.org> | 2010-05-06 11:50:47 -0700 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2010-05-06 11:50:47 -0700 |
| commit | eb48bfbbdaf3a99dbb861f251a73a3b6ae45cc8b (patch) | |
| tree | 8cb9b76a517a019f77bc2f00c2a7b2c59bf7c9c5 /src/pkg | |
| parent | 9088f9f245e432f9f87ae8cfe46b9d36dbcf1a2e (diff) | |
| download | go-eb48bfbbdaf3a99dbb861f251a73a3b6ae45cc8b.tar.xz | |
runtime.GOMAXPROCS: hack it to have it return the old value.
R=rsc
CC=golang-dev
https://golang.org/cl/1140041
Diffstat (limited to 'src/pkg')
| -rw-r--r-- | src/pkg/runtime/extern.go | 6 | ||||
| -rw-r--r-- | src/pkg/runtime/proc.c | 13 | ||||
| -rw-r--r-- | src/pkg/runtime/runtime.h | 1 | ||||
| -rw-r--r-- | src/pkg/runtime/runtime1.goc | 3 |
4 files changed, 16 insertions, 7 deletions
diff --git a/src/pkg/runtime/extern.go b/src/pkg/runtime/extern.go index 1e284e8d71..72b43ae9bd 100644 --- a/src/pkg/runtime/extern.go +++ b/src/pkg/runtime/extern.go @@ -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 diff --git a/src/pkg/runtime/proc.c b/src/pkg/runtime/proc.c index acbb3afa15..0fef16aa6e 100644 --- a/src/pkg/runtime/proc.c +++ b/src/pkg/runtime/proc.c @@ -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 diff --git a/src/pkg/runtime/runtime.h b/src/pkg/runtime/runtime.h index 4c9f52e85c..9c08796ed3 100644 --- a/src/pkg/runtime/runtime.h +++ b/src/pkg/runtime/runtime.h @@ -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*); diff --git a/src/pkg/runtime/runtime1.goc b/src/pkg/runtime/runtime1.goc index 7e5f323c12..64178e98c9 100644 --- a/src/pkg/runtime/runtime1.goc +++ b/src/pkg/runtime/runtime1.goc @@ -9,3 +9,6 @@ func mal(n uint32) (ret *uint8) { ret = mal(n); } +func GOMAXPROCS(n int32) (ret int32) { + ret = gomaxprocsfunc(n); +} |
