GEODE-2494: Replace SpinLock with spinlock_mutex.

- Cleanup C++11 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/cb8a6f32
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/cb8a6f32
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/cb8a6f32

Branch: refs/heads/feature/GEODE-2602
Commit: cb8a6f32900ece9dd27359e22f75044e6781d783
Parents: 42b1749
Author: Jacob Barrett <jbarr...@pivotal.io>
Authored: Wed Feb 15 22:29:37 2017 -0800
Committer: Jacob Barrett <jbarr...@pivotal.io>
Committed: Mon Mar 6 17:32:10 2017 -0800

----------------------------------------------------------------------
 src/cppcache/src/CqQueryVsdStats.cpp   | 63 ++++++++++++----------------
 src/cppcache/src/CqQueryVsdStats.hpp   | 24 ++++++-----
 src/cppcache/src/CqServiceVsdStats.cpp | 64 ++++++++++++-----------------
 src/cppcache/src/CqServiceVsdStats.hpp | 21 ++++++----
 4 files changed, 79 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode-native/blob/cb8a6f32/src/cppcache/src/CqQueryVsdStats.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/CqQueryVsdStats.cpp 
b/src/cppcache/src/CqQueryVsdStats.cpp
index 258d6d2..3076e2e 100644
--- a/src/cppcache/src/CqQueryVsdStats.cpp
+++ b/src/cppcache/src/CqQueryVsdStats.cpp
@@ -23,8 +23,12 @@
 #include <ace/Thread_Mutex.h>
 #include <ace/Singleton.h>
 
-const char* cqStatsName = (const char*)"CqQueryStatistics";
-const char* cqStatsDesc = (const char*)"Statistics for this cq query";
+#include <mutex>
+
+#include "util/concurrent/spinlock_mutex.hpp"
+
+const char* cqStatsName = "CqQueryStatistics";
+const char* cqStatsDesc = "Statistics for this cq query";
 
 
////////////////////////////////////////////////////////////////////////////////
 
