mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
7342060b07
This makes sure fsdiff doesn't try to unmount things that shouldn't be. **Note**: This is intended as a temporary solution to have as minor a change as possible for 1.11.1. A bigger change will be required in order to support container re-attach. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
32 lines
738 B
Go
32 lines
738 B
Go
package graphdriver
|
|
|
|
import "sync"
|
|
|
|
// RefCounter is a generic counter for use by graphdriver Get/Put calls
|
|
type RefCounter struct {
|
|
counts map[string]int
|
|
mu sync.Mutex
|
|
}
|
|
|
|
// NewRefCounter returns a new RefCounter
|
|
func NewRefCounter() *RefCounter {
|
|
return &RefCounter{counts: make(map[string]int)}
|
|
}
|
|
|
|
// Increment increaes the ref count for the given id and returns the current count
|
|
func (c *RefCounter) Increment(id string) int {
|
|
c.mu.Lock()
|
|
c.counts[id]++
|
|
count := c.counts[id]
|
|
c.mu.Unlock()
|
|
return count
|
|
}
|
|
|
|
// Decrement decreases the ref count for the given id and returns the current count
|
|
func (c *RefCounter) Decrement(id string) int {
|
|
c.mu.Lock()
|
|
c.counts[id]--
|
|
count := c.counts[id]
|
|
c.mu.Unlock()
|
|
return count
|
|
}
|