Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

smb: use atomic types

Roberto Ricci123a030441ca
diff --git a/backend/smb/connpool.go b/backend/smb/connpool.go
index ee3b0c208..5b8caef03 100644
--- a/backend/smb/connpool.go
+++ b/backend/smb/connpool.go
@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net"
- "sync/atomic"
"time"
smb2 "github.com/hirochachacha/go-smb2"
@@ -89,17 +88,17 @@ func (c *conn) closed() bool {
//
// Call removeSession() when done
func (f *Fs) addSession() {
- atomic.AddInt32(&f.sessions, 1)
+ f.sessions.Add(1)
}
// Show the SMB session is no longer in use
func (f *Fs) removeSession() {
- atomic.AddInt32(&f.sessions, -1)
+ f.sessions.Add(-1)
}
// getSessions shows whether there are any sessions in use
func (f *Fs) getSessions() int32 {
- return atomic.LoadInt32(&f.sessions)
+ return f.sessions.Load()
}
// Open a new connection to the SMB server.
diff --git a/backend/smb/smb.go b/backend/smb/smb.go
index b9ad5353b..704c998f9 100644
--- a/backend/smb/smb.go
+++ b/backend/smb/smb.go
@@ -9,6 +9,7 @@ import (
"path"
"strings"
"sync"
+ "sync/atomic"
"time"
"github.com/rclone/rclone/fs"
@@ -140,7 +141,7 @@ type Fs struct {
features *fs.Features // optional features
pacer *fs.Pacer // pacer for operations
- sessions int32
+ sessions atomic.Int32
poolMu sync.Mutex
pool []*conn
drain *time.Timer // used to drain the pool when we stop using the connections