From d4b5c8d7c1abe673915aca8674c5e0b55a0aaffa Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 11 Apr 2013 04:17:35 +0000 Subject: avoid ENOMEM checking in common code paths ENOMEM from syscalls such as inotify_add_watch and epoll_ctl are from the lack of kernel memory, so even a successful rb_gc() is unlikely to be able to reap memory taken from those slab caches. --- ext/sleepy_penguin/epoll.c | 10 ++-------- ext/sleepy_penguin/inotify.c | 11 +++-------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/ext/sleepy_penguin/epoll.c b/ext/sleepy_penguin/epoll.c index 82a545f..ed45fbd 100644 --- a/ext/sleepy_penguin/epoll.c +++ b/ext/sleepy_penguin/epoll.c @@ -139,14 +139,8 @@ static VALUE epctl(VALUE self, VALUE _op, VALUE io, VALUE events) pack_event_data(&event, io); rv = epoll_ctl(epfd, op, fd, &event); - if (rv < 0) { - if (errno == ENOMEM) { - rb_gc(); - rv = epoll_ctl(epfd, op, fd, &event); - } - if (rv < 0) - rb_sys_fail("epoll_ctl"); - } + if (rv < 0) + rb_sys_fail("epoll_ctl"); return Qnil; } diff --git a/ext/sleepy_penguin/inotify.c b/ext/sleepy_penguin/inotify.c index f858dc4..4c606a4 100644 --- a/ext/sleepy_penguin/inotify.c +++ b/ext/sleepy_penguin/inotify.c @@ -89,14 +89,9 @@ static VALUE add_watch(VALUE self, VALUE path, VALUE vmask) uint32_t mask = rb_sp_get_uflags(self, vmask); int rc = inotify_add_watch(fd, pathname, mask); - if (rc == -1) { - if (errno == ENOMEM) { - rb_gc(); - rc = inotify_add_watch(fd, pathname, mask); - } - if (rc == -1) - rb_sys_fail("inotify_add_watch"); - } + if (rc == -1) + rb_sys_fail("inotify_add_watch"); + return UINT2NUM((uint32_t)rc); } -- cgit v1.2.3-24-ge0c7