Commit 7f34a2da authored by Nathan VanBenschoten's avatar Nathan VanBenschoten Committed by Brad Fitzpatrick

database/sql: use RWMutex for driver registration

Change-Id: I0f494c9f17cb6bb0cf5e7214cf033fdbd48f27f7
Reviewed-on: https://go-review.googlesource.com/16240Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent f75f2f3f
......@@ -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)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment