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 D88031F435 for ; Fri, 12 Apr 2013 22:26:09 +0000 (UTC) Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id CD59873DEA for ; Fri, 12 Apr 2013 22:26:47 +0000 (UTC) MIME-Version: 1.0 Date: Fri, 12 Apr 2013 22:25:50 +0000 From: Eric Wong List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Message-Id: <1365805550-1593-2-git-send-email-normalperson@yhbt.net> Precedence: list References: <1365805550-1593-1-git-send-email-normalperson@yhbt.net> Sender: sleepy.penguin@librelist.org Subject: [sleepy.penguin] [PATCH 2/2] inotify: thread-safe Inotify#take for rbx To: sleepy.penguin@librelist.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Rubinius provides a Rubinius.synchronize helper for locking objects which do not otherwise have locks. We need to synchronize Inotify#take access to prevent the internal array from being clobbered. This avoids unnecessary locking overhead on MRI which maintains a GVL. --- lib/sleepy_penguin.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/sleepy_penguin.rb b/lib/sleepy_penguin.rb index c13eb0c..1888e3b 100644 --- a/lib/sleepy_penguin.rb +++ b/lib/sleepy_penguin.rb @@ -6,3 +6,18 @@ module SleepyPenguin end require 'sleepy_penguin_ext' require 'sleepy_penguin/epoll' + +# :stopdoc: +# +# We need to serialize Inotify#take for Rubinius since that has no GVL +# to protect the internal array +if defined?(SleepyPenguin::Inotify) && + defined?(Rubinius) && Rubinius.respond_to?(:synchronize) + class SleepyPenguin::Inotify + alias __take take + undef_method :take + def take(*args) + Rubinius.synchronize(@inotify_tmp) { __take(*args) } + end + end +end -- 1.8.2.1.366.ge2af9e3