]> Cypherpunks repositories - gostls13.git/commitdiff
once: replace all uses of package once with sync.Once.
authorRob Pike <r@golang.org>
Thu, 5 Aug 2010 20:14:41 +0000 (06:14 +1000)
committerRob Pike <r@golang.org>
Thu, 5 Aug 2010 20:14:41 +0000 (06:14 +1000)
package once remains for now; will be deleted after next release.

R=golang-dev, brainman
CC=golang-dev
https://golang.org/cl/1914046

14 files changed:
src/pkg/crypto/tls/common.go
src/pkg/mime/type.go
src/pkg/net/dnsclient.go
src/pkg/net/fd.go
src/pkg/net/fd_windows.go
src/pkg/net/iprawsock.go
src/pkg/net/port.go
src/pkg/os/env.go
src/pkg/rpc/server_test.go
src/pkg/time/tick.go
src/pkg/time/zoneinfo.go
src/pkg/time/zoneinfo_unix.go
src/pkg/time/zoneinfo_windows.go
src/pkg/websocket/websocket_test.go

index 717ae0a81539a3107385db1c73b1452f6d0b0a49..18c572c0189720b30e993015b60946382f915c0c 100644 (file)
@@ -9,7 +9,7 @@ import (
        "crypto/rsa"
        "io"
        "io/ioutil"
-       "once"
+       "sync"
        "time"
 )
 
