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:39:19 UTC
geode-native git commit: GEODE-2602: Fixes C++11 issues with C++/CLI.
Repository: geode-native
Updated Branches:
refs/heads/feature/GEODE-2602 c79cb05b0 -> cf68eff24
GEODE-2602: Fixes C++11 issues with C++/CLI.
Project: http://git-wip-us.apache.org/repos/asf/geode-native/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode-native/commit/cf68eff2
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/cf68eff2
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/cf68eff2
Branch: refs/heads/feature/GEODE-2602
Commit: cf68eff24bb9db035674be240647b982e9870fc9
Parents: c79cb05
Author: Jacob Barrett <jb...@pivotal.io>
Authored: Wed Mar 15 17:38:02 2017 +0000
Committer: Jacob Barrett <jb...@pivotal.io>
Committed: Wed Mar 15 17:38:02 2017 +0000
----------------------------------------------------------------------
src/cppcache/include/geode/CacheStatistics.hpp | 2 +
src/cppcache/include/geode/SharedBase.hpp | 15 +++---
src/cppcache/src/PooledBasePool.cpp | 56 +++++++++++++++++++++
src/cppcache/src/PooledBasePool.hpp | 42 ++--------------
src/cppcache/src/SharedBase.cpp | 16 ++++--
src/cppcache/src/Utils.cpp | 12 ++++-
6 files changed, 94 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode-native/blob/cf68eff2/src/cppcache/include/geode/CacheStatistics.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/include/geode/CacheStatistics.hpp b/src/cppcache/include/geode/CacheStatistics.hpp
index b7fbcfc..85e9d4b 100644
--- a/src/cppcache/include/geode/CacheStatistics.hpp
+++ b/src/cppcache/include/geode/CacheStatistics.hpp
@@ -22,6 +22,8 @@
#include "geode_globals.hpp"
#include "geode_types.hpp"
+#include <atomic>
+
/**
* @file
*/
http://git-wip-us.apache.org/repos/asf/geode-native/blob/cf68eff2/src/cppcache/include/geode/SharedBase.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/include/geode/SharedBase.hpp b/src/cppcache/include/geode/SharedBase.hpp
index 2528278..84389f4 100644
--- a/src/cppcache/include/geode/SharedBase.hpp
+++ b/src/cppcache/include/geode/SharedBase.hpp
@@ -22,7 +22,9 @@
* limitations under the License.
*/
-#include <atomic>
+#include <memory>
+#include <functional>
+
#include "geode_globals.hpp"
/** @file
@@ -41,7 +43,7 @@ namespace client {
class CPPCACHE_EXPORT SharedBase {
public:
/** Constructor. */
- inline SharedBase() : m_refCount(0) {}
+ SharedBase();
/** Atomically increment reference count */
void preserveSB() const;
@@ -53,16 +55,17 @@ class CPPCACHE_EXPORT SharedBase {
void releaseSB() const;
/** @return the reference count */
- inline int32_t refCount() { return m_refCount; }
+ int32_t refCount();
protected:
inline SharedBase(bool noInit) {}
- inline SharedBase(const SharedBase&) {}
+ inline SharedBase(const SharedBase&) : SharedBase() {};
- virtual ~SharedBase() {}
+ virtual ~SharedBase() {};
private:
- std::atomic<int32_t> m_refCount;
+ // workaround for std::atomic not allowed in managed code.
+ mutable std::unique_ptr<void, std::function<void(void*)>> m_refCount;
void operator=(const SharedBase& rhs);
};
http://git-wip-us.apache.org/repos/asf/geode-native/blob/cf68eff2/src/cppcache/src/PooledBasePool.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/PooledBasePool.cpp b/src/cppcache/src/PooledBasePool.cpp
new file mode 100644
index 0000000..f7f0b89
--- /dev/null
+++ b/src/cppcache/src/PooledBasePool.cpp
@@ -0,0 +1,56 @@
+
+#include <mutex>
+
+#include "PooledBasePool.hpp"
+#include "util/concurrent/spinlock_mutex.hpp"
+
+namespace apache {
+namespace geode {
+namespace client {
+
+using util::concurrent::spinlock_mutex;
+
+PooledBasePool::~PooledBasePool() {
+ std::lock_guard<spinlock_mutex> guard(m_poolLock);
+ while (!m_pooldata.empty()) {
+ PooledBase* item = m_pooldata.front();
+ m_pooldata.pop_front();
+ delete item;
+ }
+}
+
+void PooledBasePool::returnToPool(PooledBase* poolable) {
+ poolable->prePool();
+ {
+ std::lock_guard<spinlock_mutex> guard(m_poolLock);
+ m_pooldata.push_back(const_cast<PooledBase*>(poolable));
+ }
+}
+
+PooledBase* PooledBasePool::takeFromPool() {
+ PooledBase* result = nullptr;
+ {
+ std::lock_guard<spinlock_mutex> guard(m_poolLock);
+ if (!m_pooldata.empty()) {
+ result = m_pooldata.front();
+ m_pooldata.pop_front();
+ }
+ }
+ if (result != nullptr) {
+ result->postPool();
+ }
+ return result;
+}
+
+void PooledBasePool::clear() {
+ std::lock_guard<spinlock_mutex> guard(m_poolLock);
+ while (!m_pooldata.empty()) {
+ PooledBase* item = m_pooldata.front();
+ m_pooldata.pop_front();
+ delete item;
+ }
+}
+
+} // namespace client
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/cf68eff2/src/cppcache/src/PooledBasePool.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/PooledBasePool.hpp b/src/cppcache/src/PooledBasePool.hpp
index 2e5cc23..2608d97 100644
--- a/src/cppcache/src/PooledBasePool.hpp
+++ b/src/cppcache/src/PooledBasePool.hpp
@@ -25,7 +25,6 @@
#include "PooledBase.hpp"
#include <deque>
-#include <mutex>
#include "util/concurrent/spinlock_mutex.hpp"
namespace apache {
@@ -41,46 +40,13 @@ class CPPCACHE_EXPORT PooledBasePool {
public:
PooledBasePool() : m_poolLock(), m_pooldata() {}
- ~PooledBasePool() {
- std::lock_guard<spinlock_mutex> guard(m_poolLock);
- while (!m_pooldata.empty()) {
- PooledBase* item = m_pooldata.front();
- m_pooldata.pop_front();
- delete item;
- }
- }
+ ~PooledBasePool();
- inline void returnToPool(PooledBase* poolable) {
- poolable->prePool();
- {
- std::lock_guard<spinlock_mutex> guard(m_poolLock);
- m_pooldata.push_back(const_cast<PooledBase*>(poolable));
- }
- }
+ void returnToPool(PooledBase* poolable);
- inline PooledBase* takeFromPool() {
- PooledBase* result = nullptr;
- {
- std::lock_guard<spinlock_mutex> guard(m_poolLock);
- if (!m_pooldata.empty()) {
- result = m_pooldata.front();
- m_pooldata.pop_front();
- }
- }
- if (result != nullptr) {
- result->postPool();
- }
- return result;
- }
+ PooledBase* takeFromPool();
- inline void clear() {
- std::lock_guard<spinlock_mutex> guard(m_poolLock);
- while (!m_pooldata.empty()) {
- PooledBase* item = m_pooldata.front();
- m_pooldata.pop_front();
- delete item;
- }
- }
+ void clear();
};
} // namespace client
} // namespace geode
http://git-wip-us.apache.org/repos/asf/geode-native/blob/cf68eff2/src/cppcache/src/SharedBase.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/SharedBase.cpp b/src/cppcache/src/SharedBase.cpp
index c1d9f0c..ec3ad91 100644
--- a/src/cppcache/src/SharedBase.cpp
+++ b/src/cppcache/src/SharedBase.cpp
@@ -17,18 +17,28 @@
#include <geode/SharedBase.hpp>
-#include <typeinfo>
+#include <atomic>
+#include <memory>
+#include <functional>
namespace apache {
namespace geode {
namespace client {
+using Counter = std::atomic<int32_t>;
+
+SharedBase::SharedBase() : m_refCount((void*) new Counter(0), [](void* ptr){
+ delete reinterpret_cast<Counter*>(ptr);
+}) {}
+
+int32_t SharedBase::refCount() { return *reinterpret_cast<Counter*>(m_refCount.get()); }
+
void SharedBase::preserveSB() const {
- ++const_cast<SharedBase*>(this)->m_refCount;
+ ++*reinterpret_cast<Counter*>(this->m_refCount.get());
}
void SharedBase::releaseSB() const {
- if (--const_cast<SharedBase*>(this)->m_refCount == 0) {
+ if (--*reinterpret_cast<Counter*>(this->m_refCount.get()) == 0) {
delete this;
}
}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/cf68eff2/src/cppcache/src/Utils.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/Utils.cpp b/src/cppcache/src/Utils.cpp
index e954f6c..6ba5f93 100644
--- a/src/cppcache/src/Utils.cpp
+++ b/src/cppcache/src/Utils.cpp
@@ -22,16 +22,20 @@
#include <cstdio>
#include <chrono>
+#ifdef _WIN32
+
namespace apache {
namespace geode {
namespace client {
-#ifdef _WIN32
-
pNew Utils::s_pNew = NULL;
pDelete Utils::s_pDelete = NULL;
bool Utils::s_setNewAndDelete = false;
+} // namespace client
+} // namespace geode
+} // namespace apache
+
void* operator new(size_t size) {
if (!Utils::s_pNew) {
apache::geode::client::setDefaultNewAndDelete();
@@ -52,6 +56,10 @@ void operator delete[](void* p) { operator delete(p); }
#endif // _WIN32
+namespace apache {
+namespace geode {
+namespace client {
+
int RandGen::operator()(size_t max) {
unsigned int seed = static_cast<unsigned int>(
std::chrono::system_clock::now().time_since_epoch().count());