mirror of
https://github.com/golang/go
synced 2024-11-18 09:44:50 -07:00
database/sql: use RWMutex for driver registration
Change-Id: I0f494c9f17cb6bb0cf5e7214cf033fdbd48f27f7 Reviewed-on: https://go-review.googlesource.com/16240 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
f75f2f3fcc
commit
7f34a2dac8
@ -24,7 +24,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
driversMu sync.Mutex
|
||||
driversMu sync.RWMutex
|
||||
drivers = make(map[string]driver.Driver)
|
||||
)
|
||||
|
||||
@ -52,8 +52,8 @@ func unregisterAllDrivers() {
|
||||
|
||||
// Drivers returns a sorted list of the names of the registered drivers.
|
||||
func Drivers() []string {
|
||||
driversMu.Lock()
|
||||
defer driversMu.Unlock()
|
||||
driversMu.RLock()
|
||||
defer driversMu.RUnlock()
|
||||
var list []string
|
||||
for name := range drivers {
|
||||
list = append(list, name)
|
||||
@ -465,9 +465,9 @@ var connectionRequestQueueSize = 1000000
|
||||
// function should be called just once. It is rarely necessary to
|
||||
// close a DB.
|
||||
func Open(driverName, dataSourceName string) (*DB, error) {
|
||||
driversMu.Lock()
|
||||
driversMu.RLock()
|
||||
driveri, ok := drivers[driverName]
|
||||
driversMu.Unlock()
|
||||
driversMu.RUnlock()
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("sql: unknown driver %q (forgotten import?)", driverName)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user