BewareMyPower commented on code in PR #16940:
URL: https://github.com/apache/pulsar/pull/16940#discussion_r943435952


##########
pulsar-client-cpp/lib/PatternMultiTopicsConsumerImpl.cc:
##########
@@ -55,8 +55,9 @@ void 
PatternMultiTopicsConsumerImpl::autoDiscoveryTimerTask(const boost::system:
         return;
     }
 
-    if (state_ != Ready) {
-        LOG_ERROR("Error in autoDiscoveryTimerTask consumer state not ready: " 
<< state_);
+    const auto state = state_.load();
+    if (state != Ready) {
+        LOG_ERROR("Error in autoDiscoveryTimerTask consumer state not ready: " 
<< state);

Review Comment:
   This change is redundant. `if (state_ != Ready)` is equivalent to `if 
(state_.load() != Ready)`, see 
https://en.cppreference.com/w/cpp/atomic/atomic/operator_T.
   
   Usually when `load()` is called once, we can simplify
   
   ```c++
   const auto x = atomicValue.load();
   if (x == expectedValue) { /* ... */ }
   ```
   
   to
   
   ```c++
   if (atomicValue == expectedValue) { /* ... */ }
   ```



##########
pulsar-client-cpp/lib/PartitionedConsumerImpl.cc:
##########
@@ -583,11 +550,11 @@ void PartitionedConsumerImpl::getPartitionMetadata() {
 
 void PartitionedConsumerImpl::handleGetPartitions(Result result,
                                                   const LookupDataResultPtr& 
lookupDataResult) {
-    Lock stateLock(mutex_);
     if (state_ != Ready) {
         return;
     }
 
+    Lock stateLock(mutex_);

Review Comment:
   ```suggestion
   ```
   
   `stateLock` is used to protect `state_` before. We don't need the lock 
anymore. Here it is because the previous code forgets to unlock.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to