|  | @@ -3,17 +3,15 @@ package collect
 | 
											
												
													
														|  |  import (
 |  |  import (
 | 
											
												
													
														|  |  	"sync"
 |  |  	"sync"
 | 
											
												
													
														|  |  	"sync/atomic"
 |  |  	"sync/atomic"
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  | 
 |  | +	"github.com/v2ray/v2ray-core/common"
 | 
											
												
													
														|  |  )
 |  |  )
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  type Validity interface {
 |  |  type Validity interface {
 | 
											
												
													
														|  | 
 |  | +	common.Releasable
 | 
											
												
													
														|  |  	IsValid() bool
 |  |  	IsValid() bool
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -type entry struct {
 |  | 
 | 
											
												
													
														|  | -	key   string
 |  | 
 | 
											
												
													
														|  | -	value Validity
 |  | 
 | 
											
												
													
														|  | -}
 |  | 
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  |  type ValidityMap struct {
 |  |  type ValidityMap struct {
 | 
											
												
													
														|  |  	sync.RWMutex
 |  |  	sync.RWMutex
 | 
											
												
													
														|  |  	cache   map[string]Validity
 |  |  	cache   map[string]Validity
 | 
											
										
											
												
													
														|  | @@ -28,6 +26,11 @@ func NewValidityMap(cleanupIntervalSec int) *ValidityMap {
 | 
											
												
													
														|  |  }
 |  |  }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  func (this *ValidityMap) cleanup() {
 |  |  func (this *ValidityMap) cleanup() {
 | 
											
												
													
														|  | 
 |  | +	type entry struct {
 | 
											
												
													
														|  | 
 |  | +		key   string
 | 
											
												
													
														|  | 
 |  | +		value Validity
 | 
											
												
													
														|  | 
 |  | +	}
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  	entry2Remove := make([]entry, 0, 128)
 |  |  	entry2Remove := make([]entry, 0, 128)
 | 
											
												
													
														|  |  	this.RLock()
 |  |  	this.RLock()
 | 
											
												
													
														|  |  	for key, value := range this.cache {
 |  |  	for key, value := range this.cache {
 | 
											
										
											
												
													
														|  | @@ -40,10 +43,10 @@ func (this *ValidityMap) cleanup() {
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  	this.RUnlock()
 |  |  	this.RUnlock()
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -	for _, entry := range entry2Remove {
 |  | 
 | 
											
												
													
														|  | -		if !entry.value.IsValid() {
 |  | 
 | 
											
												
													
														|  | 
 |  | +	for _, e := range entry2Remove {
 | 
											
												
													
														|  | 
 |  | +		if !e.value.IsValid() {
 | 
											
												
													
														|  |  			this.Lock()
 |  |  			this.Lock()
 | 
											
												
													
														|  | -			delete(this.cache, entry.key)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			delete(this.cache, e.key)
 | 
											
												
													
														|  |  			this.Unlock()
 |  |  			this.Unlock()
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  	}
 |  |  	}
 |