librelist archives

« back to archive

[PATCH] util: comment explaining non-use of FIONBIO

[PATCH] util: comment explaining non-use of FIONBIO

From:
Eric Wong
Date:
2013-04-03 @ 00:30
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