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

Branch: refs/heads/feature/GEODE-2602
Commit: 9ba31955d745345b58f6560d9de4796ccf80fe60
Parents: a73e3ed
Author: Jacob Barrett <jbarr...@pivotal.io>
Authored: Wed Feb 22 17:58:05 2017 -0800
Committer: Jacob Barrett <jbarr...@pivotal.io>
Committed: Mon Mar 6 17:32:11 2017 -0800

----------------------------------------------------------------------
 src/tests/cpp/fwklib/GsRandom.cpp        | 21 ++++++++++++++++-----
 src/tests/cpp/fwklib/GsRandom.hpp        |  6 ++++--
 src/tests/cpp/fwklib/MersenneTwister.cpp |  7 ++++---
 src/tests/cpp/fwklib/MersenneTwister.hpp |  4 ++--
 4 files changed, 26 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode-native/blob/9ba31955/src/tests/cpp/fwklib/GsRandom.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/GsRandom.cpp 
b/src/tests/cpp/fwklib/GsRandom.cpp
index ae1c240..df13c44 100644
--- a/src/tests/cpp/fwklib/GsRandom.cpp
+++ b/src/tests/cpp/fwklib/GsRandom.cpp
@@ -17,13 +17,20 @@
 
 #include "GsRandom.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;
 
 GsRandom *GsRandom::singleton = 0;
 MTRand GsRandom::gen;
 int32_t GsRandom::seedUsed = -101;
-SpinLock GsRandom::lck;
+spinlock_mutex GsRandom::lck;
 
 /**
   * Creates a new random number generator using a single
@@ -36,14 +43,14 @@ GsRandom *GsRandom::getInstance(int32_t seed) {
   if (singleton == 0) {
     setInstance(seed);
   } else {
-    SpinLockGuard guard(lck);
+    std::lock_guard<spinlock_mutex> guard(lck);
     setSeed(seed);
   }
   return singleton;
 }
 
 void GsRandom::setInstance(int32_t seed) {
-  SpinLockGuard guard(lck);
+  std::lock_guard<spinlock_mutex> guard(lck);
   if (singleton == 0) {
     singleton = new GsRandom();
     if (seed != -1) {
@@ -116,3 +123,7 @@ char *GsRandom::randomAlphanumericString(int32_t max, 
int32_t min,
   buf[len] = 0;
   return buf;
 }
+}  // namespace testframework
+}  // namespace client
+}  // namespace geode
+}  // namespace apache

http://git-wip-us.apache.org/repos/asf/geode-native/blob/9ba31955/src/tests/cpp/fwklib/GsRandom.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/GsRandom.hpp 
b/src/tests/cpp/fwklib/GsRandom.hpp
index 6c26d75..701568d 100644
--- a/src/tests/cpp/fwklib/GsRandom.hpp
+++ b/src/tests/cpp/fwklib/GsRandom.hpp
@@ -24,7 +24,7 @@
 
 #include <string>
 
-#include "SpinLock.hpp"
+#include <util/concurrent/spinlock_mutex.hpp>
 #include "MersenneTwister.hpp"
 
 namespace apache {
@@ -32,12 +32,14 @@ namespace geode {
 namespace client {
 namespace testframework {
 
+using util::concurrent::spinlock_mutex;
+
 class GsRandom {
  private:
   static MTRand gen;
   static GsRandom* singleton;
   static int32_t seedUsed;
-  static SpinLock lck;
+  static spinlock_mutex lck;
   static void setInstance(int32_t seed);
 
   GsRandom() {}

http://git-wip-us.apache.org/repos/asf/geode-native/blob/9ba31955/src/tests/cpp/fwklib/MersenneTwister.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/MersenneTwister.cpp 
b/src/tests/cpp/fwklib/MersenneTwister.cpp
index 6b21318..7aedd02 100644
--- a/src/tests/cpp/fwklib/MersenneTwister.cpp
+++ b/src/tests/cpp/fwklib/MersenneTwister.cpp
@@ -74,9 +74,10 @@
 // Not thread safe (unless auto-initialization is avoided and each thread has
 // its own MTRand object)
 
+#include <mutex>
 #include "MersenneTwister.hpp"
 
-apache::geode::client::SpinLock MTRand::lck;
+apache::geode::util::concurrent::spinlock_mutex MTRand::lck;
 
 MTRand::MTRand(const uint32_t &oneSeed) { seed(oneSeed); }
 
@@ -116,7 +117,7 @@ double MTRand::randNorm(const double &mean, const double 
&variance) {
 uint32_t MTRand::randInt() {
   // Pull a 32-bit integer from the generator state
   // Every other access function simply transforms the numbers extracted here
-  apache::geode::client::SpinLockGuard guard(lck);
+  std::lock_guard<apache::geode::util::concurrent::spinlock_mutex> guard(lck);
 
   if (left <= 0) reload();
   --left;
@@ -212,7 +213,7 @@ void MTRand::seed() {
   }
 
   // Was not successful, so use time() and clock() instead
-  seed(hash(time(NULL), clock()));
+  seed(hash(time(nullptr), clock()));
 }
 
 void MTRand::initialize(const uint32_t seed) {

http://git-wip-us.apache.org/repos/asf/geode-native/blob/9ba31955/src/tests/cpp/fwklib/MersenneTwister.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/MersenneTwister.hpp 
b/src/tests/cpp/fwklib/MersenneTwister.hpp
index 9fa1b95..b22683e 100644
--- a/src/tests/cpp/fwklib/MersenneTwister.hpp
+++ b/src/tests/cpp/fwklib/MersenneTwister.hpp
@@ -85,7 +85,7 @@
 #include <ctime>
 #include <math.h>
 
-#include "SpinLock.hpp"
+#include <util/concurrent/spinlock_mutex.hpp>
 #include <geode/geode_base.hpp>
 
 class MTRand {
@@ -102,7 +102,7 @@ class MTRand {
   int32_t left;       // number of values left before reload needed
 
  private:
-  static apache::geode::client::SpinLock lck;
+  static apache::geode::util::concurrent::spinlock_mutex lck;
 
   // Methods
  public:

Reply via email to