sleepy_penguin RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <normalperson@yhbt.net>
To: sleepy.penguin@librelist.org
Subject: [sleepy.penguin] [PATCH 2/2] inotify: thread-safe Inotify#take for rbx
Date: Fri, 12 Apr 2013 22:25:50 +0000	[thread overview]
Message-ID: <1365805550-1593-2-git-send-email-normalperson@yhbt.net> (raw)
In-Reply-To: 1365805550-1593-1-git-send-email-normalperson@yhbt.net

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



      reply	other threads:[~2013-04-12 22:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-12 22:25 [sleepy.penguin] [PATCH 1/2] inotify: use thread-local internal buffer Eric Wong
2013-04-12 22:25 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/sleepy_penguin/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1365805550-1593-2-git-send-email-normalperson@yhbt.net \
    --to=normalperson@yhbt.net \
    --cc=sleepy.penguin@librelist.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).