Skip to content

Commit 361a771

Browse files
committed
refactor: Remove uber atomic in favor of stdlib
1 parent 2788339 commit 361a771

File tree

24 files changed

+61
-64
lines changed

24 files changed

+61
-64
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010
"time"
1111

12-
"go.uber.org/atomic"
12+
"sync/atomic"
1313

1414
"github.com/golang-migrate/migrate/v4"
1515
"github.com/golang-migrate/migrate/v4/database"
@@ -291,14 +291,14 @@ func (ch *ClickHouse) Drop() (err error) {
291291
}
292292

293293
func (ch *ClickHouse) Lock() error {
294-
if !ch.isLocked.CAS(false, true) {
294+
if !ch.isLocked.CompareAndSwap(false, true) {
295295
return database.ErrLocked
296296
}
297297

298298
return nil
299299
}
300300
func (ch *ClickHouse) Unlock() error {
301-
if !ch.isLocked.CAS(true, false) {
301+
if !ch.isLocked.CompareAndSwap(true, false) {
302302
return database.ErrNotLocked
303303
}
304304

database/cockroachdb/cockroachdb.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import (
99
"regexp"
1010
"strconv"
1111

12+
"sync/atomic"
13+
1214
"github.com/cockroachdb/cockroach-go/v2/crdb"
1315
"github.com/golang-migrate/migrate/v4"
1416
"github.com/golang-migrate/migrate/v4/database"
1517
"github.com/hashicorp/go-multierror"
1618
"github.com/lib/pq"
17-
"go.uber.org/atomic"
1819
)
1920

2021
func init() {

database/firebird/firebird.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import (
99
"io"
1010
nurl "net/url"
1111

12+
"sync/atomic"
13+
1214
"github.com/golang-migrate/migrate/v4"
1315
"github.com/golang-migrate/migrate/v4/database"
1416
"github.com/hashicorp/go-multierror"
1517
_ "github.com/nakagami/firebirdsql"
16-
"go.uber.org/atomic"
1718
)
1819

1920
func init() {
@@ -107,14 +108,14 @@ func (f *Firebird) Close() error {
107108
}
108109

109110
func (f *Firebird) Lock() error {
110-
if !f.isLocked.CAS(false, true) {
111+
if !f.isLocked.CompareAndSwap(false, true) {
111112
return database.ErrLocked
112113
}
113114
return nil
114115
}
115116

116117
func (f *Firebird) Unlock() error {
117-
if !f.isLocked.CAS(true, false) {
118+
if !f.isLocked.CompareAndSwap(true, false) {
118119
return database.ErrNotLocked
119120
}
120121
return nil

database/mongodb/mongodb.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import (
99
"strconv"
1010
"time"
1111

12+
"sync/atomic"
13+
1214
"github.com/cenkalti/backoff/v4"
1315
"github.com/golang-migrate/migrate/v4/database"
1416
"github.com/hashicorp/go-multierror"
1517
"go.mongodb.org/mongo-driver/bson"
1618
"go.mongodb.org/mongo-driver/mongo"
1719
"go.mongodb.org/mongo-driver/mongo/options"
1820
"go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
19-
"go.uber.org/atomic"
2021
)
2122

2223
func init() {

database/mysql/mysql.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"strings"
1616
"time"
1717

18-
"go.uber.org/atomic"
18+
"sync/atomic"
1919

2020
"github.com/go-sql-driver/mysql"
2121
"github.com/golang-migrate/migrate/v4/database"

database/pgx/pgx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"strings"
1414
"time"
1515

16-
"go.uber.org/atomic"
16+
"sync/atomic"
1717

1818
"github.com/golang-migrate/migrate/v4"
1919
"github.com/golang-migrate/migrate/v4/database"

database/pgx/v5/pgx.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"strings"
1414
"time"
1515

16-
"go.uber.org/atomic"
16+
"sync/atomic"
1717

1818
"github.com/golang-migrate/migrate/v4"
1919
"github.com/golang-migrate/migrate/v4/database"

database/postgres/postgres.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"strings"
1414
"time"
1515

16-
"go.uber.org/atomic"
16+
"sync/atomic"
1717

1818
"github.com/golang-migrate/migrate/v4"
1919
"github.com/golang-migrate/migrate/v4/database"

database/ql/ql.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import (
77
nurl "net/url"
88
"strings"
99

10+
"sync/atomic"
11+
1012
"github.com/hashicorp/go-multierror"
11-
"go.uber.org/atomic"
1213

1314
"github.com/golang-migrate/migrate/v4"
1415
"github.com/golang-migrate/migrate/v4/database"
@@ -166,13 +167,13 @@ func (m *Ql) Drop() (err error) {
166167
return nil
167168
}
168169
func (m *Ql) Lock() error {
169-
if !m.isLocked.CAS(false, true) {
170+
if !m.isLocked.CompareAndSwap(false, true) {
170171
return database.ErrLocked
171172
}
172173
return nil
173174
}
174175
func (m *Ql) Unlock() error {
175-
if !m.isLocked.CAS(true, false) {
176+
if !m.isLocked.CompareAndSwap(true, false) {
176177
return database.ErrNotLocked
177178
}
178179
return nil

0 commit comments

Comments
 (0)