github.com/divyam234/rclone@v1.64.1/fs/accounting/inprogress.go (about) 1 package accounting 2 3 import ( 4 "context" 5 "sync" 6 7 "github.com/divyam234/rclone/fs" 8 ) 9 10 // inProgress holds a synchronized map of in progress transfers 11 type inProgress struct { 12 mu sync.Mutex 13 m map[string]*Account 14 } 15 16 // newInProgress makes a new inProgress object 17 func newInProgress(ctx context.Context) *inProgress { 18 ci := fs.GetConfig(ctx) 19 return &inProgress{ 20 m: make(map[string]*Account, ci.Transfers), 21 } 22 } 23 24 // set marks the name as in progress 25 func (ip *inProgress) set(name string, acc *Account) { 26 ip.mu.Lock() 27 defer ip.mu.Unlock() 28 ip.m[name] = acc 29 } 30 31 // clear marks the name as no longer in progress 32 func (ip *inProgress) clear(name string) { 33 ip.mu.Lock() 34 defer ip.mu.Unlock() 35 delete(ip.m, name) 36 } 37 38 // get gets the account for name, of nil if not found 39 func (ip *inProgress) get(name string) *Account { 40 ip.mu.Lock() 41 defer ip.mu.Unlock() 42 return ip.m[name] 43 } 44 45 // merge adds items from another inProgress 46 func (ip *inProgress) merge(m *inProgress) { 47 ip.mu.Lock() 48 defer ip.mu.Unlock() 49 m.mu.Lock() 50 defer m.mu.Unlock() 51 for key, val := range m.m { 52 ip.m[key] = val 53 } 54 }