Skip to content

Commit

Permalink
Clean up record state
Browse files Browse the repository at this point in the history
  • Loading branch information
mgnsk committed Jun 18, 2021
1 parent 91da5e7 commit 10ede1d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
4 changes: 1 addition & 3 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,7 @@ func (c *Cache) evictLocked(key interface{}, target *interface{}) (r *record, ok
// Add before setState to allow waiters to use an unlocked record.
r.evictionWg.Add(1)
}
if !r.setState(evicting) {
panic("evcache: invalid record state")
}
r.setState(evicting)
if c.mode == ModeBlocking || c.afterEvict != nil {
c.wg.Add(1)
go func() {
Expand Down
5 changes: 2 additions & 3 deletions record.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ func (r *record) init(value interface{}, ttl time.Duration) {
}
}

func (r *record) setState(newState uint32) bool {
prevState := (newState + 3 - 1) % 3
return atomic.CompareAndSwapUint32(&r.state, prevState, newState)
func (r *record) setState(s uint32) {
atomic.StoreUint32(&r.state, s)
}

func (r *record) State() uint32 {
Expand Down

0 comments on commit 10ede1d

Please sign in to comment.