1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00

Cleanup queue in time

This commit is contained in:
V2Ray 2015-10-10 21:29:37 +02:00
parent ab151cc053
commit 7fe9683f28

View File

@ -71,8 +71,7 @@ func (queue *TimedQueue) RemovedEntries() <-chan interface{} {
} }
func (queue *TimedQueue) cleanup(tick <-chan time.Time) { func (queue *TimedQueue) cleanup(tick <-chan time.Time) {
for { for now := range tick {
now := <-tick
queue.access.RLock() queue.access.RLock()
queueLen := queue.queue.Len() queueLen := queue.queue.Len()
queue.access.RUnlock() queue.access.RUnlock()
@ -80,16 +79,18 @@ func (queue *TimedQueue) cleanup(tick <-chan time.Time) {
continue continue
} }
nowSec := now.UTC().Unix() nowSec := now.UTC().Unix()
queue.access.RLock() for {
firstEntryTime := queue.queue[0].timeSec queue.access.RLock()
queue.access.RUnlock() entry := queue.queue[0]
if firstEntryTime > nowSec { queue.access.RUnlock()
continue if entry.timeSec > nowSec {
} break
queue.access.Lock() }
firstEntryValue := heap.Pop(&queue.queue).(*timedQueueEntry).value queue.access.Lock()
queue.access.Unlock() heap.Pop(&queue.queue)
queue.access.Unlock()
queue.removed <- firstEntryValue queue.removed <- entry.value
}
} }
} }