Project

General

Profile

Bug #5355 » patch.diff

Glass_saga (Masaki Matsushita), 09/23/2011 11:53 AM

View differences:

lib/sync.rb
140 140

  
141 141
    while true
142 142
      @sync_mutex.synchronize do
143
        if sync_try_lock_sub(m)
144
          return self
145
        else
146
          if sync_sh_locker[Thread.current]
147
            sync_upgrade_waiting.push [Thread.current, sync_sh_locker[Thread.current]]
148
            sync_sh_locker.delete(Thread.current)
143
        begin
144
          if sync_try_lock_sub(m)
145
            return self
149 146
          else
150
            sync_waiting.push Thread.current
147
            if sync_sh_locker[Thread.current]
148
              sync_upgrade_waiting.push [Thread.current, sync_sh_locker[Thread.current]]
149
              sync_sh_locker.delete(Thread.current)
150
            else
151
              unless sync_waiting.include?(Thread.current) || sync_upgrade_waiting.reverse_each.any?{|w| w.first == Thread.current }
152
                sync_waiting.push Thread.current
153
              end
154
            end
155
            @sync_mutex.sleep
151 156
          end
152
          @sync_mutex.sleep
157
        ensure
158
          sync_waiting.delete(Thread.current)
153 159
        end
154 160
      end
155 161
    end