diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sync.rb | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/sync.rb b/lib/sync.rb index a57b789d55..524f3804e9 100644 --- a/lib/sync.rb +++ b/lib/sync.rb @@ -138,16 +138,22 @@ module Sync_m while true @sync_mutex.synchronize do - 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) + begin + if sync_try_lock_sub(m) + return self else - 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 end end |