You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2019/01/28 03:57:08 UTC

[GitHub] lizhanhui commented on a change in pull request #78: [ISSUE #77] optimize process of allocate opaque by atomic without lock.

lizhanhui commented on a change in pull request #78: [ISSUE #77] optimize process of allocate opaque by atomic without lock.
URL: https://github.com/apache/rocketmq-client-cpp/pull/78#discussion_r251277350
 
 

 ##########
 File path: src/protocol/RemotingCommand.cpp
 ##########
 @@ -32,11 +33,9 @@ RemotingCommand::RemotingCommand(int code,
       m_flag(0),
       m_remark(""),
       m_pExtHeader(pExtHeader) {
-  boost::lock_guard<boost::mutex> lock(m_clock);
-  m_opaque = (s_seqNumber.load(boost::memory_order_acquire)) %
-             (numeric_limits<int>::max());
-  s_seqNumber.store(m_opaque, boost::memory_order_release);
-  ++s_seqNumber;
+
+  // mask sign bit
+  m_opaque = s_seqNumber.fetch_add(1, boost::memory_order_acq_rel) & numeric_limits<int>::max();
 
 Review comment:
   As we only need an atomic incremental number and no memory barrier is required, boost::memory_order_relaxed should be fine here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services