summaryrefslogtreecommitdiff
path: root/lib/monitor.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/monitor.rb')
-rw-r--r--lib/monitor.rb27
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/monitor.rb b/lib/monitor.rb
index 288ed755ea..e99cbd4baa 100644
--- a/lib/monitor.rb
+++ b/lib/monitor.rb
@@ -87,6 +87,9 @@
# MonitorMixin module.
#
module MonitorMixin
+ EXCEPTION_NEVER = {Exception => :never}.freeze
+ EXCEPTION_IMMEDIATE = {Exception => :immediate}.freeze
+
#
# FIXME: This isn't documented in Nutshell.
#
@@ -103,13 +106,17 @@ module MonitorMixin
# even if no other thread doesn't signal.
#
def wait(timeout = nil)
- @monitor.__send__(:mon_check_owner)
- count = @monitor.__send__(:mon_exit_for_cond)
- begin
- @cond.wait(@monitor.instance_variable_get(:@mon_mutex), timeout)
- return true
- ensure
- @monitor.__send__(:mon_enter_for_cond, count)
+ Thread.handle_interrupt(EXCEPTION_NEVER) do
+ @monitor.__send__(:mon_check_owner)
+ count = @monitor.__send__(:mon_exit_for_cond)
+ begin
+ Thread.handle_interrupt(EXCEPTION_IMMEDIATE) do
+ @cond.wait(@monitor.instance_variable_get(:@mon_mutex), timeout)
+ end
+ return true
+ ensure
+ @monitor.__send__(:mon_enter_for_cond, count)
+ end
end
end
@@ -221,11 +228,13 @@ module MonitorMixin
# +MonitorMixin+.
#
def mon_synchronize
- mon_enter
+ # Prevent interrupt on handling interrupts; for example timeout errors
+ # it may break locking state.
+ Thread.handle_interrupt(Exception => :never){ mon_enter }
begin
yield
ensure
- mon_exit
+ Thread.handle_interrupt(EXCEPTION_NEVER){ mon_exit }
end
end
alias synchronize mon_synchronize