You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by di...@apache.org on 2019/02/15 09:45:00 UTC
[rocketmq-client-cpp] branch master updated: [ISSUE #77] optimize
process of allocate opaque by atomic without lock.
This is an automated email from the ASF dual-hosted git repository.
dinglei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-cpp.git
The following commit(s) were added to refs/heads/master by this push:
new af5a1bf [ISSUE #77] optimize process of allocate opaque by atomic without lock.
af5a1bf is described below
commit af5a1bfd4c28b12931845dfb5f7c1ddec2d458a4
Author: James <yw...@hotmail.com>
AuthorDate: Fri Feb 15 17:44:55 2019 +0800
[ISSUE #77] optimize process of allocate opaque by atomic without lock.
[ISSUE #77] optimize process of allocate opaque by atomic without lock.
---
src/protocol/RemotingCommand.cpp | 11 +++++------
src/protocol/RemotingCommand.h | 4 ++--
2 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/src/protocol/RemotingCommand.cpp b/src/protocol/RemotingCommand.cpp
index 46e274b..9f9b3e5 100644
--- a/src/protocol/RemotingCommand.cpp
+++ b/src/protocol/RemotingCommand.cpp
@@ -21,8 +21,9 @@
#include "SessionCredentials.h"
namespace rocketmq {
+
boost::atomic<int> RemotingCommand::s_seqNumber;
-boost::mutex RemotingCommand::m_clock;
+
//<!************************************************************************
RemotingCommand::RemotingCommand(int code,
CommandHeader* pExtHeader /* = NULL */)
@@ -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_relaxed) & numeric_limits<int>::max();
}
RemotingCommand::RemotingCommand(int code, string language, int version,
diff --git a/src/protocol/RemotingCommand.h b/src/protocol/RemotingCommand.h
index 53f2014..254d964 100755
--- a/src/protocol/RemotingCommand.h
+++ b/src/protocol/RemotingCommand.h
@@ -75,13 +75,13 @@ class RemotingCommand {
string m_msgBody;
map<string, string> m_extFields;
- static boost::mutex m_clock;
MemoryBlock m_head;
MemoryBlock m_body;
//<!save here
Json::Value m_parsedJson;
- static boost::atomic<int> s_seqNumber;
unique_ptr<CommandHeader> m_pExtHeader;
+
+ static boost::atomic<int> s_seqNumber;
};
} //<!end namespace;