ruby-concurrency/concurrent-ruby

View on GitHub
lib/concurrent-ruby/concurrent/atomic/reentrant_read_write_lock.rb

Summary

Maintainability
C
1 day
Test Coverage

Method acquire_read_lock has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

    def acquire_read_lock
      if (held = @HeldCount.value) > 0
        # If we already have a lock, there's no need to wait
        if held & READ_LOCK_MASK == 0
          # But we do need to update the counter, if we were holding a write
Severity: Minor
Found in lib/concurrent-ruby/concurrent/atomic/reentrant_read_write_lock.rb - About 3 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method acquire_write_lock has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

    def acquire_write_lock
      if (held = @HeldCount.value) >= WRITE_LOCK_HELD
        # if we already have a write (exclusive) lock, there's no need to wait
        @HeldCount.value = held + WRITE_LOCK_HELD
        return true
Severity: Minor
Found in lib/concurrent-ruby/concurrent/atomic/reentrant_read_write_lock.rb - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method acquire_read_lock has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def acquire_read_lock
      if (held = @HeldCount.value) > 0
        # If we already have a lock, there's no need to wait
        if held & READ_LOCK_MASK == 0
          # But we do need to update the counter, if we were holding a write
Severity: Minor
Found in lib/concurrent-ruby/concurrent/atomic/reentrant_read_write_lock.rb - About 1 hr to fix

    Method acquire_write_lock has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def acquire_write_lock
          if (held = @HeldCount.value) >= WRITE_LOCK_HELD
            # if we already have a write (exclusive) lock, there's no need to wait
            @HeldCount.value = held + WRITE_LOCK_HELD
            return true
    Severity: Minor
    Found in lib/concurrent-ruby/concurrent/atomic/reentrant_read_write_lock.rb - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                      @ReadQueue.ns_wait if running_writer?
      Severity: Major
      Found in lib/concurrent-ruby/concurrent/atomic/reentrant_read_write_lock.rb - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                    elsif @Counter.compare_and_set(c, c+1)
                      @HeldCount.value = held + 1
                      return true
        Severity: Major
        Found in lib/concurrent-ruby/concurrent/atomic/reentrant_read_write_lock.rb - About 45 mins to fix

          Method try_read_lock has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def try_read_lock
                if (held = @HeldCount.value) > 0
                  if held & READ_LOCK_MASK == 0
                    # If we hold a write lock, but not a read lock...
                    @Counter.update { |c| c + 1 }
          Severity: Minor
          Found in lib/concurrent-ruby/concurrent/atomic/reentrant_read_write_lock.rb - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          There are no issues that match your filters.

          Category
          Status