From 3700db51399e4949ed314ad0545d037b7762064e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 7 Jan 2010 09:28:57 +0000 Subject: POSIX_MQ#notify only works on GNU/Linux for now SIGEV_THREAD is not easy to implement, so many platforms do not implement it. --- README | 7 +++++-- lib/posix_mq.rb | 8 +++++++- test/test_posix_mq.rb | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README b/README index 5be5478..a7d9e3d 100644 --- a/README +++ b/README @@ -11,13 +11,16 @@ network-aware message queue implementations. == Features -* Supports message notifications via signals and block execution - in a separate thread. +* Supports message notifications via signals on all platforms * Supports portable non-blocking operation. Under Linux 2.6.6+ and FreeBSD 7.2+, POSIX_MQ objects may even be used with event notification mechanisms such as IO.select. +* Supports notifications via block execution in a separate thread + on platforms that implement SIGEV_THREAD for mq_notify(3), + currently only GNU/Linux. + * Optional timeouts may be applied to send and receive operations. * Thread-safe blocking operations under Ruby 1.9, releases GVL diff --git a/lib/posix_mq.rb b/lib/posix_mq.rb index 91f4140..8897050 100644 --- a/lib/posix_mq.rb +++ b/lib/posix_mq.rb @@ -37,6 +37,12 @@ class POSIX_MQ # first message and must be reset/reenabled for subsequent # notifications. This block will execute in a separate Ruby # Thread (and thus will safely have the GVL by default). + # + # This method is only supported on platforms that implement + # SIGEV_THREAD functionality in mq_notify(3). So far we only + # know of glibc + Linux supporting this. Please let us + # know if your platform can support this functionality and + # are willing to test for us def notify(&block) block.arity == 1 or raise ArgumentError, "arity of notify block must be 1" @@ -58,7 +64,7 @@ class POSIX_MQ self.notify = w self.notify_thread = thr nil - end + end if RUBY_PLATFORM =~ /linux/ end diff --git a/test/test_posix_mq.rb b/test/test_posix_mq.rb index 58ee6e5..1fa029b 100644 --- a/test/test_posix_mq.rb +++ b/test/test_posix_mq.rb @@ -249,7 +249,7 @@ class Test_POSIX_MQ < Test::Unit::TestCase assert_nothing_raised { @mq.notify { |mq| q << "hi" } } @mq << "bye" assert_equal "hi", q.pop - end + end if POSIX_MQ.respond_to?(:notify) def test_notify_thread q = Queue.new @@ -262,5 +262,5 @@ class Test_POSIX_MQ < Test::Unit::TestCase assert x.instance_of?(Thread) assert Thread.current != x assert ! thr.alive? - end + end if POSIX_MQ.respond_to?(:notify) end -- cgit v1.2.3-24-ge0c7