class Concurrent::ReentrantReadWriteLock

def try_write_lock

Returns:
  • (Boolean) - true if the lock is successfully acquired
def try_write_lock
  if (held = @HeldCount.value) >= WRITE_LOCK_HELD
    @HeldCount.value = held + WRITE_LOCK_HELD
    return true
  else
    c = @Counter.value
    if !waiting_or_running_writer?(c) &&
       running_readers(c) == held &&
       @Counter.compare_and_set(c, c+RUNNING_WRITER)
       @HeldCount.value = held + WRITE_LOCK_HELD
      return true
    end
  end
  false
end