@@ -127,6 +127,8 @@ func mutualVersion(vers uint16) (uint16, bool) {
 // The defaultConfig is used in place of a nil *Config in the TLS server and client.
 var varDefaultConfig *Config
 
+var once sync.Once
+
 func defaultConfig() *Config {
        once.Do(initDefaultConfig)
        return varDefaultConfig
index 9202b8557244bd3d3005fc52c6cddf000b288973..a10b780ae95c94d0bf68128c7d26daf9d2d46127 100644 (file)
@@ -7,7 +7,6 @@ package mime
 
 import (
        "bufio"
-       "once"
        "os"
        "strings"
        "sync"
@@ -69,6 +68,8 @@ func initMime() {
        }
 }
 
+var once sync.Once
+
 // TypeByExtension returns the MIME type associated with the file extension ext.
 // The extension ext should begin with a leading dot, as in ".html".
 // When ext has no associated type, TypeByExtension returns "".
index fe54f6b12a56e8733e9fe70246aae23034806f1b..619d9e2e0312a6bb5c3531501dfa1cb37063849b 100644 (file)
@@ -15,9 +15,9 @@
 package net
 
 import (
-       "once"
        "os"
        "rand"
+       "sync"
        "time"
 )
 
@@ -235,11 +235,13 @@ func isDomainName(s string) bool {
        return ok
 }
 
+var onceLoadConfig sync.Once
+
 func lookup(name string, qtype uint16) (cname string, addrs []dnsRR, err os.Error) {
        if !isDomainName(name) {
                return name, nil, &DNSError{Error: "invalid domain name", Name: name}
        }
-       once.Do(loadConfig)
+       onceLoadConfig.Do(loadConfig)
        if dnserr != nil || cfg == nil {
                err = dnserr
                return
@@ -293,7 +295,7 @@ func lookup(name string, qtype uint16) (cname string, addrs []dnsRR, err os.Erro
 // It returns the canonical name for the host and an array of that
 // host's addresses.
 func LookupHost(name string) (cname string, addrs []string, err os.Error) {
-       once.Do(loadConfig)
+       onceLoadConfig.Do(loadConfig)
        if dnserr != nil || cfg == nil {
                err = dnserr
                return
index 4100f62575542787ef51db0ed577a3239b866345..7d3f227c1c7b9bec67924c6c5531adcef60d9232 100644 (file)
@@ -8,7 +8,6 @@ package net
 
 import (
        "io"
-       "once"
        "os"
        "sync"
        "syscall"
@@ -258,6 +257,7 @@ func (s *pollServer) WaitWrite(fd *netFD) {
 // All the network FDs use a single pollServer.
 
 var pollserver *pollServer
+var onceStartServer sync.Once
 
 func startServer() {
        p, err := newPollServer()
@@ -268,7 +268,7 @@ func startServer() {
 }
 
 func newFD(fd, family, proto int, net string, laddr, raddr Addr) (f *netFD, err os.Error) {
-       once.Do(startServer)
+       onceStartServer.Do(startServer)
        if e := syscall.SetNonblock(fd, true); e != 0 {
                return nil, &OpError{"setnonblock", net, laddr, os.Errno(e)}
        }
index c287d71539c7d71c3cf7ee4c364df3fa9ef39682..7a78391b06133e068afb03183fd5686a1e941e91 100644 (file)
@@ -5,13 +5,14 @@
 package net
 
 import (
-       "once"
        "os"
        "sync"
        "syscall"
        "unsafe"
 )
 
+var onceStartServer sync.Once
+
 // BUG(brainman): The Windows implementation does not implement SetTimeout.
 
 // IO completion result parameters.
@@ -119,6 +120,7 @@ func (s *pollServer) Run() {
 // All the network FDs use a single pollServer.
 
 var pollserver *pollServer
+var onceStartServer sync.Once
 
 func startServer() {
        p, err := newPollServer()
@@ -134,7 +136,7 @@ func newFD(fd, family, proto int, net string, laddr, raddr Addr) (f *netFD, err
        if initErr != nil {
                return nil, initErr
        }
-       once.Do(startServer)
+       onceStartServer.Do(startServer)
        // Associate our socket with pollserver.iocp.
        if _, e := syscall.CreateIoCompletionPort(int32(fd), pollserver.iocp, 0, 0); e != 0 {
                return nil, &OpError{"CreateIoCompletionPort", net, laddr, os.Errno(e)}
@@ -303,7 +305,7 @@ func (fd *netFD) accept(toAddr func(syscall.Sockaddr) Addr) (nfd *netFD, err os.
        syscall.ForkLock.RUnlock()
 
        // Associate our new socket with IOCP.
-       once.Do(startServer)
+       onceStartServer.Do(startServer)
        if _, e = syscall.CreateIoCompletionPort(int32(s), pollserver.iocp, 0, 0); e != 0 {
                return nil, &OpError{"CreateIoCompletionPort", fd.net, fd.laddr, os.Errno(e)}
        }
index 6b48512e009abf7a0f86399fb5f965b9c9243420..92c299e4fc17531c81732d369827384330cb6298 100644 (file)
@@ -7,11 +7,13 @@
 package net
 
 import (
-       "once"
        "os"
+       "sync"
        "syscall"
 )
 
+var onceReadProtocols sync.Once
+
 func sockaddrToIP(sa syscall.Sockaddr) Addr {
        switch sa := sa.(type) {
        case *syscall.SockaddrInet4:
@@ -284,7 +286,7 @@ func readProtocols() {
 }
 
 func netProtoSplit(netProto string) (net string, proto int, err os.Error) {
-       once.Do(readProtocols)
+       onceReadProtocols.Do(readProtocols)
        i := last(netProto, ':')
        if i+1 >= len(netProto) { // no colon
                return "", 0, os.ErrorString("no IP protocol specified")
index 5f182d0d1a58b28020f7b44f0b115dc2aae93a49..cd18d2b42aa6ac582efde7a6f14f286192e6e0a3 100644 (file)
@@ -7,12 +7,13 @@
 package net
 
 import (
-       "once"
        "os"
+       "sync"
 )
 
 var services map[string]map[string]int
 var servicesError os.Error
+var onceReadServices sync.Once
 
 func readServices() {
        services = make(map[string]map[string]int)
@@ -49,7 +50,7 @@ func readServices() {
 
 // LookupPort looks up the port for the given network and service.
 func LookupPort(network, service string) (port int, err os.Error) {
-       once.Do(readServices)
+       onceReadServices.Do(readServices)
 
        switch network {
        case "tcp4", "tcp6":
index bdd2ac293cc7973749aae55975f09fab8cbf93d1..3ce84b5cba824d8d0d8f50d61a89b226b05dc9b5 100644 (file)
@@ -7,13 +7,14 @@
 package os
 
 import (
-       "once"
+       "sync"
 )
 
 // ENOENV is the Error indicating that an environment variable does not exist.
 var ENOENV = NewError("no such environment variable")
 
 var env map[string]string
+var once sync.Once
 
 
 func copyenv() {
index e502db4e31a9c24b01b68adff086356caf864bc4..9ece79b34774bb409f0963af10493b1b5f591f78 100644 (file)
@@ -9,14 +9,15 @@ import (
        "http"
        "log"
        "net"
-       "once"
        "os"
        "strings"
+       "sync"
        "testing"
 )
 
 var serverAddr string
 var httpServerAddr string
+var once sync.Once
 
 const second = 1e9
 
index 05023d4d00b82247ecd471a8c5c6d9418685cad2..9fb308396ec423e5b09866a4a8cb1a7d5ef84d66 100644 (file)
@@ -5,7 +5,7 @@
 package time
 
 import (
-       "once"
+       "sync"
 )
 
 // A Ticker holds a synchronous channel that delivers `ticks' of a clock
@@ -156,6 +156,8 @@ func tickerLoop() {
        }
 }
 
+var onceStartTickerLoop sync.Once
+
 // NewTicker returns a new Ticker containing a channel that will
 // send the time, in nanoseconds, every ns nanoseconds.  It adjusts the
 // intervals to make up for pauses in delivery of the ticks.
@@ -165,7 +167,7 @@ func NewTicker(ns int64) *Ticker {
        }
        c := make(chan int64, 1) //  See comment on send in tickerLoop
        t := &Ticker{c, c, ns, false, Nanoseconds() + ns, nil}
-       once.Do(startTickerLoop)
+       onceStartTickerLoop.Do(startTickerLoop)
        // must be run in background so global Tickers can be created
        go func() { newTicker <- t }()
        return t
index 7884898f72d20172bb0b85d211e7105b9e9fcf7f..6e5b2efb76b5161f60fbc90a74e8f6ba412d96ac 100644 (file)
@@ -203,6 +203,7 @@ func readinfofile(name string) ([]zonetime, bool) {
 }
 
 var zones []zonetime
+var onceSetupZone sync.Once
 
 func setupZone() {
        // consult $TZ to find the time zone to use.
@@ -223,7 +224,7 @@ func setupZone() {
 
 // Look up the correct time zone (daylight savings or not) for the given unix time, in the current location.
 func lookupTimezone(sec int64) (zone string, offset int) {
-       once.Do(setupZone)
+       onceSetupZone.Do(setupZone)
        if len(zones) == 0 {
                return "UTC", 0
        }
index 5a8c94aaf74eb0e51d16d6a21f22b134ff0f1949..26c86ab038dda52ac8ae904a77cccc27faf2c1eb 100644 (file)
@@ -11,8 +11,8 @@ package time
 
 import (
        "io/ioutil"
-       "once"
        "os"
+       "sync"
 )
 
 const (
@@ -203,6 +203,7 @@ func readinfofile(name string) ([]zonetime, bool) {
 }
 
 var zones []zonetime
+var onceSetupZone sync.Once
 
 func setupZone() {
        // consult $TZ to find the time zone to use.
@@ -223,7 +224,7 @@ func setupZone() {
 
 // Look up the correct time zone (daylight savings or not) for the given unix time, in the current location.
 func lookupTimezone(sec int64) (zone string, offset int) {
-       once.Do(setupZone)
+       onceSetupZone.Do(setupZone)
        if len(zones) == 0 {
                return "UTC", 0
        }
@@ -251,7 +252,7 @@ func lookupTimezone(sec int64) (zone string, offset int) {
 // For a system in Sydney, "EST" and "EDT", though they have
 // different meanings than they do in New York.
 func lookupByName(name string) (off int, found bool) {
-       once.Do(setupZone)
+       onceSetupZone.Do(setupZone)
        for _, z := range zones {
                if name == z.zone.name {
                        return z.zone.utcoff, true
index d249165c11281173188169d7de60e363024c4e73..d9112598f21a42c54addb5ab39d8d2584dad8962 100644 (file)
@@ -6,8 +6,8 @@ package time
 
 import (
        "syscall"
-       "os"
        "once"
+       "os"
 )
 
 // BUG(brainman): The Windows implementation assumes that
@@ -121,6 +121,7 @@ func (zi *zoneinfo) pickZone(t *Time) *zone {
 
 var tz zoneinfo
 var initError os.Error
+var onceSetupZone sync.Once
 
 func setupZone() {
        var i syscall.Timezoneinformation
@@ -145,7 +146,7 @@ func setupZone() {
 
 // Look up the correct time zone (daylight savings or not) for the given unix time, in the current location.
 func lookupTimezone(sec int64) (zone string, offset int) {
-       once.Do(setupZone)
+       onceSetupZone.Do(setupZone)
        if initError != nil {
                return "", 0
        }
@@ -174,7 +175,7 @@ func lookupTimezone(sec int64) (zone string, offset int) {
 // time zone with the given abbreviation. It only considers
 // time zones that apply to the current system.
 func lookupByName(name string) (off int, found bool) {
-       once.Do(setupZone)
+       onceSetupZone.Do(setupZone)
        if initError != nil {
                return 0, false
        }
index 1932aca11315fd47e580df65cff5b5659f61970c..22aa1fa5be7be22bd9519f8b30d415b5e457973d 100644 (file)
@@ -11,11 +11,12 @@ import (
        "io"
        "log"
        "net"
-       "once"
+       "sync"
        "testing"
 )
 
 var serverAddr string
+var once sync.Once
 
 func echoServer(ws *Conn) { io.Copy(ws, ws) }