From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS47066 71.19.144.0/20 X-Spam-Status: No, score=-1.9 required=3.0 tests=AWL,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: normalperson@yhbt.net Received: from zedshaw2.xen.prgmr.com (zedshaw2.xen.prgmr.com [71.19.156.177]) by dcvr.yhbt.net (Postfix) with ESMTP id 2C9BD1F5B8 for ; Wed, 3 Apr 2013 00:30:59 +0000 (UTC) Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id 9FAB774E1A for ; Wed, 3 Apr 2013 00:33:59 +0000 (UTC) MIME-Version: 1.0 Date: Wed, 3 Apr 2013 00:30:41 +0000 From: Eric Wong In-Reply-To: <20130403003041.GA23982@dcvr.yhbt.net> List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Message-Id: <20130403003041.GA23982@dcvr.yhbt.net> Precedence: list References: <20130403003041.GA23982@dcvr.yhbt.net> Sender: sleepy.penguin@librelist.org Subject: [sleepy.penguin] [PATCH] util: comment explaining non-use of FIONBIO To: sleepy.penguin@librelist.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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