sync_unlock(m = EX) public

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
# File lib/sync.rb, line 156
  def sync_unlock(m = EX)
    Thread.critical = true
    if sync_mode == UN
      Thread.critical = false
      Err::UnknownLocker.Fail(Thread.current)
    end
    
    m = sync_mode if m == EX and sync_mode == SH
    
    runnable = false
    case m
    when UN
      Thread.critical = false
      Err::UnknownLocker.Fail(Thread.current)
      
    when EX
      if sync_ex_locker == Thread.current
        if (self.sync_ex_count = sync_ex_count - 1) == 0
          self.sync_ex_locker = nil
          if sync_sh_locker.include?(Thread.current)
            self.sync_mode = SH
          else
            self.sync_mode = UN
          end
          runnable = true
        end
      else
        Err::UnknownLocker.Fail(Thread.current)
      end
      
    when SH
      if (count = sync_sh_locker[Thread.current]).nil?
        Err::UnknownLocker.Fail(Thread.current)
      else
        if (sync_sh_locker[Thread.current] = count - 1) == 0 
          sync_sh_locker.delete(Thread.current)
          if sync_sh_locker.empty? and sync_ex_count == 0
            self.sync_mode = UN
            runnable = true
          end
        end
      end
    end
    
    if runnable
      if sync_upgrade_waiting.size > 0
        for k, v in sync_upgrade_waiting
          sync_sh_locker[k] = v
        end
        wait = sync_upgrade_waiting
        self.sync_upgrade_waiting = []
        Thread.critical = false
        
        for w, v in wait
          w.run
        end
      else
        wait = sync_waiting
        self.sync_waiting = []
        Thread.critical = false
        for w in wait
          w.run
        end
      end
    end
    
    Thread.critical = false
    self
  end
Register or log in to add new notes.