You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2017/03/01 23:35:12 UTC
[07/21] geode-native git commit: GEODE-2494: Replaced spin lock
protected counter with std::atomic.
GEODE-2494: Replaced spin lock protected counter with std::atomic.
- Cleanup C++11 standards.
Project: http://git-wip-us.apache.org/repos/asf/geode-native/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode-native/commit/a801e5eb
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/a801e5eb
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/a801e5eb
Branch: refs/heads/develop
Commit: a801e5eb7be915532beab7e8dfe196430789372d
Parents: 15f1407
Author: Jacob Barrett <jb...@pivotal.io>
Authored: Wed Feb 15 23:33:21 2017 -0800
Committer: Jacob Barrett <jb...@pivotal.io>
Committed: Wed Mar 1 15:10:42 2017 -0800
----------------------------------------------------------------------
src/cppcache/src/EventId.cpp | 35 ++++++++++++++++-------------------
1 file changed, 16 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode-native/blob/a801e5eb/src/cppcache/src/EventId.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/EventId.cpp b/src/cppcache/src/EventId.cpp
index a987b76..6f944a6 100644
--- a/src/cppcache/src/EventId.cpp
+++ b/src/cppcache/src/EventId.cpp
@@ -18,31 +18,29 @@
#include "EventId.hpp"
#include "GeodeTypeIdsImpl.hpp"
#include "ClientProxyMembershipID.hpp"
-#include <ace/TSS_T.h>
-#include <ace/OS.h>
-#include <ace/INET_Addr.h>
+#include <cstring>
+#include <atomic>
namespace apache {
namespace geode {
namespace client {
-// to be used only with ACE_TSS<> or WinTSS<>
class EventIdTSS {
private:
- static SpinLock s_eidThrIdLock;
- static int64_t s_eidThrId;
+ static std::atomic<int64_t> s_eidThrId;
int64_t m_eidThrTSS;
int64_t m_eidSeqTSS;
+ ~EventIdTSS() = default;
+ EventIdTSS(const EventIdTSS&) = delete;
+ EventIdTSS& operator=(const EventIdTSS&) = delete;
+
public:
// this should get called just once per thread due to first access to TSS
EventIdTSS() {
- {
- SpinLockGuard _guard(s_eidThrIdLock);
- m_eidThrTSS = ++s_eidThrId;
- }
+ m_eidThrTSS = ++s_eidThrId;
m_eidSeqTSS = 0;
}
@@ -52,13 +50,12 @@ class EventIdTSS {
inline int64_t getSeqNum() { return m_eidSeqTSS - 1; }
- static ACE_TSS<EventIdTSS> s_eventId;
+ static thread_local EventIdTSS s_eventId;
}; // class EventIdTSS
-SpinLock EventIdTSS::s_eidThrIdLock;
-int64_t EventIdTSS::s_eidThrId = 0;
-ACE_TSS<EventIdTSS> EventIdTSS::s_eventId;
+std::atomic<int64_t> EventIdTSS::s_eidThrId;
+thread_local EventIdTSS EventIdTSS::s_eventId;
void EventId::toData(DataOutput& output) const {
// This method is always expected to write out nonstatic distributed
@@ -162,18 +159,18 @@ EventId::EventId(bool doInit, uint32_t reserveSize,
}
for (uint32_t i = 0; i < reserveSize; i++) {
- EventIdTSS::s_eventId->getAndIncEidSeq();
+ EventIdTSS::s_eventId.getAndIncEidSeq();
}
}
void EventId::initFromTSS() {
- m_eidThr = EventIdTSS::s_eventId->getEidThr();
- m_eidSeq = EventIdTSS::s_eventId->getAndIncEidSeq();
+ m_eidThr = EventIdTSS::s_eventId.getEidThr();
+ m_eidSeq = EventIdTSS::s_eventId.getAndIncEidSeq();
}
void EventId::initFromTSS_SameThreadIdAndSameSequenceId() {
- m_eidThr = EventIdTSS::s_eventId->getEidThr();
- m_eidSeq = EventIdTSS::s_eventId->getSeqNum();
+ m_eidThr = EventIdTSS::s_eventId.getEidThr();
+ m_eidSeq = EventIdTSS::s_eventId.getSeqNum();
}
EventId::~EventId() {}