Skip to content

Commit

Permalink
guard all access to item.promotions
Browse files Browse the repository at this point in the history
  • Loading branch information
karlseguin committed Dec 28, 2014
1 parent c75dcd4 commit 557d56e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (c *Cache) worker() {
case item := <-c.deletables:
atomic.AddInt64(&c.size, -item.size)
if item.element == nil {
item.promotions = -2
atomic.StoreInt32(&item.promotions, -2)
} else {
c.list.Remove(item.element)
}
Expand All @@ -165,10 +165,10 @@ func (c *Cache) worker() {

func (c *Cache) doPromote(item *Item) bool {
//already deleted
if item.promotions == -2 {
if atomic.LoadInt32(&item.promotions) == -2 {
return false
}
item.promotions = 0
atomic.StoreInt32(&item.promotions, 0)
if item.element != nil { //not a new item
c.list.MoveToFront(item.element)
return false
Expand Down

0 comments on commit 557d56e

Please sign in to comment.