summaryrefslogtreecommitdiff
path: root/src/pkg/sync
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/sync')
-rw-r--r--src/pkg/sync/internal_test.go15
-rw-r--r--src/pkg/sync/mutex.go21
-rw-r--r--src/pkg/sync/mutex_test.go9
3 files changed, 16 insertions, 29 deletions
diff --git a/src/pkg/sync/internal_test.go b/src/pkg/sync/internal_test.go
deleted file mode 100644
index b365f79e9..000000000
--- a/src/pkg/sync/internal_test.go
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2009 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-// expose internals for testing
-
-package sync
-
-func Semacquire(s *int32) {
- semacquire(s);
-}
-
-func Semrelease(s *int32) {
- semrelease(s);
-}
diff --git a/src/pkg/sync/mutex.go b/src/pkg/sync/mutex.go
index 23691aa33..309970f1e 100644
--- a/src/pkg/sync/mutex.go
+++ b/src/pkg/sync/mutex.go
@@ -8,23 +8,24 @@
// is better done via channels and communication.
package sync
-func cas(val *int32, old, new int32) bool
-func semacquire(*int32)
-func semrelease(*int32)
+import "runtime"
+
+func cas(val *uint32, old, new uint32) bool
// A Mutex is a mutual exclusion lock.
// Mutexes can be created as part of other structures;
// the zero value for a Mutex is an unlocked mutex.
type Mutex struct {
- key int32;
- sema int32;
+ key uint32;
+ sema uint32;
}
-func xadd(val *int32, delta int32) (new int32) {
+func xadd(val *uint32, delta int32) (new uint32) {
for {
v := *val;
- if cas(val, v, v+delta) {
- return v+delta;
+ nv := v+uint32(delta);
+ if cas(val, v, nv) {
+ return nv;
}
}
panic("unreached");
@@ -38,7 +39,7 @@ func (m *Mutex) Lock() {
// changed from 0 to 1; we hold lock
return;
}
- semacquire(&m.sema);
+ runtime.Semacquire(&m.sema);
}
// Unlock unlocks m.
@@ -52,7 +53,7 @@ func (m *Mutex) Unlock() {
// changed from 1 to 0; no contention
return;
}
- semrelease(&m.sema);
+ runtime.Semrelease(&m.sema);
}
// Stub implementation of r/w locks.
diff --git a/src/pkg/sync/mutex_test.go b/src/pkg/sync/mutex_test.go
index 2944a20fb..d7be79fff 100644
--- a/src/pkg/sync/mutex_test.go
+++ b/src/pkg/sync/mutex_test.go
@@ -7,20 +7,21 @@
package sync_test
import (
+ "runtime";
. "sync";
"testing";
)
-func HammerSemaphore(s *int32, cdone chan bool) {
+func HammerSemaphore(s *uint32, cdone chan bool) {
for i := 0; i < 1000; i++ {
- Semacquire(s);
- Semrelease(s);
+ runtime.Semacquire(s);
+ runtime.Semrelease(s);
}
cdone <- true;
}
func TestSemaphore(t *testing.T) {
- s := new(int32);
+ s := new(uint32);
*s = 1;
c := make(chan bool);
for i := 0; i < 10; i++ {