Skip to content
Permalink
Browse files

Reduce the size of the RunEpollOnce stack frame by 800kb. This fixes …

…the long-standing epoll+threads issue (#84)
  • Loading branch information...
tmm1 committed Apr 29, 2009
1 parent 6626063 commit 1f6a4c912256b8110af94e270f7dde486f3c9d75
Showing with 8 additions and 6 deletions.
  1. +5 −6 ext/em.cpp
  2. +3 −0 ext/em.h
@@ -440,26 +440,25 @@ bool EventMachine_t::_RunEpollOnce()
{
#ifdef HAVE_EPOLL
assert (epfd != -1);
struct epoll_event ev [MaxEpollDescriptors];
int s;

#ifdef BUILD_FOR_RUBY
TRAP_BEG;
#endif
s = epoll_wait (epfd, ev, MaxEpollDescriptors, 50);
s = epoll_wait (epfd, epoll_events, MaxEpollDescriptors, 50);
#ifdef BUILD_FOR_RUBY
TRAP_END;
#endif

if (s > 0) {
for (int i=0; i < s; i++) {
EventableDescriptor *ed = (EventableDescriptor*) ev[i].data.ptr;
EventableDescriptor *ed = (EventableDescriptor*) epoll_events[i].data.ptr;

if (ev[i].events & (EPOLLERR | EPOLLHUP))
if (epoll_events[i].events & (EPOLLERR | EPOLLHUP))
ed->ScheduleClose (false);
if (ev[i].events & EPOLLIN)
if (epoll_events[i].events & EPOLLIN)
ed->Read();
if (ev[i].events & EPOLLOUT) {
if (epoll_events[i].events & EPOLLOUT) {
ed->Write();
epoll_ctl (epfd, EPOLL_CTL_MOD, ed->GetSocket(), ed->GetEpollEvent());
// Ignoring return value
@@ -179,6 +179,9 @@ class EventMachine_t
private:
bool bEpoll;
int epfd; // Epoll file-descriptor
#ifdef HAVE_EPOLL
struct epoll_event epoll_events [MaxEpollDescriptors];
#endif

bool bKqueue;
int kqfd; // Kqueue file-descriptor

13 comments on commit 1f6a4c9

@ice799

This comment has been minimized.

Copy link

replied Apr 29, 2009

Word.

@raggi

This comment has been minimized.

Copy link
Member

replied Apr 29, 2009

nice one boys :)

@nickmartini

This comment has been minimized.

Copy link

replied Apr 29, 2009

Awesome

@julien51

This comment has been minimized.

Copy link

replied Apr 29, 2009

yes!

@dmillar

This comment has been minimized.

Copy link

replied Apr 29, 2009

beautiful.

@libc

This comment has been minimized.

Copy link
Contributor

replied Apr 29, 2009

what about kqueue? it has stack array too, or it's too small to make any difference?

@libc

This comment has been minimized.

Copy link
Contributor

replied Apr 29, 2009

(it's 40000 bytes)

@imbaczek

This comment has been minimized.

Copy link

replied Apr 29, 2009

1337 gdb skillz, gj.

@seydar

This comment has been minimized.

Copy link

replied Apr 29, 2009

wouldn't it have been a roughly four line patch if you had kept the name the same? ev -> epoll_events

@raggi

This comment has been minimized.

Copy link
Member

replied Apr 30, 2009

yes, but it'd have stayed unreadable :)

@raggi

This comment has been minimized.

Copy link
Member

replied Apr 30, 2009

libc you're absolutely right, someone will likely get to that later this week, if the impact still exists then.

@seydar

This comment has been minimized.

Copy link

replied May 9, 2009

well done :-D a patch like this makes me happy

@eyberg

This comment has been minimized.

Copy link

replied May 21, 2009

jesus balls! nice find!

Please sign in to comment.
You can’t perform that action at this time.