@@ -32,31 +36,23 @@ namespace apache {
 namespace geode {
 namespace client {
 
-using namespace apache::geode::statistics;
+using statistics::StatisticsFactory;
+using util::concurrent::spinlock_mutex;
+using std::lock_guard;
 
 
////////////////////////////////////////////////////////////////////////////////
 
-CqQueryStatType* CqQueryStatType::single = NULL;
-SpinLock CqQueryStatType::m_singletonLock;
-SpinLock CqQueryStatType::m_statTypeLock;
-
-void CqQueryStatType::clean() {
-  SpinLockGuard guard(m_singletonLock);
-  if (single != NULL) {
-    delete single;
-    single = NULL;
-  }
-}
+spinlock_mutex CqQueryStatType::m_statTypeLock;
 
 StatisticsType* CqQueryStatType::getStatType() {
   const bool largerIsBetter = true;
-  SpinLockGuard guard(m_statTypeLock);
+  lock_guard<spinlock_mutex> guard(m_statTypeLock);
   StatisticsFactory* factory = StatisticsFactory::getExistingInstance();
   GF_D_ASSERT(!!factory);
 
   StatisticsType* statsType = factory->findType("CqQueryStatistics");
 
-  if (statsType == NULL) {
+  if (statsType == nullptr) {
     m_stats[0] = factory->createIntCounter(
         "inserts", "The total number of inserts this cq qurey", "entries",
         largerIsBetter);
@@ -81,19 +77,14 @@ StatisticsType* CqQueryStatType::getStatType() {
   return statsType;
 }
 
-CqQueryStatType* CqQueryStatType::getInstance() {
-  SpinLockGuard guard(m_singletonLock);
-  if (single == NULL) {
-    single = new CqQueryStatType();
-  }
-  return single;
+CqQueryStatType& CqQueryStatType::getInstance() {
+  // C++11 initializes statics threads safe
+  static CqQueryStatType instance;
+  return instance;
 }
 
 CqQueryStatType::CqQueryStatType()
-    : /* adongre
-       * CID 28931: Uninitialized scalar field (UNINIT_CTOR)
-       */
-      m_numInsertsId(0),
+    : m_numInsertsId(0),
       m_numUpdatesId(0),
       m_numDeletesId(0),
       m_numEventsId(0) {
@@ -108,21 +99,21 @@ CqQueryStatType::CqQueryStatType()
 
////////////////////////////////////////////////////////////////////////////////
 
 CqQueryVsdStats::CqQueryVsdStats(const char* cqqueryName) {
-  CqQueryStatType* regStatType = CqQueryStatType::getInstance();
+  auto& regStatType = CqQueryStatType::getInstance();
 
-  StatisticsType* statsType = regStatType->getStatType();
+  StatisticsType* statsType = regStatType.getStatType();
 
-  GF_D_ASSERT(statsType != NULL);
+  GF_D_ASSERT(statsType != nullptr);
 
   StatisticsFactory* factory = StatisticsFactory::getExistingInstance();
 
   m_cqQueryVsdStats = factory->createAtomicStatistics(
       statsType, const_cast<char*>(cqqueryName));
 
-  m_numInsertsId = regStatType->getNumInsertsId();
-  m_numUpdatesId = regStatType->getNumUpdatesId();
-  m_numDeletesId = regStatType->getNumDeletesId();
-  m_numEventsId = regStatType->getNumEventsId();
+  m_numInsertsId = regStatType.getNumInsertsId();
+  m_numUpdatesId = regStatType.getNumUpdatesId();
+  m_numDeletesId = regStatType.getNumDeletesId();
+  m_numEventsId = regStatType.getNumEventsId();
 
   m_cqQueryVsdStats->setInt(m_numInsertsId, 0);
   m_cqQueryVsdStats->setInt(m_numUpdatesId, 0);
@@ -131,10 +122,10 @@ CqQueryVsdStats::CqQueryVsdStats(const char* cqqueryName) 
{
 }
 
 CqQueryVsdStats::~CqQueryVsdStats() {
-  if (m_cqQueryVsdStats != NULL) {
-    // Don't Delete, Already closed, Just set NULL
+  if (m_cqQueryVsdStats != nullptr) {
+    // Don't Delete, Already closed, Just set nullptr
     // delete m_CqQueryVsdStats;
-    m_cqQueryVsdStats = NULL;
+    m_cqQueryVsdStats = nullptr;
   }
 }
 }  // namespace client

http://git-wip-us.apache.org/repos/asf/geode-native/blob/cb8a6f32/src/cppcache/src/CqQueryVsdStats.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/CqQueryVsdStats.hpp 
b/src/cppcache/src/CqQueryVsdStats.hpp
index 5b162da..3cc5672 100644
--- a/src/cppcache/src/CqQueryVsdStats.hpp
+++ b/src/cppcache/src/CqQueryVsdStats.hpp
@@ -23,15 +23,18 @@
 #include <geode/geode_globals.hpp>
 #include <geode/statistics/Statistics.hpp>
 #include <geode/statistics/StatisticsFactory.hpp>
-#include "SpinLock.hpp"
-
 #include <geode/CqStatistics.hpp>
 
+#include "util/concurrent/spinlock_mutex.hpp"
+
 namespace apache {
 namespace geode {
 namespace client {
 
-using namespace apache::geode::statistics;
+using statistics::StatisticDescriptor;
+using statistics::StatisticsType;
+using statistics::Statistics;
+using util::concurrent::spinlock_mutex;
 
 class CPPCACHE_EXPORT CqQueryVsdStats : public CqStatistics {
  public:
@@ -65,7 +68,7 @@ class CPPCACHE_EXPORT CqQueryVsdStats : public CqStatistics {
   }
 
  private:
-  apache::geode::statistics::Statistics* m_cqQueryVsdStats;
+  Statistics* m_cqQueryVsdStats;
 
   int32_t m_numInsertsId;
   int32_t m_numUpdatesId;
@@ -75,20 +78,19 @@ class CPPCACHE_EXPORT CqQueryVsdStats : public CqStatistics 
{
 
 class CqQueryStatType {
  private:
-  static int8_t instanceFlag;
-  static CqQueryStatType* single;
-  static SpinLock m_singletonLock;
-  static SpinLock m_statTypeLock;
+  static spinlock_mutex m_statTypeLock;
 
  public:
-  static CqQueryStatType* getInstance();
+  static CqQueryStatType& getInstance();
 
   StatisticsType* getStatType();
 
-  static void clean();
-
  private:
   CqQueryStatType();
+  ~CqQueryStatType() = default;
+  CqQueryStatType(const CqQueryStatType&) = delete;
+  CqQueryStatType& operator=(const CqQueryStatType&) = delete;
+
   StatisticDescriptor* m_stats[4];
 
   int32_t m_numInsertsId;

http://git-wip-us.apache.org/repos/asf/geode-native/blob/cb8a6f32/src/cppcache/src/CqServiceVsdStats.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/CqServiceVsdStats.cpp 
b/src/cppcache/src/CqServiceVsdStats.cpp
index af154d6..b78c056 100644
--- a/src/cppcache/src/CqServiceVsdStats.cpp
+++ b/src/cppcache/src/CqServiceVsdStats.cpp
@@ -23,8 +23,12 @@
 #include <ace/Thread_Mutex.h>
 #include <ace/Singleton.h>
 
-const char* cqServiceStatsName = (const char*)"CqServiceStatistics";
-const char* cqServiceStatsDesc = (const char*)"Statistics for this cq Service";
+#include <mutex>
+
+#include "util/concurrent/spinlock_mutex.hpp"
+
+const char* cqServiceStatsName = "CqServiceStatistics";
+const char* cqServiceStatsDesc = "Statistics for this cq Service";
 
 
////////////////////////////////////////////////////////////////////////////////
 
@@ -32,31 +36,23 @@ namespace apache {
 namespace geode {
 namespace client {
 
-using namespace apache::geode::statistics;
+using statistics::StatisticsFactory;
+using util::concurrent::spinlock_mutex;
+using std::lock_guard;
 
 
////////////////////////////////////////////////////////////////////////////////
 
-CqServiceStatType* CqServiceStatType::single = NULL;
-SpinLock CqServiceStatType::m_singletonLock;
-SpinLock CqServiceStatType::m_statTypeLock;
-
-void CqServiceStatType::clean() {
-  SpinLockGuard guard(m_singletonLock);
-  if (single != NULL) {
-    delete single;
-    single = NULL;
-  }
-}
+spinlock_mutex CqServiceStatType::m_statTypeLock;
 
 StatisticsType* CqServiceStatType::getStatType() {
   const bool largerIsBetter = true;
-  SpinLockGuard guard(m_statTypeLock);
+  lock_guard<spinlock_mutex> guard(m_statTypeLock);
   StatisticsFactory* factory = StatisticsFactory::getExistingInstance();
   GF_D_ASSERT(!!factory);
 
   StatisticsType* statsType = factory->findType("CqServiceStatistics");
 
-  if (statsType == NULL) {
+  if (statsType == nullptr) {
     m_stats[0] = factory->createIntCounter(
         "CqsActive", "The total number of CqsActive this cq qurey", "entries",
         largerIsBetter);
@@ -87,19 +83,13 @@ StatisticsType* CqServiceStatType::getStatType() {
   return statsType;
 }
 
-CqServiceStatType* CqServiceStatType::getInstance() {
-  SpinLockGuard guard(m_singletonLock);
-  if (single == NULL) {
-    single = new CqServiceStatType();
-  }
-  return single;
+CqServiceStatType& CqServiceStatType::getInstance() {
+  static CqServiceStatType instance;
+  return instance;
 }
 
 CqServiceStatType::CqServiceStatType()
-    : /* adongre
-       * CID 28932: Uninitialized scalar field (UNINIT_CTOR)
-       */
-      m_numCqsActiveId(0),
+    : m_numCqsActiveId(0),
       m_numCqsCreatedId(0),
       m_numCqsOnClientId(0),
       m_numCqsClosedId(0),
@@ -115,22 +105,22 @@ CqServiceStatType::CqServiceStatType()
 
////////////////////////////////////////////////////////////////////////////////
 
 CqServiceVsdStats::CqServiceVsdStats(const char* cqServiceName) {
-  CqServiceStatType* regStatType = CqServiceStatType::getInstance();
+  auto& regStatType = CqServiceStatType::getInstance();
 
-  StatisticsType* statsType = regStatType->getStatType();
+  StatisticsType* statsType = regStatType.getStatType();
 
-  GF_D_ASSERT(statsType != NULL);
+  GF_D_ASSERT(statsType != nullptr);
 
   StatisticsFactory* factory = StatisticsFactory::getExistingInstance();
 
   m_cqServiceVsdStats = factory->createAtomicStatistics(
       statsType, const_cast<char*>(cqServiceName));
 
-  m_numCqsActiveId = regStatType->getNumCqsActiveId();
-  m_numCqsCreatedId = regStatType->getNumCqsCreatedId();
-  m_numCqsOnClientId = regStatType->getNumCqsOnClientId();
-  m_numCqsClosedId = regStatType->getNumCqsClosedId();
-  m_numCqsStoppedId = regStatType->getNumCqsStoppedId();
+  m_numCqsActiveId = regStatType.getNumCqsActiveId();
+  m_numCqsCreatedId = regStatType.getNumCqsCreatedId();
+  m_numCqsOnClientId = regStatType.getNumCqsOnClientId();
+  m_numCqsClosedId = regStatType.getNumCqsClosedId();
+  m_numCqsStoppedId = regStatType.getNumCqsStoppedId();
 
   m_cqServiceVsdStats->setInt(m_numCqsActiveId, 0);
   m_cqServiceVsdStats->setInt(m_numCqsCreatedId, 0);
@@ -139,10 +129,10 @@ CqServiceVsdStats::CqServiceVsdStats(const char* 
cqServiceName) {
 }
 
 CqServiceVsdStats::~CqServiceVsdStats() {
-  if (m_cqServiceVsdStats != NULL) {
-    // Don't Delete, Already closed, Just set NULL
+  if (m_cqServiceVsdStats != nullptr) {
+    // Don't Delete, Already closed, Just set nullptr
     // delete m_CqServiceVsdStats;
-    m_cqServiceVsdStats = NULL;
+    m_cqServiceVsdStats = nullptr;
   }
 }
 }  // namespace client

http://git-wip-us.apache.org/repos/asf/geode-native/blob/cb8a6f32/src/cppcache/src/CqServiceVsdStats.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/CqServiceVsdStats.hpp 
b/src/cppcache/src/CqServiceVsdStats.hpp
index 44a8c3d..710dfdb 100644
--- a/src/cppcache/src/CqServiceVsdStats.hpp
+++ b/src/cppcache/src/CqServiceVsdStats.hpp
@@ -23,14 +23,18 @@
 #include <geode/geode_globals.hpp>
 #include <geode/statistics/Statistics.hpp>
 #include <geode/statistics/StatisticsFactory.hpp>
-#include "SpinLock.hpp"
 #include <geode/CqServiceStatistics.hpp>
 
+#include "util/concurrent/spinlock_mutex.hpp"
+
 namespace apache {
 namespace geode {
 namespace client {
 
-using namespace apache::geode::statistics;
+using statistics::StatisticDescriptor;
+using statistics::StatisticsType;
+using statistics::Statistics;
+using util::concurrent::spinlock_mutex;
 
 class CPPCACHE_EXPORT CqServiceVsdStats : public CqServiceStatistics {
  public:
@@ -108,20 +112,19 @@ class CPPCACHE_EXPORT CqServiceVsdStats : public 
CqServiceStatistics {
 
 class CqServiceStatType {
  private:
-  static int8_t instanceFlag;
-  static CqServiceStatType* single;
-  static SpinLock m_singletonLock;
-  static SpinLock m_statTypeLock;
+  static spinlock_mutex m_statTypeLock;
 
  public:
-  static CqServiceStatType* getInstance();
+  static CqServiceStatType& getInstance();
 
   StatisticsType* getStatType();
 
-  static void clean();
-
  private:
   CqServiceStatType();
+  ~CqServiceStatType() = default;
+  CqServiceStatType(const CqServiceStatType&) = delete;
+  CqServiceStatType& operator=(const CqServiceStatType&) = delete;
+
   StatisticDescriptor* m_stats[5];
 
   int32_t m_numCqsActiveId;

Reply via email to