summaryrefslogtreecommitdiff
path: root/src/pkg/sync/mutex.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-10-15 17:46:53 -0700
committerRuss Cox <rsc@golang.org>2009-10-15 17:46:53 -0700
commita86d7c2bd9196ad9c768a4cb52b5434d23f8fe84 (patch)
treeb18dff11371da4606dfa47c3018e78f62f3b6564 /src/pkg/sync/mutex.go
parent96c3809cb09820dd80548f1940a35e442c93c65d (diff)
downloadgolang-a86d7c2bd9196ad9c768a4cb52b5434d23f8fe84.tar.gz
publish semacquire and semrelease for use by sync.
more enforcing package boundaries R=r DELTA=46 (13 added, 15 deleted, 18 changed) OCL=35806 CL=35806
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.