]> Cypherpunks repositories - gostls13.git/commit
database/sql: associate a mutex with each driver interface
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 14 Mar 2013 22:01:45 +0000 (15:01 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 14 Mar 2013 22:01:45 +0000 (15:01 -0700)
commitf28c8fba67008ae0b14517979e9b48ac38fa22b6
treea6460d06f73125731c4e748549604586301ace2b
parenteb80431b6136663c7a1141a879c89b64fb8ba24f
database/sql: associate a mutex with each driver interface

The database/sql/driver docs make this promise:

   "Conn is a connection to a database. It is not used
   concurrently by multiple goroutines."

That promises exists as part of database/sql's overall
goal of making drivers relatively easy to write.

So far this promise has been kept without the use of locks by
being careful in the database/sql package, but sometimes too
careful. (cf. golang.org/issue/3857)

The CL associates a Mutex with each driver.Conn, and with the
interface value progeny thereof. (e.g. each driver.Tx,
driver.Stmt, driver.Rows, driver.Result, etc) Then whenever
those interface values are used, the Locker is locked.

This CL should be a no-op (aside from some new Lock/Unlock
pairs) and doesn't attempt to fix Issue 3857 or Issue 4459,
but should make it much easier in a subsequent CL.

Update #3857

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7803043
src/pkg/database/sql/convert.go
src/pkg/database/sql/sql.go
src/pkg/database/sql/sql_test.go