def compare_and_set_state(next_state, expected_current) # :nodoc:
      mutex.lock
      if @state == expected_current
        @state = next_state
        true
      else
        false
      end
    ensure
      mutex.unlock
    end
def compare_and_set_state(next_state, expected_current) # :nodoc:
      mutex.lock
      if @state == expected_current
        @state = next_state
        true
      else
        false
      end
    ensure
      mutex.unlock
    end
Atomic compare and set operation. State is set to `next_state` only if
 `current state == expected_current`.

 @param [Symbol] next_state
 @param [Symbol] expected_current

 @return [Boolean]
   TRrue is state is changed, false otherwise

 @!visibility private