mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-25 16:30:25 +08:00
优化计数器
This commit is contained in:
@@ -66,13 +66,10 @@ func (this *Counter) Increase(key uint64, lifeSeconds int) uint64 {
|
|||||||
var index = int(key % this.countMaps)
|
var index = int(key % this.countMaps)
|
||||||
this.locker.RLock(index)
|
this.locker.RLock(index)
|
||||||
var item = this.itemMaps[index][key]
|
var item = this.itemMaps[index][key]
|
||||||
var l = len(this.itemMaps[index])
|
|
||||||
this.locker.RUnlock(index)
|
this.locker.RUnlock(index)
|
||||||
if item == nil { // no need to care about duplication
|
if item == nil {
|
||||||
if l > maxItemsPerGroup {
|
// no need to care about duplication
|
||||||
return 1
|
// always insert new item even when itemMap is full
|
||||||
}
|
|
||||||
|
|
||||||
item = NewItem(lifeSeconds)
|
item = NewItem(lifeSeconds)
|
||||||
this.locker.Lock(index)
|
this.locker.Lock(index)
|
||||||
this.itemMaps[index][key] = item
|
this.itemMaps[index][key] = item
|
||||||
|
|||||||
Reference in New Issue
Block a user