From 123a030441cadd87f32321d67ea477b8a13c06c2 Mon Sep 17 00:00:00 2001 From: Roberto Ricci Date: Fri, 18 Aug 2023 16:38:19 +0200 Subject: [PATCH] smb: use atomic types --- backend/smb/connpool.go | 7 +++---- backend/smb/smb.go | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) 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