]> Cypherpunks repositories - gostls13.git/commitdiff
use sync.Mutex instead of a channel for locking
authorRob Pike <r@golang.org>
Fri, 5 Dec 2008 23:18:07 +0000 (15:18 -0800)
committerRob Pike <r@golang.org>
Fri, 5 Dec 2008 23:18:07 +0000 (15:18 -0800)
R=rsc
DELTA=12  (3 added, 1 deleted, 8 changed)
OCL=20631
CL=20634

src/lib/Makefile
src/lib/reflect/type.go

index b920aa6198f2a4939670e61c32e33111f85f3f45..197e535d71e65a92b03f45e2ea2fa5fe4d36c0bd 100644 (file)
@@ -97,7 +97,7 @@ io.dirinstall: os.dirinstall syscall.dirinstall
 net.dirinstall: once.install os.dirinstall strconv.dirinstall
 os.dirinstall: syscall.dirinstall
 regexp.dirinstall: os.dirinstall
-reflect.dirinstall: strconv.dirinstall
+reflect.dirinstall: strconv.dirinstall sync.dirinstall
 strconv.dirinstall: os.dirinstall utf8.install
 tabwriter.dirinstall: os.dirinstall io.dirinstall container/array.dirinstall
 time.dirinstall: once.install os.dirinstall
index 279f6f3150d1e77aa0468900294d11a12f5fcd1d..5258cf5b5ab3422ad3bd1f6133772a98d200b857 100644 (file)
@@ -7,6 +7,8 @@
 
 package reflect
 
+import "sync"
+
 export type Type interface
 
 export func ExpandType(name string) Type
@@ -390,21 +392,20 @@ var MissingStub *StubType;
 var DotDotDotStub *StubType;
 
 // The database stored in the maps is global; use locking to guarantee safety.
-var lockchan *chan bool  // Channel with buffer of 1, used as a mutex
+var typestringlock sync.Mutex
 
 func Lock() {
-       lockchan <- true        // block if buffer is full
+       typestringlock.Lock()
 }
 
 func Unlock() {
-       <-lockchan      // release waiters
+       typestringlock.Unlock()
 }
 
 func init() {
        ptrsize = 8;    // TODO: compute this
        interfacesize = 2*ptrsize;      // TODO: compute this
 
-       lockchan = new(chan bool, 1);   // unlocked at creation - buffer is empty
        Lock(); // not necessary because of init ordering but be safe.
 
        types = new(map[string] *Type);