def acquire_read_lock
      while(true)
        c = @counter.value
        raise ResourceLimitError, 'Too many reader threads' if max_readers?(c)

        if waiting_writer?(c)
          @reader_mutex.synchronize do
            @reader_q.wait(@reader_mutex) if waiting_writer?
          end

          while(true)
            c = @counter.value
            if running_writer?(c)
              @reader_mutex.synchronize do
                @reader_q.wait(@reader_mutex) if running_writer?
              end
            else
              return if @counter.compare_and_swap(c,c+1)
            end
          end
        else
          break if @counter.compare_and_swap(c,c+1)
        end
      end
      true
    end
def acquire_read_lock
      while(true)
        c = @counter.value
        raise ResourceLimitError, 'Too many reader threads' if max_readers?(c)

        if waiting_writer?(c)
          @reader_mutex.synchronize do
            @reader_q.wait(@reader_mutex) if waiting_writer?
          end

          while(true)
            c = @counter.value
            if running_writer?(c)
              @reader_mutex.synchronize do
                @reader_q.wait(@reader_mutex) if running_writer?
              end
            else
              return if @counter.compare_and_swap(c,c+1)
            end
          end
        else
          break if @counter.compare_and_swap(c,c+1)
        end
      end
      true
    end
Acquire a read lock. If a write lock has been acquired will block until
 it is released. Will not block if other read locks have been acquired.

 @return [Boolean]
   True if the lock is successfully acquired.

 @raise [Garcon::ResourceLimitError]
   If the maximum number of readers is exceeded.