Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pilot committed Oct 11, 2023
1 parent 16dc9d2 commit b8e0606
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion epoll.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package event

import (
"sync"
"syscall"
"time"
"unsafe"
Expand All @@ -19,6 +20,12 @@ const (
maxUint32 = 0xFFFFFFFF
)

var fdEvPool = sync.Pool{
New: func() any {
return new(fdEvent)
},
}

type fdEvent struct {
r *Event
w *Event
Expand Down Expand Up @@ -51,7 +58,7 @@ func (ep *poller) add(ev *Event) error {
if ok {
op = syscall.EPOLL_CTL_MOD
} else {
es = new(fdEvent)
es = fdEvPool.Get().(*fdEvent)
ep.fdEvents[ev.fd] = es
}

Expand Down Expand Up @@ -95,6 +102,7 @@ func (ep *poller) del(ev *Event) error {
op := syscall.EPOLL_CTL_DEL
if es.evs&(syscall.EPOLLIN|syscall.EPOLLOUT) == 0 {
delete(ep.fdEvents, ev.fd)
fdEvPool.Put(es)
} else {
op = syscall.EPOLL_CTL_MOD
}
Expand Down

0 comments on commit b8e0606

Please sign in to comment.