* [sleepy.penguin] [PATCH] util: comment explaining non-use of FIONBIO
@ 2013-04-03 0:30 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2013-04-03 0:30 UTC (permalink / raw)
To: sleepy.penguin
I was about to change this to the FIONBIO here myself before
I realized we do not frequently _change_ file flags.
---
ext/sleepy_penguin/util.c | 7 +++++++
1 file changed, 7 insertions(+)
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)");
--
1.8.2.279.g631bc94
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2013-04-03 0:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-03 0:30 [sleepy.penguin] [PATCH] util: comment explaining non-use of FIONBIO Eric Wong
Code repositories for project(s) associated with this public inbox
https://yhbt.net/sleepy_penguin.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).