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/15 17:51:14 UTC
[13/34] geode-native git commit: GEODE-2494: Replace SpinLock with
spinlock_mutex.
GEODE-2494: Replace SpinLock with spinlock_mutex.
- Cleanup C++ 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/30c6fc7f
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/30c6fc7f
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/30c6fc7f
Branch: refs/heads/feature/GEODE-2602
Commit: 30c6fc7f9f19e988dedb41a16620496b32c0ae70
Parents: eee5d17
Author: Jacob Barrett <jb...@pivotal.io>
Authored: Tue Feb 21 21:55:33 2017 -0800
Committer: Jacob Barrett <jb...@pivotal.io>
Committed: Wed Mar 15 10:44:22 2017 -0700
----------------------------------------------------------------------
src/cppcache/src/LRUEntriesMap.cpp | 48 +++++++++++++++++----------------
src/cppcache/src/LRUEntriesMap.hpp | 21 ++++++++-------
2 files changed, 36 insertions(+), 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode-native/blob/30c6fc7f/src/cppcache/src/LRUEntriesMap.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/LRUEntriesMap.cpp b/src/cppcache/src/LRUEntriesMap.cpp
index 4b30513..154a1bd 100644
--- a/src/cppcache/src/LRUEntriesMap.cpp
+++ b/src/cppcache/src/LRUEntriesMap.cpp
@@ -20,6 +20,9 @@
#include "MapSegment.hpp"
#include "CacheImpl.hpp"
+#include <mutex>
+#include "util/concurrent/spinlock_mutex.hpp"
+
namespace apache {
namespace geode {
namespace client {
@@ -48,11 +51,6 @@ class CPPCACHE_EXPORT TestMapAction : public virtual LRUAction {
virtual LRUAction::Action getType() { return LRUAction::LOCAL_DESTROY; }
friend class LRUAction;
};
-} // namespace client
-} // namespace geode
-} // namespace apache
-
-using namespace apache::geode::client;
LRUEntriesMap::LRUEntriesMap(EntryFactory* entryFactory, RegionInternal* region,
const LRUAction::Action& lruAction,
@@ -67,18 +65,18 @@ LRUEntriesMap::LRUEntriesMap(EntryFactory* entryFactory, RegionInternal* region,
m_validEntries(0),
m_heapLRUEnabled(heapLRUEnabled) {
m_currentMapSize = 0;
- m_action = NULL;
- m_evictionControllerPtr = NULL;
+ m_action = nullptr;
+ m_evictionControllerPtr = nullptr;
// translate action type to an instance.
- if (region == NULL) {
+ if (region == nullptr) {
m_action = new TestMapAction(this);
} else {
m_action = LRUAction::newLRUAction(lruAction, region, this);
m_name = region->getName();
CacheImpl* cImpl = region->getCacheImpl();
- if (cImpl != NULL) {
+ if (cImpl != nullptr) {
m_evictionControllerPtr = cImpl->getEvictionController();
- if (m_evictionControllerPtr != NULL) {
+ if (m_evictionControllerPtr != nullptr) {
m_evictionControllerPtr->registerRegion(m_name);
LOGINFO("Heap LRU eviction controller registered region %s",
m_name.c_str());
@@ -88,7 +86,7 @@ LRUEntriesMap::LRUEntriesMap(EntryFactory* entryFactory, RegionInternal* region,
}
void LRUEntriesMap::close() {
- if (m_evictionControllerPtr != NULL) {
+ if (m_evictionControllerPtr != nullptr) {
m_evictionControllerPtr->updateRegionHeapInfo((-1 * (m_currentMapSize)));
m_evictionControllerPtr->deregisterRegion(m_name);
}
@@ -137,7 +135,7 @@ GfErrType LRUEntriesMap::create(const CacheableKeyPtr& key,
m_lruList.appendEntry(mePtr);
me = mePtr;
}
- if (m_evictionControllerPtr != NULL) {
+ if (m_evictionControllerPtr != nullptr) {
int64_t newSize =
static_cast<int64_t>(Utils::checkAndGetObjectSize(newValue));
newSize += static_cast<int64_t>(Utils::checkAndGetObjectSize(key));
@@ -238,7 +236,7 @@ GfErrType LRUEntriesMap::invalidate(const CacheableKeyPtr& key,
} else {
newSize -= sizeof(void*);
}
- if (m_evictionControllerPtr != NULL) {
+ if (m_evictionControllerPtr != nullptr) {
if (newSize != 0) {
updateMapSize(newSize);
}
@@ -253,12 +251,12 @@ GfErrType LRUEntriesMap::put(const CacheableKeyPtr& key,
int destroyTracker, VersionTagPtr versionTag,
bool& isUpdate, DataInput* delta) {
MapSegment* segmentRPtr = segmentFor(key);
- GF_D_ASSERT(segmentRPtr != NULL);
+ GF_D_ASSERT(segmentRPtr != nullptr);
GfErrType err = GF_NOERR;
bool segmentLocked = false;
{
- if (m_action != NULL &&
+ if (m_action != nullptr &&
m_action->getType() == LRUAction::OVERFLOW_TO_DISK) {
segmentRPtr->acquire();
segmentLocked = true;
@@ -297,7 +295,7 @@ GfErrType LRUEntriesMap::put(const CacheableKeyPtr& key,
}
}
// SpinLock& lock = segmentRPtr->getSpinLock();
- // SpinLockGuard mapGuard( lock );
+ // std::lock_guard<spinlock_mutex> mapGuard( lock );
// TODO: when can newValue be a token ??
if (CacheableToken::isToken(newValue) && !isOldValueToken) {
@@ -328,7 +326,7 @@ GfErrType LRUEntriesMap::put(const CacheableKeyPtr& key,
}
}
}
- if (m_evictionControllerPtr != NULL) {
+ if (m_evictionControllerPtr != nullptr) {
int64_t newSize =
static_cast<int64_t>(Utils::checkAndGetObjectSize(newValue));
/*
@@ -372,7 +370,8 @@ bool LRUEntriesMap::get(const CacheableKeyPtr& key, CacheablePtr& returnPtr,
bool doProcessLRU = false;
MapSegment* segmentRPtr = segmentFor(key);
bool segmentLocked = false;
- if (m_action != NULL && m_action->getType() == LRUAction::OVERFLOW_TO_DISK) {
+ if (m_action != nullptr &&
+ m_action->getType() == LRUAction::OVERFLOW_TO_DISK) {
segmentRPtr->acquire();
segmentLocked = true;
}
@@ -406,14 +405,14 @@ bool LRUEntriesMap::get(const CacheableKeyPtr& key, CacheablePtr& returnPtr,
VersionTagPtr versionTag;
if (GF_NOERR ==
segmentRPtr->put(key, tmpObj, mePtr, oldValue, 0, 0, isUpdate,
- versionTag, NULL)) {
+ versionTag, nullptr)) {
// m_entriesRetrieved++;
++m_validEntries;
lruProps.clearEvicted();
m_lruList.appendEntry(nodeToMark);
}
doProcessLRU = true;
- if (m_evictionControllerPtr != NULL) {
+ if (m_evictionControllerPtr != nullptr) {
int64_t newSize = 0;
if (tmpObj != NULLPTR) {
newSize += static_cast<int64_t>(
@@ -475,7 +474,7 @@ GfErrType LRUEntriesMap::remove(const CacheableKeyPtr& key,
m_pmPtr->destroy(key, persistenceInfo);
}
}
- if (m_evictionControllerPtr != NULL) {
+ if (m_evictionControllerPtr != nullptr) {
int64_t sizeToRemove = static_cast<int64_t>(key->objectSize());
sizeToRemove += static_cast<int64_t>(result->objectSize());
updateMapSize((-1 * sizeToRemove));
@@ -488,9 +487,9 @@ GfErrType LRUEntriesMap::remove(const CacheableKeyPtr& key,
void LRUEntriesMap::updateMapSize(int64_t size) {
// TODO: check and remove null check since this has already been done
// by all the callers
- if (m_evictionControllerPtr != NULL) {
+ if (m_evictionControllerPtr != nullptr) {
{
- SpinLockGuard __guard(m_mapInfoLock);
+ std::lock_guard<spinlock_mutex> __guard(m_mapInfoLock);
m_currentMapSize += size;
}
m_evictionControllerPtr->updateRegionHeapInfo(size);
@@ -511,3 +510,6 @@ CacheablePtr LRUEntriesMap::getFromDisk(const CacheableKeyPtr& key,
}
return tmpObj;
}
+} // namespace client
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/30c6fc7f/src/cppcache/src/LRUEntriesMap.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/LRUEntriesMap.hpp b/src/cppcache/src/LRUEntriesMap.hpp
index 3efcbeb..074bb1e 100644
--- a/src/cppcache/src/LRUEntriesMap.hpp
+++ b/src/cppcache/src/LRUEntriesMap.hpp
@@ -1,8 +1,3 @@
-#pragma once
-
-#ifndef GEODE_LRUENTRIESMAP_H_
-#define GEODE_LRUENTRIESMAP_H_
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -20,6 +15,11 @@
* limitations under the License.
*/
+#pragma once
+
+#ifndef GEODE_LRUENTRIESMAP_H_
+#define GEODE_LRUENTRIESMAP_H_
+
#include <geode/geode_globals.hpp>
#include <geode/Cache.hpp>
#include "ConcurrentEntriesMap.hpp"
@@ -27,7 +27,8 @@
#include "LRUList.hpp"
#include "LRUMapEntry.hpp"
#include "MapEntryT.hpp"
-#include "SpinLock.hpp"
+
+#include "util/concurrent/spinlock_mutex.hpp"
#include "NonCopyable.hpp"
@@ -65,7 +66,7 @@ class CPPCACHE_EXPORT LRUEntriesMap : public ConcurrentEntriesMap,
PersistenceManagerPtr m_pmPtr;
EvictionController* m_evictionControllerPtr;
int64_t m_currentMapSize;
- SpinLock m_mapInfoLock;
+ spinlock_mutex m_mapInfoLock;
std::string m_name;
AtomicInc m_validEntries;
bool m_heapLRUEnabled;
@@ -83,7 +84,7 @@ class CPPCACHE_EXPORT LRUEntriesMap : public ConcurrentEntriesMap,
CacheablePtr& oldValue, int updateCount,
int destroyTracker, VersionTagPtr versionTag,
bool& isUpdate = EntriesMap::boolVal,
- DataInput* delta = NULL);
+ DataInput* delta = nullptr);
virtual GfErrType invalidate(const CacheableKeyPtr& key, MapEntryImplPtr& me,
CacheablePtr& oldValue,
VersionTagPtr versionTag);
@@ -113,8 +114,8 @@ class CPPCACHE_EXPORT LRUEntriesMap : public ConcurrentEntriesMap,
virtual void close();
inline bool mustEvict() const {
- if (m_action == NULL) {
- LOGFINE("Eviction action is NULL");
+ if (m_action == nullptr) {
+ LOGFINE("Eviction action is nullptr");
return false;
}
if (m_action->overflows()) {