guard all access to item.promotions
This commit is contained in:
parent
c75dcd4c12
commit
557d56ec6f
1 changed files with 3 additions and 3 deletions
6
cache.go
6
cache.go
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue