smb: use atomic types

This commit is contained in:
Roberto Ricci 2023-08-18 16:38:19 +02:00 committed by Nick Craig-Wood
parent 28ceb323ee
commit 123a030441
2 changed files with 5 additions and 5 deletions

View file

@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"net" "net"
"sync/atomic"
"time" "time"
smb2 "github.com/hirochachacha/go-smb2" smb2 "github.com/hirochachacha/go-smb2"
@ -89,17 +88,17 @@ func (c *conn) closed() bool {
// //
// Call removeSession() when done // Call removeSession() when done
func (f *Fs) addSession() { func (f *Fs) addSession() {
atomic.AddInt32(&f.sessions, 1) f.sessions.Add(1)
} }
// Show the SMB session is no longer in use // Show the SMB session is no longer in use
func (f *Fs) removeSession() { func (f *Fs) removeSession() {
atomic.AddInt32(&f.sessions, -1) f.sessions.Add(-1)
} }
// getSessions shows whether there are any sessions in use // getSessions shows whether there are any sessions in use
func (f *Fs) getSessions() int32 { func (f *Fs) getSessions() int32 {
return atomic.LoadInt32(&f.sessions) return f.sessions.Load()
} }
// Open a new connection to the SMB server. // Open a new connection to the SMB server.

View file

@ -9,6 +9,7 @@ import (
"path" "path"
"strings" "strings"
"sync" "sync"
"sync/atomic"
"time" "time"
"github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs"
@ -140,7 +141,7 @@ type Fs struct {
features *fs.Features // optional features features *fs.Features // optional features
pacer *fs.Pacer // pacer for operations pacer *fs.Pacer // pacer for operations
sessions int32 sessions atomic.Int32
poolMu sync.Mutex poolMu sync.Mutex
pool []*conn pool []*conn
drain *time.Timer // used to drain the pool when we stop using the connections drain *time.Timer // used to drain the pool when we stop using the connections