Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2743C200C38 for ; Wed, 15 Mar 2017 18:51:10 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 26242160B7C; Wed, 15 Mar 2017 17:51:10 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3BDF7160B9D for ; Wed, 15 Mar 2017 18:51:08 +0100 (CET) Received: (qmail 11708 invoked by uid 500); 15 Mar 2017 17:51:05 -0000 Mailing-List: contact commits-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list commits@geode.apache.org Received: (qmail 10194 invoked by uid 99); 15 Mar 2017 17:51:05 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Mar 2017 17:51:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 41F8AF4B6C; Wed, 15 Mar 2017 17:51:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jbarrett@apache.org To: commits@geode.apache.org Date: Wed, 15 Mar 2017 17:51:31 -0000 Message-Id: <7a29ecdccc254b1d8d11fae0d0f97b74@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [30/34] geode-native git commit: GEODE-2602: Fixes C++11 issues with C++/CLI. archived-at: Wed, 15 Mar 2017 17:51:10 -0000 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/57e915b2 Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/57e915b2 Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/57e915b2 Branch: refs/heads/feature/GEODE-2602 Commit: 57e915b289e59d7fd5c3c97e4ade189cd798df73 Parents: e0145ac Author: Jacob Barrett Authored: Wed Mar 15 17:38:02 2017 +0000 Committer: Jacob Barrett Committed: Wed Mar 15 10:44:24 2017 -0700 ---------------------------------------------------------------------- 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/57e915b2/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 + /** * @file */ http://git-wip-us.apache.org/repos/asf/geode-native/blob/57e915b2/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 +#include +#include + #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 m_refCount; + // workaround for std::atomic not allowed in managed code. + mutable std::unique_ptr> m_refCount; void operator=(const SharedBase& rhs); }; http://git-wip-us.apache.org/repos/asf/geode-native/blob/57e915b2/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 + +#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 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 guard(m_poolLock); + m_pooldata.push_back(const_cast(poolable)); + } +} + +PooledBase* PooledBasePool::takeFromPool() { + PooledBase* result = nullptr; + { + std::lock_guard 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 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/57e915b2/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 -#include #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 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 guard(m_poolLock); - m_pooldata.push_back(const_cast(poolable)); - } - } + void returnToPool(PooledBase* poolable); - inline PooledBase* takeFromPool() { - PooledBase* result = nullptr; - { - std::lock_guard 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 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/57e915b2/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 -#include +#include +#include +#include namespace apache { namespace geode { namespace client { +using Counter = std::atomic; + +SharedBase::SharedBase() : m_refCount((void*) new Counter(0), [](void* ptr){ + delete reinterpret_cast(ptr); +}) {} + +int32_t SharedBase::refCount() { return *reinterpret_cast(m_refCount.get()); } + void SharedBase::preserveSB() const { - ++const_cast(this)->m_refCount; + ++*reinterpret_cast(this->m_refCount.get()); } void SharedBase::releaseSB() const { - if (--const_cast(this)->m_refCount == 0) { + if (--*reinterpret_cast(this->m_refCount.get()) == 0) { delete this; } } http://git-wip-us.apache.org/repos/asf/geode-native/blob/57e915b2/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 #include +#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( std::chrono::system_clock::now().time_since_epoch().count());