-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Open
Labels
kind/enhancementEnhancements are not bugs or new features but can improve usability or performance.Enhancements are not bugs or new features but can improve usability or performance.kind/refactorPR's that refactor, or clean-up codePR's that refactor, or clean-up code
Description
The current interface only allows Incrementing and Decrementing, but does not allow getting the current reference-count. As a result, we need to do implement confusing code to get the current count;
// Check if the refcount is non-zero.
m.rc.Increment(target)
if m.rc.Decrement(target) > 0 {
// it's in use
}We should look at a cleaner way to get this information without having to increment/decrement. Perhaps we don't need the actual count (only if in use?), but we can discuss that when working on this.
moby/daemon/graphdriver/counter.go
Lines 10 to 37 in 54fcd40
| // RefCounter is a generic counter for use by graphdriver Get/Put calls | |
| type RefCounter struct { | |
| counts map[string]*minfo | |
| mu sync.Mutex | |
| checker Checker | |
| } | |
| // NewRefCounter returns a new RefCounter | |
| func NewRefCounter(c Checker) *RefCounter { | |
| return &RefCounter{ | |
| checker: c, | |
| counts: make(map[string]*minfo), | |
| } | |
| } | |
| // Increment increases the ref count for the given id and returns the current count | |
| func (c *RefCounter) Increment(path string) int { | |
| return c.incdec(path, func(minfo *minfo) { | |
| minfo.count++ | |
| }) | |
| } | |
| // Decrement decreases the ref count for the given id and returns the current count | |
| func (c *RefCounter) Decrement(path string) int { | |
| return c.incdec(path, func(minfo *minfo) { | |
| minfo.count-- | |
| }) | |
| } |
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
kind/enhancementEnhancements are not bugs or new features but can improve usability or performance.Enhancements are not bugs or new features but can improve usability or performance.kind/refactorPR's that refactor, or clean-up codePR's that refactor, or clean-up code