summaryrefslogtreecommitdiff
path: root/src/pkg/sync/mutex.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/sync/mutex.go')
-rw-r--r--src/pkg/sync/mutex.go21
1 files changed, 11 insertions, 10 deletions
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.