diff --git a/README.md b/README.md index 9d0d806ef..c3204ef11 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,8 @@ A MySQL-Driver for Go's [database/sql](https://golang.org/pkg/database/sql/) pac ## Requirements -* Go 1.19 or higher. We aim to support the 3 latest versions of Go. -* MySQL (5.7+) and MariaDB (10.3+) are supported. +* Go 1.20 or higher. We aim to support the 3 latest versions of Go. +* MySQL (5.7+) and MariaDB (10.5+) are supported. * [TiDB](https://github.com/pingcap/tidb) is supported by PingCAP. * Do not ask questions about TiDB in our issue tracker or forum. * [Document](https://docs.pingcap.com/tidb/v6.1/dev-guide-sample-application-golang) diff --git a/atomic_bool.go b/atomic_bool.go deleted file mode 100644 index 1b7e19f3e..000000000 --- a/atomic_bool.go +++ /dev/null @@ -1,19 +0,0 @@ -// Go MySQL Driver - A MySQL-Driver for Go's database/sql package. -// -// Copyright 2022 The Go-MySQL-Driver Authors. All rights reserved. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this file, -// You can obtain one at http://mozilla.org/MPL/2.0/. -//go:build go1.19 -// +build go1.19 - -package mysql - -import "sync/atomic" - -/****************************************************************************** -* Sync utils * -******************************************************************************/ - -type atomicBool = atomic.Bool diff --git a/atomic_bool_go118.go b/atomic_bool_go118.go deleted file mode 100644 index 2e9a7f0b6..000000000 --- a/atomic_bool_go118.go +++ /dev/null @@ -1,47 +0,0 @@ -// Go MySQL Driver - A MySQL-Driver for Go's database/sql package. -// -// Copyright 2022 The Go-MySQL-Driver Authors. All rights reserved. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this file, -// You can obtain one at http://mozilla.org/MPL/2.0/. -//go:build !go1.19 -// +build !go1.19 - -package mysql - -import "sync/atomic" - -/****************************************************************************** -* Sync utils * -******************************************************************************/ - -// atomicBool is an implementation of atomic.Bool for older version of Go. -// it is a wrapper around uint32 for usage as a boolean value with -// atomic access. -type atomicBool struct { - _ noCopy - value uint32 -} - -// Load returns whether the current boolean value is true -func (ab *atomicBool) Load() bool { - return atomic.LoadUint32(&ab.value) > 0 -} - -// Store sets the value of the bool regardless of the previous value -func (ab *atomicBool) Store(value bool) { - if value { - atomic.StoreUint32(&ab.value, 1) - } else { - atomic.StoreUint32(&ab.value, 0) - } -} - -// Swap sets the value of the bool and returns the old value. -func (ab *atomicBool) Swap(value bool) bool { - if value { - return atomic.SwapUint32(&ab.value, 1) > 0 - } - return atomic.SwapUint32(&ab.value, 0) > 0 -} diff --git a/atomic_bool_test.go b/atomic_bool_test.go deleted file mode 100644 index a3b4ea0e8..000000000 --- a/atomic_bool_test.go +++ /dev/null @@ -1,71 +0,0 @@ -// Go MySQL Driver - A MySQL-Driver for Go's database/sql package. -// -// Copyright 2022 The Go-MySQL-Driver Authors. All rights reserved. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this file, -// You can obtain one at http://mozilla.org/MPL/2.0/. -//go:build !go1.19 -// +build !go1.19 - -package mysql - -import ( - "testing" -) - -func TestAtomicBool(t *testing.T) { - var ab atomicBool - if ab.Load() { - t.Fatal("Expected value to be false") - } - - ab.Store(true) - if ab.value != 1 { - t.Fatal("Set(true) did not set value to 1") - } - if !ab.Load() { - t.Fatal("Expected value to be true") - } - - ab.Store(true) - if !ab.Load() { - t.Fatal("Expected value to be true") - } - - ab.Store(false) - if ab.value != 0 { - t.Fatal("Set(false) did not set value to 0") - } - if ab.Load() { - t.Fatal("Expected value to be false") - } - - ab.Store(false) - if ab.Load() { - t.Fatal("Expected value to be false") - } - if ab.Swap(false) { - t.Fatal("Expected the old value to be false") - } - if ab.Swap(true) { - t.Fatal("Expected the old value to be false") - } - if !ab.Load() { - t.Fatal("Expected value to be true") - } - - ab.Store(true) - if !ab.Load() { - t.Fatal("Expected value to be true") - } - if !ab.Swap(true) { - t.Fatal("Expected the old value to be true") - } - if !ab.Swap(false) { - t.Fatal("Expected the old value to be true") - } - if ab.Load() { - t.Fatal("Expected value to be false") - } -} diff --git a/connection.go b/connection.go index c170114fe..55e42eb18 100644 --- a/connection.go +++ b/connection.go @@ -17,6 +17,7 @@ import ( "net" "strconv" "strings" + "sync/atomic" "time" ) @@ -41,7 +42,7 @@ type mysqlConn struct { closech chan struct{} finished chan<- struct{} canceled atomicError // set non-nil if conn is canceled - closed atomicBool // set when conn is closed, before closech is closed + closed atomic.Bool // set when conn is closed, before closech is closed } // Handles parameters set in DSN after the connection is established diff --git a/go.mod b/go.mod index 4629714c0..2eed53ebb 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module github.com/go-sql-driver/mysql -go 1.18 +go 1.20 require filippo.io/edwards25519 v1.1.0