Skip to content

Commit 8945e85

Browse files
authored
Merge pull request #1303 from romshark/master
refactor: Remove go.uber.org/atomic in favor of std sync/atomic
1 parent 7108d80 commit 8945e85

File tree

24 files changed

+56
-77
lines changed

24 files changed

+56
-77
lines changed

database/cassandra/cassandra.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import (
77
nurl "net/url"
88
"strconv"
99
"strings"
10+
"sync/atomic"
1011
"time"
1112

12-
"go.uber.org/atomic"
13-
1413
"github.com/gocql/gocql"
1514
"github.com/golang-migrate/migrate/v4/database"
1615
"github.com/golang-migrate/migrate/v4/database/multistmt"
@@ -199,14 +198,14 @@ func (c *Cassandra) Close() error {
199198
}
200199

201200
func (c *Cassandra) Lock() error {
202-
if !c.isLocked.CAS(false, true) {
201+
if !c.isLocked.CompareAndSwap(false, true) {
203202
return database.ErrLocked
204203
}
205204
return nil
206205
}
207206

208207
func (c *Cassandra) Unlock() error {
209-
if !c.isLocked.CAS(true, false) {
208+
if !c.isLocked.CompareAndSwap(true, false) {
210209
return database.ErrNotLocked
211210
}
212211
return nil

database/clickhouse/clickhouse.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import (
77
"net/url"
88
"strconv"
99
"strings"
10+
"sync/atomic"
1011
"time"
1112

12-
"go.uber.org/atomic"
13-
1413
"github.com/golang-migrate/migrate/v4"
1514
"github.com/golang-migrate/migrate/v4/database"
1615
"github.com/golang-migrate/migrate/v4/database/multistmt"
@@ -291,14 +290,14 @@ func (ch *ClickHouse) Drop() (err error) {
291290
}
292291

293292
func (ch *ClickHouse) Lock() error {
294-
if !ch.isLocked.CAS(false, true) {
293+
if !ch.isLocked.CompareAndSwap(false, true) {
295294
return database.ErrLocked
296295
}
297296

298297
return nil
299298
}
300299
func (ch *ClickHouse) Unlock() error {
301-
if !ch.isLocked.CAS(true, false) {
300+
if !ch.isLocked.CompareAndSwap(true, false) {
302301
return database.ErrNotLocked
303302
}
304303

database/cockroachdb/cockroachdb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import (
88
nurl "net/url"
99
"regexp"
1010
"strconv"
11+
"sync/atomic"
1112

1213
"github.com/cockroachdb/cockroach-go/v2/crdb"
1314
"github.com/golang-migrate/migrate/v4"
1415
"github.com/golang-migrate/migrate/v4/database"
1516
"github.com/hashicorp/go-multierror"
1617
"github.com/lib/pq"
17-
"go.uber.org/atomic"
1818
)
1919

2020
func init() {

database/firebird/firebird.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88
"fmt"
99
"io"
1010
nurl "net/url"
11+
"sync/atomic"
1112

1213
"github.com/golang-migrate/migrate/v4"
1314
"github.com/golang-migrate/migrate/v4/database"
1415
"github.com/hashicorp/go-multierror"
1516
_ "github.com/nakagami/firebirdsql"
16-
"go.uber.org/atomic"
1717
)
1818

1919
func init() {
@@ -107,14 +107,14 @@ func (f *Firebird) Close() error {
107107
}
108108

109109
func (f *Firebird) Lock() error {
110-
if !f.isLocked.CAS(false, true) {
110+
if !f.isLocked.CompareAndSwap(false, true) {
111111
return database.ErrLocked
112112
}
113113
return nil
114114
}
115115

116116
func (f *Firebird) Unlock() error {
117-
if !f.isLocked.CAS(true, false) {
117+
if !f.isLocked.CompareAndSwap(true, false) {
118118
return database.ErrNotLocked
119119
}
120120
return nil

database/mongodb/mongodb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"net/url"
88
"os"
99
"strconv"
10+
"sync/atomic"
1011
"time"
1112

1213
"github.com/cenkalti/backoff/v4"
@@ -16,7 +17,6 @@ import (
1617
"go.mongodb.org/mongo-driver/mongo"
1718
"go.mongodb.org/mongo-driver/mongo/options"
1819
"go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
19-
"go.uber.org/atomic"
2020
)
2121

2222
func init() {

database/mysql/mysql.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import (
1313
"os"
1414
"strconv"
1515
"strings"
16+
"sync/atomic"
1617
"time"
1718

18-
"go.uber.org/atomic"
19-
2019
"github.com/go-sql-driver/mysql"
2120
"github.com/golang-migrate/migrate/v4/database"
2221
"github.com/hashicorp/go-multierror"

database/pgx/pgx.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import (
1111
"regexp"
1212
"strconv"
1313
"strings"
14+
"sync/atomic"
1415
"time"
1516

16-
"go.uber.org/atomic"
17-
1817
"github.com/golang-migrate/migrate/v4"
1918
"github.com/golang-migrate/migrate/v4/database"
2019
"github.com/golang-migrate/migrate/v4/database/multistmt"

database/pgx/v5/pgx.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import (
1111
"regexp"
1212
"strconv"
1313
"strings"
14+
"sync/atomic"
1415
"time"
1516

16-
"go.uber.org/atomic"
17-
1817
"github.com/golang-migrate/migrate/v4"
1918
"github.com/golang-migrate/migrate/v4/database"
2019
"github.com/golang-migrate/migrate/v4/database/multistmt"

database/postgres/postgres.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import (
1111
"regexp"
1212
"strconv"
1313
"strings"
14+
"sync/atomic"
1415
"time"
1516

16-
"go.uber.org/atomic"
17-
1817
"github.com/golang-migrate/migrate/v4"
1918
"github.com/golang-migrate/migrate/v4/database"
2019
"github.com/golang-migrate/migrate/v4/database/multistmt"

database/ql/ql.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
"io"
77
nurl "net/url"
88
"strings"
9+
"sync/atomic"
910

1011
"github.com/hashicorp/go-multierror"
11-
"go.uber.org/atomic"
1212

1313
"github.com/golang-migrate/migrate/v4"
1414
"github.com/golang-migrate/migrate/v4/database"
@@ -166,13 +166,13 @@ func (m *Ql) Drop() (err error) {
166166
return nil
167167
}
168168
func (m *Ql) Lock() error {
169-
if !m.isLocked.CAS(false, true) {
169+
if !m.isLocked.CompareAndSwap(false, true) {
170170
return database.ErrLocked
171171
}
172172
return nil
173173
}
174174
func (m *Ql) Unlock() error {
175-
if !m.isLocked.CAS(true, false) {
175+
if !m.isLocked.CompareAndSwap(true, false) {
176176
return database.ErrNotLocked
177177
}
178178
return nil

0 commit comments

Comments
 (0)