You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by mm...@apache.org on 2019/10/24 04:48:18 UTC

[geode-native] branch develop updated: GEODE-7347: Guarding CacheImpl during Cache move to avoid race condition. (#542)

This is an automated email from the ASF dual-hosted git repository.

mmartell pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git


The following commit(s) were added to refs/heads/develop by this push:
     new 3a51a80  GEODE-7347: Guarding CacheImpl during Cache move to avoid race condition. (#542)
3a51a80 is described below

commit 3a51a80c27c4e811526eb489a305f08647381955
Author: Matthew Reddington <mr...@pivotal.io>
AuthorDate: Wed Oct 23 21:48:09 2019 -0700

    GEODE-7347: Guarding CacheImpl during Cache move to avoid race condition. (#542)
    
    Co-authored-by: Mike Oleske<mo...@pivotal.io>
---
 cppcache/include/geode/Cache.hpp |  2 +-
 cppcache/src/Cache.cpp           | 13 ++++++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/cppcache/include/geode/Cache.hpp b/cppcache/include/geode/Cache.hpp
index f1f1d6b..3a0635c 100644
--- a/cppcache/include/geode/Cache.hpp
+++ b/cppcache/include/geode/Cache.hpp
@@ -254,7 +254,7 @@ class APACHE_GEODE_EXPORT Cache : public GeodeCache {
         bool readPdxSerialized,
         const std::shared_ptr<AuthInitialize>& authInitialize);
 
-  std::shared_ptr<CacheImpl> m_cacheImpl;
+  std::unique_ptr<CacheImpl> m_cacheImpl;
 
  protected:
   static bool isPoolInMultiuserMode(std::shared_ptr<Region> regionPtr);
diff --git a/cppcache/src/Cache.cpp b/cppcache/src/Cache.cpp
index e041eb0..af740c9 100644
--- a/cppcache/src/Cache.cpp
+++ b/cppcache/src/Cache.cpp
@@ -112,16 +112,19 @@ Cache::Cache(const std::shared_ptr<Properties>& dsProp,
           new CacheImpl(this, dsProp, ignorePdxUnreadFields, readPdxSerialized,
                         authInitialize))) {}
 
-Cache::Cache(Cache&& other) noexcept
-    : m_cacheImpl(std::move(other.m_cacheImpl)) {
-  m_cacheImpl->setCache(this);
+Cache::Cache(Cache&& other) noexcept {
+  other.m_cacheImpl->doIfDestroyNotPending([&]() {
+    m_cacheImpl = std::move(other.m_cacheImpl);
+    m_cacheImpl->setCache(this);
+  });
 }
 
 Cache& Cache::operator=(Cache&& other) noexcept {
-  if (this != &other) {
+  other.m_cacheImpl->doIfDestroyNotPending([&]() {
     m_cacheImpl = std::move(other.m_cacheImpl);
     m_cacheImpl->setCache(this);
-  }
+  });
+
   return *this;
 }