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:22 UTC

[21/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/eda4f622
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/eda4f622
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/eda4f622

Branch: refs/heads/feature/GEODE-2602
Commit: eda4f62266de045d59514327ba239f4b76f2fcda
Parents: bee1455
Author: Jacob Barrett <jb...@pivotal.io>
Authored: Tue Feb 21 22:52:50 2017 -0800
Committer: Jacob Barrett <jb...@pivotal.io>
Committed: Wed Mar 15 10:44:23 2017 -0700

----------------------------------------------------------------------
 src/tests/cpp/fwk/UdpIpc.cpp           | 17 +++++++--
 src/tests/cpp/fwklib/FrameworkTest.cpp | 28 ++++++++++-----
 src/tests/cpp/fwklib/FrameworkTest.hpp |  6 +++-
 src/tests/cpp/security/Security.cpp    | 54 +++++++++++++++++------------
 src/tests/cpp/security/Security.hpp    |  2 +-
 5 files changed, 72 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode-native/blob/eda4f622/src/tests/cpp/fwk/UdpIpc.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwk/UdpIpc.cpp b/src/tests/cpp/fwk/UdpIpc.cpp
index d7efbd4..2b15fa6 100644
--- a/src/tests/cpp/fwk/UdpIpc.cpp
+++ b/src/tests/cpp/fwk/UdpIpc.cpp
@@ -35,8 +35,15 @@
 
 #include "fwklib/FwkExport.hpp"
 
-using namespace apache::geode::client;
-using namespace apache::geode::client::testframework;
+#include <mutex>
+#include <util/concurrent/spinlock_mutex.hpp>
+
+namespace apache {
+namespace geode {
+namespace client {
+namespace testframework {
+
+using util::concurrent::spinlock_mutex;
 
 static UdpIpc *g_test = NULL;
 
@@ -72,7 +79,7 @@ TESTTASK finalize() {
 // ----------------------------------------------------------------------------
 
 void UdpIpc::checkTest(const char *taskId) {
-  SpinLockGuard guard(m_lck);
+  std::lock_guard<spinlock_mutex> guard(m_lck);
   setTask(taskId);
   if (m_cache == NULLPTR) {
     PropertiesPtr pp = Properties::create();
@@ -258,3 +265,7 @@ void UdpIpc::doClient() {
   FWKINFO("Stop");
   FWKINFO("Client sent " << msgCnt << " messages");
 }
+}
+}
+}
+}

http://git-wip-us.apache.org/repos/asf/geode-native/blob/eda4f622/src/tests/cpp/fwklib/FrameworkTest.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/FrameworkTest.cpp b/src/tests/cpp/fwklib/FrameworkTest.cpp
index 9c3e642..c73383b 100644
--- a/src/tests/cpp/fwklib/FrameworkTest.cpp
+++ b/src/tests/cpp/fwklib/FrameworkTest.cpp
@@ -23,12 +23,18 @@
 #include <geode/PoolFactory.hpp>
 #include "PoolAttributes.hpp"
 
-using namespace apache::geode::client;
-using namespace apache::geode::client::testframework;
+#include <util/concurrent/spinlock_mutex.hpp>
+
+namespace apache {
+namespace geode {
+namespace client {
+namespace testframework {
+
+using util::concurrent::spinlock_mutex;
 
 // ========================================================================
 
-SpinLock FrameworkTest::m_lck;
+spinlock_mutex FrameworkTest::m_lck;
 
 // ----------------------------------------------------------------------------
 
@@ -47,7 +53,9 @@ FrameworkTest::FrameworkTest(const char* initArgs) {
   }
   m_bbc = new FwkBBClient(addr);
   m_deltaMicros = 0;
-  m_timeSync = new TimeSync(port, (int32_t*)&m_deltaMicros);
+  m_timeSync = new TimeSync(
+      port, const_cast<int32_t*>(
+                reinterpret_cast<volatile int32_t*>(&m_deltaMicros)));
   m_coll = new TestDriver(xml);
   TestClient::createTestClient(50, m_id);
   incClientCount();
@@ -253,7 +261,7 @@ void FrameworkTest::cacheInitialize(PropertiesPtr& props,
     if (isPdxSerialized) {
       cacheFactory->setPdxReadSerialized(isPdxSerialized);
     }
-  } catch (Exception e) {
+  } catch (Exception& e) {
     FWKEXCEPTION(
         "DistributedSystem::connect encountered Exception: " << e.getMessage());
   }
@@ -264,9 +272,9 @@ void FrameworkTest::cacheInitialize(PropertiesPtr& props,
     if (m_istransaction) {
       txManager = m_cache->getCacheTransactionManager();
     }
-  } catch (CacheExistsException ignore) {
+  } catch (CacheExistsException& ignore) {
     m_cache = NULLPTR;
-  } catch (Exception e) {
+  } catch (Exception& e) {
     FWKEXCEPTION(
         "CacheFactory::create encountered Exception: " << e.getMessage());
   }
@@ -283,7 +291,7 @@ void FrameworkTest::cacheFinalize() {
     try {
       destroyAllRegions();
       m_cache->close();
-    } catch (CacheClosedException ignore) {
+    } catch (CacheClosedException& ignore) {
     } catch (Exception& e) {
       FWKSEVERE("Caught an unexpected Exception during cache close: "
                 << e.getMessage());
@@ -544,3 +552,7 @@ std::string FrameworkTest::poolAttributesToString(PoolPtr& pool) {
   sString += "\n";
   return sString;
 }
+}  // namespace testframework
+}  // namespace client
+}  // namespace geode
+}  // namespace apache

http://git-wip-us.apache.org/repos/asf/geode-native/blob/eda4f622/src/tests/cpp/fwklib/FrameworkTest.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/FrameworkTest.hpp b/src/tests/cpp/fwklib/FrameworkTest.hpp
index cf5d2d7..2c422a9 100644
--- a/src/tests/cpp/fwklib/FrameworkTest.hpp
+++ b/src/tests/cpp/fwklib/FrameworkTest.hpp
@@ -26,11 +26,15 @@
 
 #include <string>
 
+#include <util/concurrent/spinlock_mutex.hpp>
+
 namespace apache {
 namespace geode {
 namespace client {
 namespace testframework {
 
+using util::concurrent::spinlock_mutex;
+
 class FrameworkTest  // Base class all test classes written for xml testing
                      // should derive from.
 {
@@ -46,7 +50,7 @@ class FrameworkTest  // Base class all test classes written for xml testing
   CachePtr m_cache;
   // bool m_istransaction;
   CacheTransactionManagerPtr txManager;
-  static SpinLock m_lck;
+  static spinlock_mutex m_lck;
 
 #ifdef _WIN32
   bool m_doneSetNewAndDelete;

http://git-wip-us.apache.org/repos/asf/geode-native/blob/eda4f622/src/tests/cpp/security/Security.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/security/Security.cpp b/src/tests/cpp/security/Security.cpp
index 0f4d850..fe9280d 100644
--- a/src/tests/cpp/security/Security.cpp
+++ b/src/tests/cpp/security/Security.cpp
@@ -41,16 +41,18 @@
 
 #include "security/CredentialGenerator.hpp"
 
-namespace FwkSecurity {
+#include <mutex>
+#include <util/concurrent/spinlock_mutex.hpp>
+
+namespace apache {
+namespace geode {
+namespace client {
+namespace testframework {
+namespace security {
+
 std::string REGIONSBB("Regions");
 std::string CLIENTSBB("ClientsBb");
 std::string READYCLIENTS("ReadyClients");
-}  // namespace FwkSecurity
-
-using namespace FwkSecurity;
-using namespace apache::geode::client;
-using namespace apache::geode::client::testframework;
-using namespace apache::geode::client::testframework::security;
 
 Security *g_test = NULL;
 
@@ -156,7 +158,7 @@ void Security::getClientSecurityParams(PropertiesPtr prop,
 // ----------------------------------------------------------------------------
 
 void Security::checkTest(const char *taskId) {
-  SpinLockGuard guard(m_lck);
+  std::lock_guard<spinlock_mutex> guard(m_lck);
   setTask(taskId);
   if (m_cache == NULLPTR || m_cache->isClosed()) {
     PropertiesPtr pp = Properties::create();
@@ -180,7 +182,7 @@ TESTTASK doCreateRegion(const char *taskId) {
   try {
     g_test->checkTest(taskId);
     result = g_test->createRegion();
-  } catch (FwkException ex) {
+  } catch (FwkException &ex) {
     result = FWK_SEVERE;
     FWKSEVERE("doCreateRegion caught exception: " << ex.getMessage());
   }
@@ -194,7 +196,7 @@ TESTTASK doCheckValues(const char *taskId) {
   try {
     g_test->checkTest(taskId);
     result = g_test->checkValues();
-  } catch (FwkException ex) {
+  } catch (FwkException &ex) {
     result = FWK_SEVERE;
     FWKSEVERE("doCheckValues caught exception: " << ex.getMessage());
   }
@@ -239,7 +241,7 @@ TESTTASK doRegisterInterestList(const char *taskId) {
   try {
     g_test->checkTest(taskId);
     result = g_test->registerInterestList();
-  } catch (FwkException ex) {
+  } catch (FwkException &ex) {
     result = FWK_SEVERE;
     FWKSEVERE("doRegisterInterestList caught exception: " << ex.getMessage());
   }
@@ -253,7 +255,7 @@ TESTTASK doRegisterRegexList(const char *taskId) {
   try {
     g_test->checkTest(taskId);
     result = g_test->registerRegexList();
-  } catch (FwkException ex) {
+  } catch (FwkException &ex) {
     result = FWK_SEVERE;
     FWKSEVERE("doRegisterRegexList caught exception: " << ex.getMessage());
   }
@@ -266,7 +268,7 @@ TESTTASK doUnRegisterRegexList(const char *taskId) {
   try {
     g_test->checkTest(taskId);
     result = g_test->unregisterRegexList();
-  } catch (FwkException ex) {
+  } catch (FwkException &ex) {
     result = FWK_SEVERE;
     FWKSEVERE("doRegisterRegexList caught exception: " << ex.getMessage());
   }
@@ -279,7 +281,7 @@ TESTTASK doRegisterAllKeys(const char *taskId) {
   try {
     g_test->checkTest(taskId);
     result = g_test->registerAllKeys();
-  } catch (FwkException ex) {
+  } catch (FwkException &ex) {
     result = FWK_SEVERE;
     FWKSEVERE("doRegisterAllKeys caught exception: " << ex.getMessage());
   }
@@ -468,7 +470,7 @@ int32_t Security::createRegion() {
                                                      << std::endl);
     result = FWK_SUCCESS;
 
-  } catch (Exception e) {
+  } catch (Exception &e) {
     FWKSEVERE("Security::createRegion FAILED -- caught exception: "
               << e.getMessage());
   } catch (FwkException &e) {
@@ -725,7 +727,7 @@ int32_t Security::checkValues() {
             << creates << " values from creates, " << updates
             << " values from updates, and " << unknowns << " unknown values.");
     result = FWK_SUCCESS;
-  } catch (Exception e) {
+  } catch (Exception &e) {
     FWKSEVERE(
         "Security::checkValues FAILED -- caught exception: " << e.getMessage());
   } catch (FwkException &e) {
@@ -780,17 +782,17 @@ RegionPtr Security::getRegionPtr(const char *reg) {
         FWKEXCEPTION("Failed to get region: " << name);
       }
     }
-  } catch (CacheClosedException e) {
+  } catch (CacheClosedException &e) {
     FWKEXCEPTION(
         "In Security::getRegionPtr()  CacheFactory::getInstance encountered "
         "CacheClosedException: "
         << e.getMessage());
-  } catch (EntryNotFoundException e) {
+  } catch (EntryNotFoundException &e) {
     FWKEXCEPTION(
         "In Security::getRegionPtr()  CacheFactory::getInstance encountered "
         "EntryNotFoundException: "
         << e.getMessage());
-  } catch (IllegalArgumentException e) {
+  } catch (IllegalArgumentException &e) {
     FWKEXCEPTION(
         "In Security::getRegionPtr()  CacheFactory::getInstance encountered "
         "IllegalArgumentException: "
@@ -930,7 +932,7 @@ void Security::runQuery(int32_t &queryCnt) {
               << endTime.usec() << " sec");
       queryCnt++;
     }
-  } catch (Exception e) {
+  } catch (Exception &e) {
     FWKEXCEPTION(
         "CacheServerTest::runQuery Caught Exception: " << e.getMessage());
   } catch (FwkException &e) {
@@ -1014,12 +1016,15 @@ int32_t Security::doEntryOperations() {
                 reinterpret_cast<const unsigned char *>(valBuf),
                 static_cast<int32_t>(strlen(valBuf)));
             int32_t *val =
-                (int32_t *)(dynCast<CacheableBytesPtr>(tmpValue)->value());
+                const_cast<int32_t *>(reinterpret_cast<const int32_t *>(
+                    dynCast<CacheableBytesPtr>(tmpValue)->value()));
             *val = (*val == keyVal) ? keyVal + 1
                                     : keyVal;  // alternate the value so that it
                                                // can be validated later.
             int64_t *adjNow =
-                (int64_t *)(dynCast<CacheableBytesPtr>(tmpValue)->value() + 4);
+                const_cast<int64_t *>(reinterpret_cast<const int64_t *>(
+                    dynCast<CacheableBytesPtr>(tmpValue)->value())) +
+                4;
             *adjNow = getAdjustedNowMicros();
           }
           regionPtr->put(keyPtr, tmpValue);
@@ -1075,3 +1080,8 @@ int32_t Security::doEntryOperations() {
           << " query.");
   return fwkResult;
 }
+}  // namespace security
+}  // namespace testframework
+}  // namespace client
+}  // namespace geode
+}  // namespace apache

http://git-wip-us.apache.org/repos/asf/geode-native/blob/eda4f622/src/tests/cpp/security/Security.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/security/Security.hpp b/src/tests/cpp/security/Security.hpp
index 909f37c..ac67c29 100644
--- a/src/tests/cpp/security/Security.hpp
+++ b/src/tests/cpp/security/Security.hpp
@@ -114,7 +114,7 @@ class Security : public FrameworkTest {
   CacheableBytesPtr* m_CValue;
 };
 
-}  //   namespace security
+}  // namespace security
 }  // namespace testframework
 }  // namespace client
 }  // namespace geode