forked from libevent/libevent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace big chain of if/thens in epoll.c with a table lookup
This should save a bunch of branches by doing instead a lookup in a nice static table. To ensure correctness, the table is generated from a Python script, included with this commit.
- Loading branch information
1 parent
b8b8aa5
commit 8c83eb6
Showing
2 changed files
with
231 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/python | ||
|
||
def get(old,wc,rc): | ||
if ('xxx' in (rc, wc)): | ||
return "0",-1 | ||
|
||
if ('add' in (rc, wc)): | ||
events = [] | ||
if rc == 'add' or (rc != 'del' and 'r' in old): | ||
events.append("EPOLLIN") | ||
if wc == 'add' or (wc != 'del' and 'w' in old): | ||
events.append("EPOLLOUT") | ||
|
||
if old == "0": | ||
op = "EPOLL_CTL_ADD" | ||
else: | ||
op = "EPOLL_CTL_MOD" | ||
return "|".join(events), op | ||
|
||
if ('del' in (rc, wc)): | ||
op = "EPOLL_CTL_DEL" | ||
if rc == 'del': | ||
if wc == 'del': | ||
events = "EPOLLIN|EPOLLOUT" | ||
elif 'w' in old: | ||
events = "EPOLLOUT" | ||
op = "EPOLL_CTL_MOD" | ||
else: | ||
events = "EPOLLIN" | ||
else: | ||
assert wc == 'del' | ||
if 'r' in old: | ||
events = "EPOLLIN" | ||
op = "EPOLL_CTL_MOD" | ||
else: | ||
events = "EPOLLOUT" | ||
return events, op | ||
|
||
return 0, 0 | ||
|
||
|
||
def fmt(op, ev, old, wc, rc): | ||
entry = "{ %s, %s },"%(op, ev) | ||
assert len(entry)<=36 | ||
sp = " "*(36-len(entry)) | ||
print "\t%s%s/* old=%2s, write:%3s, read:%3s */" % ( | ||
entry, sp, old, wc, rc) | ||
|
||
|
||
for old in ('0','r','w','rw'): | ||
for wc in ('0', 'add', 'del', 'xxx'): | ||
for rc in ('0', 'add', 'del', 'xxx'): | ||
|
||
op,ev = get(old,wc,rc) | ||
|
||
fmt(op, ev, old, wc, rc) | ||
|