Skip to content

Commit

Permalink
still apply slice style swapbuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
xtaci committed Jan 31, 2020
1 parent db75296 commit 1c63570
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions aio_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ func (p *poller) Watch(fd int) error {

func (p *poller) Wait(chEventNotify chan pollerEvents, die chan struct{}) {
events := make([]syscall.EpollEvent, maxEvents)
swapEvents := make(chan pollerEvents, 2)
for i := 0; i < cap(swapEvents); i++ {
swapEvents <- make([]event, 0, maxEvents)
swapEvents := make([]pollerEvents, 2)
swapIdx := 0
for i := 0; i < len(swapEvents); i++ {
swapEvents[i] = make([]event, 0, maxEvents)
}

for {
Expand All @@ -88,8 +89,9 @@ func (p *poller) Wait(chEventNotify chan pollerEvents, die chan struct{}) {
}

// note chan swap must not continue unexpected
pe := <-swapEvents
pe := swapEvents[swapIdx]
pe = pe[:0]
swapIdx = (swapIdx + 1) % len(swapEvents)

for i := 0; i < n; i++ {
ev := &events[i]
Expand All @@ -115,7 +117,6 @@ func (p *poller) Wait(chEventNotify chan pollerEvents, die chan struct{}) {

select {
case chEventNotify <- pe:
swapEvents <- pe
case <-die:
return
}
Expand Down

0 comments on commit 1c63570

Please sign in to comment.