* 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
This commit is contained in:
parent
028ca79f98
commit
c62ec3ae1a
@ -1,3 +1,9 @@
|
|||||||
|
Sat Dec 1 03:49:45 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Sat Dec 1 03:38:04 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
Sat Dec 1 03:38:04 2012 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
|
||||||
|
|
||||||
* lib/thread.rb (ConditionVariable#broadcast): s/RuntimeError/StandardError/
|
* lib/thread.rb (ConditionVariable#broadcast): s/RuntimeError/StandardError/
|
||||||
|
43
lib/sync.rb
43
lib/sync.rb
@ -135,25 +135,26 @@ module Sync_m
|
|||||||
|
|
||||||
def sync_lock(m = EX)
|
def sync_lock(m = EX)
|
||||||
return unlock if m == UN
|
return unlock if m == UN
|
||||||
|
Thread.async_interrupt_timing(StandardError => :on_blocking) do
|
||||||
while true
|
while true
|
||||||
@sync_mutex.synchronize do
|
@sync_mutex.synchronize do
|
||||||
begin
|
begin
|
||||||
if sync_try_lock_sub(m)
|
if sync_try_lock_sub(m)
|
||||||
return self
|
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)
|
|
||||||
else
|
else
|
||||||
unless sync_waiting.include?(Thread.current) || sync_upgrade_waiting.reverse_each.any?{|w| w.first == Thread.current }
|
if sync_sh_locker[Thread.current]
|
||||||
sync_waiting.push 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
|
end
|
||||||
|
@sync_mutex.sleep
|
||||||
end
|
end
|
||||||
@sync_mutex.sleep
|
ensure
|
||||||
|
sync_waiting.delete(Thread.current)
|
||||||
end
|
end
|
||||||
ensure
|
|
||||||
sync_waiting.delete(Thread.current)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -226,11 +227,13 @@ module Sync_m
|
|||||||
end
|
end
|
||||||
|
|
||||||
def sync_synchronize(mode = EX)
|
def sync_synchronize(mode = EX)
|
||||||
sync_lock(mode)
|
Thread.async_interrupt_timing(StandardError => :on_blocking) do
|
||||||
begin
|
sync_lock(mode)
|
||||||
yield
|
begin
|
||||||
ensure
|
yield
|
||||||
sync_unlock
|
ensure
|
||||||
|
sync_unlock
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user