mirror of
https://github.com/matrix-org/dendrite
synced 2024-12-13 23:02:46 +00:00
Tweaks
This commit is contained in:
parent
8fd878c75a
commit
f9ab3f4b81
1 changed files with 8 additions and 9 deletions
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
type fifoQueue struct {
|
||||
frames []*inputTask
|
||||
tasks []*inputTask
|
||||
count int
|
||||
mutex sync.Mutex
|
||||
notifs chan struct{}
|
||||
|
@ -18,16 +18,15 @@ func newFIFOQueue() *fifoQueue {
|
|||
return q
|
||||
}
|
||||
|
||||
func (q *fifoQueue) push(frame *inputTask) bool {
|
||||
func (q *fifoQueue) push(frame *inputTask) {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
q.frames = append(q.frames, frame)
|
||||
q.tasks = append(q.tasks, frame)
|
||||
q.count++
|
||||
select {
|
||||
case q.notifs <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (q *fifoQueue) pop() (*inputTask, bool) {
|
||||
|
@ -36,14 +35,14 @@ func (q *fifoQueue) pop() (*inputTask, bool) {
|
|||
if q.count == 0 {
|
||||
return nil, false
|
||||
}
|
||||
frame := q.frames[0]
|
||||
q.frames[0] = nil
|
||||
q.frames = q.frames[1:]
|
||||
frame := q.tasks[0]
|
||||
q.tasks[0] = nil
|
||||
q.tasks = q.tasks[1:]
|
||||
q.count--
|
||||
if q.count == 0 {
|
||||
// Force a GC of the underlying array, since it might have
|
||||
// grown significantly if the queue was hammered for some reason
|
||||
q.frames = nil
|
||||
q.tasks = nil
|
||||
}
|
||||
return frame, true
|
||||
}
|
||||
|
@ -51,7 +50,7 @@ func (q *fifoQueue) pop() (*inputTask, bool) {
|
|||
func (q *fifoQueue) wait() <-chan struct{} {
|
||||
q.mutex.Lock()
|
||||
defer q.mutex.Unlock()
|
||||
if q.count > 0 {
|
||||
if q.count > 0 && len(q.notifs) == 0 {
|
||||
ch := make(chan struct{})
|
||||
close(ch)
|
||||
return ch
|
||||
|
|
Loading…
Reference in a new issue