github.com/ncw/rclone@v1.48.1-0.20190724201158-a35aa1360e3e/fs/accounting/inprogress.go (about)

     1  package accounting
     2  
     3  import (
     4  	"sync"
     5  
     6  	"github.com/ncw/rclone/fs"
     7  )
     8  
     9  // inProgress holds a synchronized map of in progress transfers
    10  type inProgress struct {
    11  	mu sync.Mutex
    12  	m  map[string]*Account
    13  }
    14  
    15  // newInProgress makes a new inProgress object
    16  func newInProgress() *inProgress {
    17  	return &inProgress{
    18  		m: make(map[string]*Account, fs.Config.Transfers),
    19  	}
    20  }
    21  
    22  // set marks the name as in progress
    23  func (ip *inProgress) set(name string, acc *Account) {
    24  	ip.mu.Lock()
    25  	defer ip.mu.Unlock()
    26  	ip.m[name] = acc
    27  }
    28  
    29  // clear marks the name as no longer in progress
    30  func (ip *inProgress) clear(name string) {
    31  	ip.mu.Lock()
    32  	defer ip.mu.Unlock()
    33  	delete(ip.m, name)
    34  }
    35  
    36  // get gets the account for name, of nil if not found
    37  func (ip *inProgress) get(name string) *Account {
    38  	ip.mu.Lock()
    39  	defer ip.mu.Unlock()
    40  	return ip.m[name]
    41  }