mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-03 22:45:13 +08:00
queue add RLockRange method.
This commit is contained in:
@@ -78,7 +78,7 @@ func (q *Queue) Get(i int) interface{} {
|
||||
i += q.count
|
||||
}
|
||||
if i < 0 || i >= q.count {
|
||||
panic("queue: Get() called with index out of range")
|
||||
return nil
|
||||
}
|
||||
// bitwise modulus
|
||||
return q.buf[(q.head+i)&(len(q.buf)-1)]
|
||||
|
||||
@@ -43,6 +43,15 @@ func (q *SyncQueue) Pop() interface{} {
|
||||
return q.que.Pop()
|
||||
}
|
||||
|
||||
func (q *SyncQueue) RLockRange(f func(interface{})) {
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
for i := 0; i < q.que.Length(); i++ {
|
||||
f(q.Get(i))
|
||||
}
|
||||
}
|
||||
|
||||
func NewSyncQueue() *SyncQueue {
|
||||
syncQueue := SyncQueue{}
|
||||
syncQueue.que = NewQueue()
|
||||
|
||||
Reference in New Issue
Block a user