about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-04-03 00:28:01 +0000
committerEric Wong <normalperson@yhbt.net>2013-04-03 00:28:01 +0000
commit446033931a8051656585bacd6277e9823a3e62e8 (patch)
tree4ddf5970c0b329f522126485a460d302c36ec6ab
parent2f5c82c26aeaf3536deace3521097d3e9eaefc20 (diff)
downloadsleepy_penguin-446033931a8051656585bacd6277e9823a3e62e8.tar.gz
I was about to change this to the FIONBIO here myself before
I realized we do not frequently _change_ file flags.
-rw-r--r--ext/sleepy_penguin/util.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/ext/sleepy_penguin/util.c b/ext/sleepy_penguin/util.c
index 301cc92..5cf84bf 100644
--- a/ext/sleepy_penguin/util.c
+++ b/ext/sleepy_penguin/util.c
@@ -123,6 +123,13 @@ void rb_sp_set_nonblock(int fd)
                 rb_sys_fail("fcntl(F_GETFL)");
         if ((flags & O_NONBLOCK) == O_NONBLOCK)
                 return;
+        /*
+         * Note: while this is Linux-only and we could safely rely on
+         * ioctl(FIONBIO), needing F_SETFL is an uncommon path, and
+         * F_GETFL is lockless.  ioctl(FIONBIO) always acquires a spin
+         * lock, so it's more expensive even if we do not need to change
+         * anything.
+         */
         flags = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
         if (flags == -1)
                 rb_sys_fail("fcntl(F_SETFL)");