aboutsummaryrefslogtreecommitdiffstats
path: root/lib/sync.rb
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-30 18:55:28 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-30 18:55:28 +0000
commitc62ec3ae1aa5ac3b3f7f2756763a41c5703c06ca (patch)
tree1fbfbf05623163f771da48384cf02aaeefb74178 /lib/sync.rb
parent028ca79f986448221361bf2e9c16ec9c3e3b734b (diff)
downloadruby-c62ec3ae1aa5ac3b3f7f2756763a41c5703c06ca.tar.gz
* lib/sync.rb (Sync_m#sync_synchronize): add Thread.async_interrupt_timing
for protecting from async interrupt. * lib/sync.rb (Sync_m#sync_lock): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/sync.rb')
-rw-r--r--lib/sync.rb43
1 files changed, 23 insertions, 20 deletions
diff --git a/lib/sync.rb b/lib/sync.rb
index 524f3804e9..378c659b7b 100644
--- a/lib/sync.rb
+++ b/lib/sync.rb
@@ -135,25 +135,26 @@ module Sync_m
def sync_lock(m = EX)
return unlock if m == UN
-
- while true
- @sync_mutex.synchronize do
- begin
- if sync_try_lock_sub(m)
- return self
- else
- if sync_sh_locker[Thread.current]
- sync_upgrade_waiting.push [Thread.current, sync_sh_locker[Thread.current]]
- sync_sh_locker.delete(Thread.current)
+ Thread.async_interrupt_timing(StandardError => :on_blocking) do
+ while true
+ @sync_mutex.synchronize do
+ begin
+ if sync_try_lock_sub(m)
+ return self
else
- unless sync_waiting.include?(Thread.current) || sync_upgrade_waiting.reverse_each.any?{|w| w.first == Thread.current }
- sync_waiting.push Thread.current
+ if sync_sh_locker[Thread.current]
+ sync_upgrade_waiting.push [Thread.current, sync_sh_locker[Thread.current]]
+ sync_sh_locker.delete(Thread.current)
+ else
+ unless sync_waiting.include?(Thread.current) || sync_upgrade_waiting.reverse_each.any?{|w| w.first == Thread.current }
+ sync_waiting.push Thread.current
+ end
end
+ @sync_mutex.sleep
end
- @sync_mutex.sleep
+ ensure
+ sync_waiting.delete(Thread.current)
end
- ensure
- sync_waiting.delete(Thread.current)
end
end
end
@@ -226,11 +227,13 @@ module Sync_m
end
def sync_synchronize(mode = EX)
- sync_lock(mode)
- begin
- yield
- ensure
- sync_unlock
+ Thread.async_interrupt_timing(StandardError => :on_blocking) do
+ sync_lock(mode)
+ begin
+ yield
+ ensure
+ sync_unlock
+ end
end
end