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/06/22 21:06:55 UTC
[1/5] geode-native git commit: GEODE-2494: Replace SpinLock with
spinlock_mutex.
Repository: geode-native
Updated Branches:
refs/heads/develop b1a9af530 -> e32a15008
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/tests/cpp/security/Security.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/security/Security.cpp b/src/tests/cpp/security/Security.cpp
index 57013b0..f0a3166 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: "
@@ -931,7 +933,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) {
@@ -1076,3 +1078,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/3305de70/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
[5/5] geode-native git commit: GEODE-2602: Fixes C++11 issues.
Posted by jb...@apache.org.
GEODE-2602: Fixes C++11 issues.
- Fixes C++11 issues with C++/CLI.
- Fixes C++11 issues with Solaris Studio 12.5.
- Updated documents for current C++11 requirements.
Project: http://git-wip-us.apache.org/repos/asf/geode-native/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode-native/commit/e32a1500
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/e32a1500
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/e32a1500
Branch: refs/heads/develop
Commit: e32a150086b2cc37898c1ec8d24155ea3822cd50
Parents: bfec2fa
Author: Jacob Barrett <jb...@pivotal.io>
Authored: Wed Mar 15 17:38:02 2017 +0000
Committer: Ernie Burghardt <eb...@pivotal.io>
Committed: Thu Jun 22 13:54:24 2017 -0700
----------------------------------------------------------------------
BUILDING.md | 15 +++---
CONTRIBUTING.md | 54 +--------------------
src/CMakeLists.txt | 2 +-
src/cppcache/include/geode/CacheStatistics.hpp | 2 +
src/cppcache/src/RegionStats.cpp | 1 -
src/tests/cpp/fwklib/UDPIpc.cpp | 4 +-
src/tests/cpp/fwklib/UDPIpc.hpp | 16 +++---
7 files changed, 21 insertions(+), 73 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode-native/blob/e32a1500/BUILDING.md
----------------------------------------------------------------------
diff --git a/BUILDING.md b/BUILDING.md
index 29ff26f..444cfbf 100644
--- a/BUILDING.md
+++ b/BUILDING.md
@@ -54,12 +54,13 @@ Due to limitations in CMake, the documentation must be built as a separate step
## All Platforms
### Required Tools
-* [CMake 3.4](https://cmake.org/) or newer
+* [CMake 3.8](https://cmake.org/) or newer
* C++11 compiler *(see platform specific requirements)*
* [Doxygen 8.11](http://www.stack.nl/~dimitri/doxygen/download.html) *(for building source documentation)*
## Mac OS X
-* Mac OS X 10.12 (Sierra)
+* Mac OS X 10.12 (Sierra) or newer
+* XCode 8.2 or newer
### Required Tools
* [XCode](https://developer.apple.com/xcode/download/)
@@ -68,18 +69,18 @@ Due to limitations in CMake, the documentation must be built as a separate step
`$ xcode-select --install`
### Optional Tools
-* [CMake GUI](https://cmake.org/files/v3.4/cmake-3.4.3-Darwin-x86_64.dmg)
+* [CMake GUI](https://cmake.org/)
* [Doxygen GUI](http://ftp.stack.nl/pub/users/dimitri/Doxygen-1.8.11.dmg)
* [Eclipse CDT 8.8](https://eclipse.org/cdt/) or newer
## Windows
* Windows 8.1 64-bit
* Windows 10 64-bit
-* Windows Server 2012 64-bit
* Windows Server 2012 R2 64-bit
+* Windows Server 2016 64-bit
### Required Tools
-* [Visual Studio 2013](https://www.visualstudio.com) or newer
+* [Visual Studio 2015](https://www.visualstudio.com) or newer
* .NET 4.5.2 or later
* patch.exe (available as part of GnuWin or Cygwin)
@@ -96,12 +97,10 @@ Due to limitations in CMake, the documentation must be built as a separate step
* [Eclipse CDT 8.8](https://eclipse.org/cdt/) or newer
## Solaris
-* Solaris 10 SPARC
-* Solaris 10 x86
* Solaris 11 SPARC
* Solaris 11 x86
### Required Tools
-* [Solaris Studio 12.4](http://www.oracle.com/technetwork/server-storage/solarisstudio/downloads/index-jsp-141149.html) or newer
+* [Solaris Studio 12.5](http://www.oracle.com/technetwork/server-storage/solarisstudio/downloads/index-jsp-141149.html) or newer
http://git-wip-us.apache.org/repos/asf/geode-native/blob/e32a1500/CONTRIBUTING.md
----------------------------------------------------------------------
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 278f67f..e3d9ab0 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -44,57 +44,5 @@ For C++ it is required to follow the [Google C++ Style Guide](https://google.git
$ cmake --build . --target format
# System Requirements
+See [BUILDING.md](BUILDING.md)
-## All Platforms
-
-### Required Tools
-* [CMake 3.4](https://cmake.org/) or newer
-* C++11 compiler *(see platform specific requirements)*
-* [Doxygen 8.11](http://www.stack.nl/~dimitri/doxygen/download.html) *(for building source documentation)*
-
-## Mac OS X
-* Mac OS X 10.12 (Sierra)
-
-### Required Tools
-* [XCode](https://developer.apple.com/xcode/download/)
-* Xcode command line developer tools
-
- `$ xcode-select --install`
-
-### Optional Tools
-* [CMake GUI](https://cmake.org/files/v3.4/cmake-3.4.3-Darwin-x86_64.dmg)
-* [Doxygen GUI](http://ftp.stack.nl/pub/users/dimitri/Doxygen-1.8.11.dmg)
-* [Eclipse CDT 8.8](https://eclipse.org/cdt/) or newer
-
-## Windows
-* Windows 8.1 64-bit
-* Windows 10 64-bit
-* Windows Server 2012 64-bit
-* Windows Server 2012 R2 64-bit
-
-### Required Tools
-* [Visual Studio 2013](https://www.visualstudio.com) or newer
-* [Cygwin](https://www.cygwin.com/)
-
-## Linux
-* RHEL/CentOS 6
-* RHEL/CentOS 7
-* SLES 11
-* SLES 12
-
-### Required Tools
-* [GCC 4.6](https://gcc.gnu.org) or newer
-
-### Optional Tools
-* [Eclipse CDT 8.8](https://eclipse.org/cdt/) or newer
-
-## Solaris
-* Solaris 10 SPARC
-* Solaris 10 x86
-* Solaris 11 SPARC
-* Solaris 11 x86
-
-### Required Tools
-* [Solaris Studio 12.4](http://www.oracle.com/technetwork/server-storage/solarisstudio/downloads/index-jsp-141149.html) or newer
-
-
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/geode-native/blob/e32a1500/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d3e2ee1..2c43578 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -166,7 +166,7 @@ add_library(c++11 INTERFACE)
if(CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
# Force linker to error on undefined symbols in shared libraries
- set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z defs")
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -z defs -xatomic=none")
# TODO cmake find a better way to set runtime libraries
# C++11 requires these libraries, treat -std=c++11 as library
#TODO look into CMAKE_CXX_STANDARD_LIBRARIES
http://git-wip-us.apache.org/repos/asf/geode-native/blob/e32a1500/src/cppcache/include/geode/CacheStatistics.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/include/geode/CacheStatistics.hpp b/src/cppcache/include/geode/CacheStatistics.hpp
index afbb82a..fc65f89 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 <atomic>
+
/**
* @file
*/
http://git-wip-us.apache.org/repos/asf/geode-native/blob/e32a1500/src/cppcache/src/RegionStats.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/RegionStats.cpp b/src/cppcache/src/RegionStats.cpp
index cff6e0e..e8f8004 100644
--- a/src/cppcache/src/RegionStats.cpp
+++ b/src/cppcache/src/RegionStats.cpp
@@ -215,7 +215,6 @@ RegionStatType::RegionStatType()
m_entriesId(0),
m_overflowsId(0),
m_retrievesId(0),
- m_nonSingleHopId(0),
m_metaDataRefreshId(0),
m_LoaderCallsCompletedId(0),
m_LoaderCallTimeId(0),
http://git-wip-us.apache.org/repos/asf/geode-native/blob/e32a1500/src/tests/cpp/fwklib/UDPIpc.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/UDPIpc.cpp b/src/tests/cpp/fwklib/UDPIpc.cpp
index a5a7928..d3f9fc5 100644
--- a/src/tests/cpp/fwklib/UDPIpc.cpp
+++ b/src/tests/cpp/fwklib/UDPIpc.cpp
@@ -254,7 +254,7 @@ int32_t Receiver::doTask() {
void Receiver::initialize() {
int32_t tries = 100;
- int32_t port = m_basePort;
+ uint16_t port = m_basePort;
int32_t lockResult = m_mutex.tryacquire();
int32_t result = -1;
if (lockResult != -1) { // The listener thread
@@ -358,7 +358,7 @@ void Responder::initialize() {
int32_t result = -1;
int32_t tries = 100;
while ((result < 0) && (--tries > 0)) {
- int32_t port = ++m_offset + 111 + m_basePort;
+ uint16_t port = ++m_offset + 111 + m_basePort;
result = m_io->open(ACE_INET_Addr(port, "localhost"));
if (result < 0) {
FWKWARN("Server failed to open io, " << errno << ", on port " << port);
http://git-wip-us.apache.org/repos/asf/geode-native/blob/e32a1500/src/tests/cpp/fwklib/UDPIpc.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/UDPIpc.hpp b/src/tests/cpp/fwklib/UDPIpc.hpp
index 68b9ad9..dc143d9 100644
--- a/src/tests/cpp/fwklib/UDPIpc.hpp
+++ b/src/tests/cpp/fwklib/UDPIpc.hpp
@@ -197,15 +197,15 @@ class UDPMessageQueues : public SharedTaskObject {
class Receiver : public ServiceTask {
private:
ACE_TSS<ACE_SOCK_Dgram> m_io;
- int32_t m_basePort;
+ uint16_t m_basePort;
ACE_thread_t m_listener;
- std::atomic<int32_t> m_offset;
+ std::atomic<uint16_t> m_offset;
std::list<std::string> m_addrs;
UDPMessageQueues* m_queues;
ACE_Thread_Mutex m_mutex;
public:
- Receiver(UDPMessageQueues* shared, int32_t port)
+ Receiver(UDPMessageQueues* shared, uint16_t port)
: ServiceTask(shared), m_basePort(port), m_listener(0), m_mutex() {
m_queues = dynamic_cast<UDPMessageQueues*>(m_shared);
}
@@ -224,12 +224,12 @@ class Receiver : public ServiceTask {
class STReceiver : public ServiceTask {
private:
ACE_SOCK_Dgram m_io;
- int32_t m_basePort;
+ uint16_t m_basePort;
UDPMessageQueues* m_queues;
std::string m_addr;
public:
- STReceiver(UDPMessageQueues* shared, int32_t port)
+ STReceiver(UDPMessageQueues* shared, uint16_t port)
: ServiceTask(shared), m_basePort(port) {
m_queues = dynamic_cast<UDPMessageQueues*>(m_shared);
}
@@ -272,12 +272,12 @@ class Processor : public ServiceTask {
class Responder : public ServiceTask {
private:
ACE_TSS<ACE_SOCK_Dgram> m_io;
- int32_t m_basePort;
- std::atomic<int32_t> m_offset;
+ uint16_t m_basePort;
+ std::atomic<uint16_t> m_offset;
UDPMessageQueues* m_queues;
public:
- Responder(UDPMessageQueues* shared, int32_t port)
+ Responder(UDPMessageQueues* shared, uint16_t port)
: ServiceTask(shared), m_basePort(port) {
m_queues = dynamic_cast<UDPMessageQueues*>(m_shared);
}
[4/5] geode-native git commit: GEODE-2552: Replaced sleeps and timers
with std::chrono
Posted by jb...@apache.org.
GEODE-2552: Replaced sleeps and timers with std::chrono
- Replace NanoSleep with std::this_thread::sleepFor
- Replaced custom time/duration with std::crono.
- Replaced NanoTimer with std::chrono.
- Replaced millisleep with std::this_thread::sleep_for.
Project: http://git-wip-us.apache.org/repos/asf/geode-native/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode-native/commit/bfec2fa7
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/bfec2fa7
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/bfec2fa7
Branch: refs/heads/develop
Commit: bfec2fa7e464bf8b7d45f259b6952ba6ba53f5ef
Parents: 0cc06f0
Author: Jacob Barrett <jb...@pivotal.io>
Authored: Sat Feb 25 13:18:12 2017 -0800
Committer: Ernie Burghardt <eb...@pivotal.io>
Committed: Thu Jun 22 13:54:12 2017 -0700
----------------------------------------------------------------------
src/cppcache/include/geode/geode_globals.hpp | 14 ---
.../integration-test/ThinClientDurable.hpp | 23 ++--
.../ThinClientDurableFailover.hpp | 17 +--
.../ThinClientDurableInterest.hpp | 15 +--
.../testThinClientConflation.cpp | 11 +-
.../testThinClientCqDurable.cpp | 10 +-
.../testThinClientHAEventIDMap.cpp | 22 ++--
.../testThinClientHAPeriodicAck.cpp | 18 ++--
src/cppcache/src/EvictionController.cpp | 19 ++--
src/cppcache/src/LocalRegion.cpp | 21 ++--
src/cppcache/src/Log.cpp | 6 +-
src/cppcache/src/NanoTimer.cpp | 53 ----------
src/cppcache/src/NanoTimer.hpp | 39 -------
src/cppcache/src/TcrConnectionManager.cpp | 14 ++-
src/cppcache/src/TcrEndpoint.cpp | 18 +++-
src/cppcache/src/Utils.cpp | 5 +-
src/cppcache/src/Utils.hpp | 6 +-
src/cppcache/src/statistics/HostStatSampler.cpp | 105 ++++++++++---------
src/cppcache/src/statistics/HostStatSampler.hpp | 8 +-
.../src/statistics/PoolStatsSampler.cpp | 44 ++++----
.../src/statistics/StatArchiveWriter.cpp | 51 +++++----
.../src/statistics/StatArchiveWriter.hpp | 12 ++-
src/cppcache/test/NanoTimerTest.cpp | 30 ------
src/quickstart/cpp/DurableClient.cpp | 2 +-
24 files changed, 249 insertions(+), 314 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/include/geode/geode_globals.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/include/geode/geode_globals.hpp b/src/cppcache/include/geode/geode_globals.hpp
index a22cfdd..ae3b56d 100644
--- a/src/cppcache/include/geode/geode_globals.hpp
+++ b/src/cppcache/include/geode/geode_globals.hpp
@@ -96,12 +96,8 @@
#define __has_cpp_attribute(x) 0
#endif
-<<<<<<< HEAD
#if __cplusplus >= 201402L
#if __has_cpp_attribute(deprecated)
-=======
-#if __cplusplus >= 201402L && __has_cpp_attribute(deprecated)
->>>>>>> GEODE-2531: Replace HostAsm::atomic with std::atomic.
// C++14 standard deprecated attribute
#define __DEPRECATED__(msg) [[deprecated(msg)]]
#else
@@ -126,16 +122,6 @@
#include <cstdint>
-namespace apache {
-namespace geode {
-namespace client {
-
-extern void CPPCACHE_EXPORT millisleep(uint32_t millis);
-
-} // namespace client
-} // namespace geode
-} // namespace apache
-
#include "Log.hpp"
#include "Assert.hpp"
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/integration-test/ThinClientDurable.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/ThinClientDurable.hpp b/src/cppcache/integration-test/ThinClientDurable.hpp
index a10ef20..5faad78 100644
--- a/src/cppcache/integration-test/ThinClientDurable.hpp
+++ b/src/cppcache/integration-test/ThinClientDurable.hpp
@@ -29,6 +29,9 @@
#include "fw_dunit.hpp"
#include "ThinClientHelper.hpp"
+#include <thread>
+#include <chrono>
+
/* Testing Parameters Param's Value
Termination : Keepalive = true/ false, Client crash / Netdown
Restart Time: Before Timeout / After Timeout
@@ -61,7 +64,7 @@ class OperMonitor : public CacheListener {
CacheableInt32Ptr value = nullptr;
try {
value = std::dynamic_pointer_cast<CacheableInt32>(event.getNewValue());
- } catch (Exception) {
+ } catch (Exception&) {
// do nothing.
}
@@ -198,22 +201,22 @@ void feederUpdate(int value, int ignoreR2 = false) {
continue;
}
createIntEntry(regionNames[regIdx], mixKeys[0], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[regIdx], mixKeys[1], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[regIdx], mixKeys[2], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[regIdx], mixKeys[3], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
destroyEntry(regionNames[regIdx], mixKeys[0]);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
destroyEntry(regionNames[regIdx], mixKeys[1]);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
destroyEntry(regionNames[regIdx], mixKeys[2]);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
destroyEntry(regionNames[regIdx], mixKeys[3]);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
@@ -315,7 +318,7 @@ DUNIT_TASK_DEFINITION(FEEDER, FeederUpdate1)
feederUpdate(1);
// Wait 5 seconds for events to be removed from ha queues.
- apache::geode::client::millisleep(5000);
+ std::this_thread::sleep_for(std::chrono::seconds(5));
LOG("FeederUpdate1 complete.");
}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/integration-test/ThinClientDurableFailover.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/ThinClientDurableFailover.hpp b/src/cppcache/integration-test/ThinClientDurableFailover.hpp
index 628c342..07fc425 100644
--- a/src/cppcache/integration-test/ThinClientDurableFailover.hpp
+++ b/src/cppcache/integration-test/ThinClientDurableFailover.hpp
@@ -29,6 +29,9 @@
#include "fw_dunit.hpp"
#include "ThinClientHelper.hpp"
+#include <thread>
+#include <chrono>
+
/* Testing Parameters Param's Value
Termination : Keepalive = true/ false, Client crash
Restart Time: Before Timeout / After Timeout
@@ -59,7 +62,7 @@ class OperMonitor : public CacheListener {
CacheableInt32Ptr value = nullptr;
try {
value = std::dynamic_pointer_cast<CacheableInt32>(event.getNewValue());
- } catch (Exception) {
+ } catch (Exception&) {
// do nothing.
}
@@ -182,9 +185,9 @@ void initClientCache(int redundancy, int durableTimeout, OperMonitorPtr& mon,
void feederUpdate(int value) {
createIntEntry(regionNames[0], mixKeys[0], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[0], mixKeys[1], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
/* Close Client 1 with option keep alive = true*/
@@ -219,7 +222,7 @@ DUNIT_TASK_DEFINITION(SERVER1, StartServer2)
}
// sleep for 3 seconds to allow redundancy monitor to detect new server.
- apache::geode::client::millisleep(3000);
+ std::this_thread::sleep_for(std::chrono::seconds(3));
LOG("SERVER started");
}
END_TASK_DEFINITION
@@ -247,7 +250,7 @@ DUNIT_TASK_DEFINITION(FEEDER, FeederUpdate1)
feederUpdate(1);
// Wait 5 seconds for events to be removed from ha queues.
- apache::geode::client::millisleep(5000);
+ std::this_thread::sleep_for(std::chrono::seconds(5));
LOG("FeederUpdate1 complete.");
}
@@ -258,7 +261,7 @@ DUNIT_TASK_DEFINITION(FEEDER, FeederUpdate2)
feederUpdate(2);
// Wait 5 seconds for events to be removed from ha queues.
- apache::geode::client::millisleep(5000);
+ std::this_thread::sleep_for(std::chrono::seconds(5));
LOG("FeederUpdate2 complete.");
}
@@ -307,7 +310,7 @@ DUNIT_TASK_DEFINITION(SERVER1, CloseServer1)
{
CacheHelper::closeServer(1);
// Wait 2 seconds to allow client failover.
- apache::geode::client::millisleep(2000);
+ std::this_thread::sleep_for(std::chrono::seconds(2));
LOG("SERVER closed");
}
END_TASK_DEFINITION
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/integration-test/ThinClientDurableInterest.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/ThinClientDurableInterest.hpp b/src/cppcache/integration-test/ThinClientDurableInterest.hpp
index eba3789..29507e0 100644
--- a/src/cppcache/integration-test/ThinClientDurableInterest.hpp
+++ b/src/cppcache/integration-test/ThinClientDurableInterest.hpp
@@ -29,6 +29,9 @@
#include "fw_dunit.hpp"
#include "ThinClientHelper.hpp"
+#include <thread>
+#include <chrono>
+
/* This is to test
1- If client doesn't do explicit registration on reconnect, durable events shud
be recieved.
@@ -181,21 +184,21 @@ void initClientRemoveIntrest(int ClientIdx, OperMonitorPtr mon) {
void feederUpdate(int value) {
createIntEntry(regionNames[0], mixKeys[0], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[0], mixKeys[1], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
void feederUpdate1(int value) {
createIntEntry(regionNames[0], mixKeys[0], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[0], mixKeys[1], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[1], mixKeys[2], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[1], mixKeys[3], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
DUNIT_TASK_DEFINITION(FEEDER, FeederInit)
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/integration-test/testThinClientConflation.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/testThinClientConflation.cpp b/src/cppcache/integration-test/testThinClientConflation.cpp
index aa93b8b..5be6103 100644
--- a/src/cppcache/integration-test/testThinClientConflation.cpp
+++ b/src/cppcache/integration-test/testThinClientConflation.cpp
@@ -18,6 +18,9 @@
#include "fw_dunit.hpp"
#include "ThinClientHelper.hpp"
+#include <thread>
+#include <chrono>
+
/* Testing Parameters Param's Value
Server Conflation: on / off
Client side conflation setting on/ off / server / not set
@@ -176,7 +179,7 @@ DUNIT_TASK_DEFINITION(CLIENT1, ValidateClient1Conflation)
{
// Client Already Initiated , Send Client Ready and wait
getHelper()->cachePtr->readyForEvents();
- apache::geode::client::millisleep(5000);
+ std::this_thread::sleep_for(std::chrono::seconds(5));
mon1C1->validate(true);
LOG("Client 1 region 1 verified for conflation = true");
@@ -191,7 +194,7 @@ DUNIT_TASK_DEFINITION(CLIENT2, ValidateClient2Conflation)
{
// Client Already Initiated , Send Client Ready and wait
getHelper()->cachePtr->readyForEvents();
- apache::geode::client::millisleep(5000);
+ std::this_thread::sleep_for(std::chrono::seconds(5));
mon1C2->validate(false);
LOG("Client 2 region 1 verified for conflation = false");
@@ -227,7 +230,7 @@ DUNIT_TASK_DEFINITION(CLIENT1, ValidateClient1Server)
{
// Client Already Initiated , Send Client Ready and wait
getHelper()->cachePtr->readyForEvents();
- apache::geode::client::millisleep(5000);
+ std::this_thread::sleep_for(std::chrono::seconds(5));
mon1C1->validate(true);
LOG("Client 1 region 1 verified for conflation = server");
@@ -242,7 +245,7 @@ DUNIT_TASK_DEFINITION(CLIENT2, ValidateClient2None)
{
// Client Already Initiated , Send Client Ready and wait
getHelper()->cachePtr->readyForEvents();
- apache::geode::client::millisleep(5000);
+ std::this_thread::sleep_for(std::chrono::seconds(5));
mon1C2->validate(true);
LOG("Client 2 region 1 verified for no conflation setting");
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/integration-test/testThinClientCqDurable.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/testThinClientCqDurable.cpp b/src/cppcache/integration-test/testThinClientCqDurable.cpp
index 85f8e64..1039d07 100644
--- a/src/cppcache/integration-test/testThinClientCqDurable.cpp
+++ b/src/cppcache/integration-test/testThinClientCqDurable.cpp
@@ -24,6 +24,8 @@
#include <ace/OS.h>
#include <ace/High_Res_Timer.h>
#include <string>
+#include <thread>
+#include <chrono>
#define ROOT_SCOPE DISTRIBUTED_ACK
@@ -219,7 +221,7 @@ void RunDurableCqClient() {
// execute Cq Query
qry->execute();
- apache::geode::client::millisleep(10000);
+ std::this_thread::sleep_for(std::chrono::seconds(10));
LOGINFO("Executed new CqQuery");
@@ -230,7 +232,7 @@ void RunDurableCqClient() {
LOGINFO("Sent ReadyForEvents message to server");
// wait for some time to recieve events
- apache::geode::client::millisleep(10000);
+ std::this_thread::sleep_for(std::chrono::seconds(10));
// Close the Geode Cache with keepalive = true. Server will queue events
// for
@@ -266,7 +268,7 @@ void RunFeederClient() {
regionPtr->put(keyPtr, valPtr);
}
- apache::geode::client::millisleep(10000);
+ std::this_thread::sleep_for(std::chrono::seconds(10));
LOGINFO("put on 0-10 keys done.");
// Close the Geode Cache
@@ -299,7 +301,7 @@ void RunFeederClient1() {
regionPtr->put(keyPtr, valPtr);
}
- apache::geode::client::millisleep(10000);
+ std::this_thread::sleep_for(std::chrono::seconds(10));
LOGINFO("put on 0-10 keys done.");
// Close the Geode Cache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/integration-test/testThinClientHAEventIDMap.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/testThinClientHAEventIDMap.cpp b/src/cppcache/integration-test/testThinClientHAEventIDMap.cpp
index ba7b6b9..6112541 100644
--- a/src/cppcache/integration-test/testThinClientHAEventIDMap.cpp
+++ b/src/cppcache/integration-test/testThinClientHAEventIDMap.cpp
@@ -20,6 +20,8 @@
#include <ace/OS.h>
#include <string>
+#include <thread>
+#include <chrono>
#define ROOT_NAME "testThinClientHAEventIDMap"
#define ROOT_SCOPE DISTRIBUTED_ACK
@@ -484,21 +486,21 @@ DUNIT_TASK_DEFINITION(CLIENT1, CreateEntries)
{
for (int value = 1; value <= 100; value++) {
createIntEntry(regionNames[0], keys[0], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[0], keys[1], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[0], keys[2], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[0], keys[3], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[1], keys[0], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[1], keys[1], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[1], keys[2], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[1], keys[3], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
END_TASK_DEFINITION
@@ -514,8 +516,8 @@ END_TASK_DEFINITION
DUNIT_TASK_DEFINITION(CLIENT2, VerifyClient2Entries)
{
- apache::geode::client::millisleep(
- 30000); // wait 30 sec for notifications to complete
+ // wait 30 sec for notifications to complete
+ std::this_thread::sleep_for(std::chrono::seconds(30));
verifyIntEntry(regionNames[0], keys[0], 100);
verifyIntEntry(regionNames[0], keys[1], 100);
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/integration-test/testThinClientHAPeriodicAck.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/testThinClientHAPeriodicAck.cpp b/src/cppcache/integration-test/testThinClientHAPeriodicAck.cpp
index d347c34..ddd47b3 100644
--- a/src/cppcache/integration-test/testThinClientHAPeriodicAck.cpp
+++ b/src/cppcache/integration-test/testThinClientHAPeriodicAck.cpp
@@ -20,6 +20,8 @@
#include <ace/OS.h>
#include <string>
+#include <thread>
+#include <chrono>
#define ROOT_NAME "testThinClientHAPeriodicAck"
#define ROOT_SCOPE DISTRIBUTED_ACK
@@ -488,21 +490,21 @@ DUNIT_TASK_DEFINITION(CLIENT1, CreateEntries)
{
for (int value = 1; value <= 100; value++) {
createIntEntry(regionNames[0], keys[0], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
createIntEntry(regionNames[0], keys[1], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
createIntEntry(regionNames[0], keys[2], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
createIntEntry(regionNames[0], keys[3], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
createIntEntry(regionNames[1], keys[0], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
createIntEntry(regionNames[1], keys[1], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
createIntEntry(regionNames[1], keys[2], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
createIntEntry(regionNames[1], keys[3], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
}
END_TASK_DEFINITION
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/EvictionController.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/EvictionController.cpp b/src/cppcache/src/EvictionController.cpp
index 726e464..64049a2 100644
--- a/src/cppcache/src/EvictionController.cpp
+++ b/src/cppcache/src/EvictionController.cpp
@@ -23,7 +23,9 @@
#include "ReadWriteLock.hpp"
#include <string>
-using namespace apache::geode::client;
+namespace apache {
+namespace geode {
+namespace client {
const char* EvictionController::NC_EC_Thread = "NC EC Thread";
EvictionController::EvictionController(size_t maxHeapSize,
@@ -54,7 +56,7 @@ int EvictionController::svc() {
int64_t pendingEvictions = 0;
while (m_run) {
int64_t readInfo = 0;
- readInfo = (int64_t)m_queue.get(1500);
+ readInfo = m_queue.get(1500);
if (readInfo == 0) continue;
processHeapInfo(readInfo, pendingEvictions);
@@ -62,7 +64,7 @@ int EvictionController::svc() {
int32_t size = m_queue.size();
for (int i = 0; i < size; i++) {
int64_t readInfo = 0;
- readInfo = (int64_t)m_queue.get();
+ readInfo = m_queue.get();
if (readInfo == 0) continue;
processHeapInfo(readInfo, pendingEvictions);
}
@@ -104,8 +106,6 @@ void EvictionController::processHeapInfo(int64_t& readInfo,
pendingEvictions += bytesToEvict;
if (evictionPercentage > 100) evictionPercentage = 100;
orderEvictions(evictionPercentage);
- // Sleep for 10 seconds to allow the evictions to catch up
- // apache::geode::client::millisleep(10); //taken this out for now
}
}
@@ -120,7 +120,7 @@ void EvictionController::deregisterRegion(std::string& name) {
// Iterate over regions vector and remove the one that we need to remove
WriteGuard guard(m_regionLock);
for (size_t i = 0; i < m_regions.size(); i++) {
- std::string str = (std::string)m_regions.at(i);
+ std::string str = m_regions.at(i);
if (str == name) {
std::vector<std::string>::iterator iter = m_regions.begin();
m_regions.erase(iter + i);
@@ -149,12 +149,12 @@ void EvictionController::evict(int32_t percentage) {
{
ReadGuard guard(m_regionLock);
for (size_t i = 0; i < m_regions.size(); i++) {
- regionTmpVector.push_back((std::string)m_regions.at(i));
+ regionTmpVector.push_back(m_regions.at(i));
}
}
for (size_t i = 0; i < regionTmpVector.size(); i++) {
- std::string str = (std::string)regionTmpVector.at(i);
+ std::string str = regionTmpVector.at(i);
RegionPtr rptr;
m_cacheImpl->getRegion(str.c_str(), rptr);
if (rptr != nullptr) {
@@ -165,3 +165,6 @@ void EvictionController::evict(int32_t percentage) {
}
}
}
+} // namespace client
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/LocalRegion.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/LocalRegion.cpp b/src/cppcache/src/LocalRegion.cpp
index 246e9db..2e465cb 100644
--- a/src/cppcache/src/LocalRegion.cpp
+++ b/src/cppcache/src/LocalRegion.cpp
@@ -21,7 +21,6 @@
#include "CacheImpl.hpp"
#include "CacheRegionHelper.hpp"
#include "CacheableToken.hpp"
-#include "NanoTimer.hpp"
#include "Utils.hpp"
#include "EntryExpiryHandler.hpp"
@@ -34,7 +33,9 @@
#include <vector>
#include <geode/PoolManager.hpp>
-using namespace apache::geode::client;
+namespace apache {
+namespace geode {
+namespace client {
LocalRegion::LocalRegion(const std::string& name, CacheImpl* cache,
const RegionInternalPtr& rPtr,
@@ -649,7 +650,7 @@ void LocalRegion::setRegionExpiryTask() {
uint32_t duration = getRegionExpiryDuration();
RegionExpiryHandler* handler =
new RegionExpiryHandler(rptr, getRegionExpiryAction(), duration);
- long expiryTaskId =
+ int64_t expiryTaskId =
CacheImpl::expiryTaskManager->scheduleExpiryTask(handler, duration, 0);
handler->setExpiryTaskId(expiryTaskId);
LOGFINE(
@@ -669,7 +670,7 @@ void LocalRegion::registerEntryExpiryTask(MapEntryImplPtr& entry) {
uint32_t duration = getEntryExpiryDuration();
EntryExpiryHandler* handler =
new EntryExpiryHandler(rptr, entry, getEntryExpirationAction(), duration);
- long id =
+ int64_t id =
CacheImpl::expiryTaskManager->scheduleExpiryTask(handler, duration, 0);
if (Log::finestEnabled()) {
CacheableKeyPtr key;
@@ -1036,9 +1037,6 @@ GfErrType LocalRegion::getAllNoThrow(const VectorOfCacheableKey& keys,
return err;
}
-namespace apache {
-namespace geode {
-namespace client {
// encapsulates actions that need to be taken for a put() operation
class PutActions {
public:
@@ -1605,9 +1603,6 @@ class InvalidateActions {
private:
LocalRegion& m_region;
};
-} // namespace client
-} // namespace geode
-} // namespace apache
template <typename TAction>
GfErrType LocalRegion::updateNoThrow(const CacheableKeyPtr& key,
@@ -3101,7 +3096,7 @@ void LocalRegion::evict(int32_t percentage) {
if (m_released || m_destroyPending) return;
if (m_entries != nullptr) {
int32_t size = m_entries->size();
- int32_t entriesToEvict = (int32_t)(percentage * size) / 100;
+ int32_t entriesToEvict = (percentage * size) / 100;
// only invoked from EvictionController so static_cast is always safe
LRUEntriesMap* lruMap = static_cast<LRUEntriesMap*>(m_entries);
LOGINFO("Evicting %d entries. Current entry count is %d", entriesToEvict,
@@ -3154,3 +3149,7 @@ CacheablePtr LocalRegion::handleReplay(GfErrType& err,
}
TombstoneListPtr LocalRegion::getTombstoneList() { return m_tombstoneList; }
+
+} // namespace client
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/Log.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/Log.cpp b/src/cppcache/src/Log.cpp
index 5a456a4..e42b9e0 100644
--- a/src/cppcache/src/Log.cpp
+++ b/src/cppcache/src/Log.cpp
@@ -21,6 +21,8 @@
#include <string>
#include <utility>
#include <vector>
+#include <thread>
+#include <chrono>
#include <ace/ACE.h>
#include <ace/Guard_T.h>
@@ -370,7 +372,7 @@ void Log::init(LogLevel level, const char* logFileName, int32_t logFileLimit,
break;
}
// continue after some sleep
- apache::geode::client::millisleep(200);
+ std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
/* (don't throw exception; try appending to existing file instead)
if (renameResult < 0) {
@@ -435,7 +437,7 @@ void Log::writeBanner() {
break;
}
// continue after some sleep
- apache::geode::client::millisleep(200);
+ std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
if (!g_log) {
g_isLogFileOpened = false;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/NanoTimer.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/NanoTimer.cpp b/src/cppcache/src/NanoTimer.cpp
deleted file mode 100644
index 25ec2e4..0000000
--- a/src/cppcache/src/NanoTimer.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "NanoTimer.hpp"
-#include <ace/OS.h>
-#include <ace/Time_Value.h>
-#include <ace/High_Res_Timer.h>
-
-// @TODO: Make these actually nano granularity when possible.
-
-namespace apache {
-namespace geode {
-namespace client {
-
-int64_t NanoTimer::now() {
- ACE_Time_Value now = ACE_High_Res_Timer::gettimeofday_hr();
- return (now.sec() * 1000000000ll) /* convert secs to nanosecs */
- + (now.usec() * 1000ll); /* convert microsecs to nanosecs */
-}
-
-void NanoTimer::sleep(uint32_t nanos) {
- timespec spec;
- spec.tv_sec = 0L;
- spec.tv_nsec = nanos;
- timespec remaining;
- remaining.tv_sec = 0L;
- remaining.tv_nsec = 0L;
- ACE_OS::nanosleep(&spec, &remaining);
-}
-
-void millisleep(uint32_t millis) {
- time_t secs = millis / 1000;
- suseconds_t usecs = (millis % 1000) * 1000;
- ACE_Time_Value duration(secs, usecs);
- ACE_OS::sleep(duration);
-}
-} // namespace client
-} // namespace geode
-} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/NanoTimer.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/NanoTimer.hpp b/src/cppcache/src/NanoTimer.hpp
deleted file mode 100644
index 8dbf4d8..0000000
--- a/src/cppcache/src/NanoTimer.hpp
+++ /dev/null
@@ -1,39 +0,0 @@
-#pragma once
-
-#ifndef GEODE_NANOTIMER_H_
-#define GEODE_NANOTIMER_H_
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <geode/geode_globals.hpp>
-
-namespace apache {
-namespace geode {
-namespace client {
-
-class CPPCACHE_EXPORT NanoTimer {
- public:
- static int64_t now();
-
- static void sleep(uint32_t nanos);
-};
-} // namespace client
-} // namespace geode
-} // namespace apache
-
-#endif // GEODE_NANOTIMER_H_
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/TcrConnectionManager.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/TcrConnectionManager.cpp b/src/cppcache/src/TcrConnectionManager.cpp
index b59acc9..71d2347 100644
--- a/src/cppcache/src/TcrConnectionManager.cpp
+++ b/src/cppcache/src/TcrConnectionManager.cpp
@@ -33,7 +33,12 @@
#include "ServerLocation.hpp"
#include <ace/INET_Addr.h>
#include <set>
-using namespace apache::geode::client;
+#include <thread>
+#include <chrono>
+
+namespace apache {
+namespace geode {
+namespace client {
volatile bool TcrConnectionManager::isNetDown = false;
volatile bool TcrConnectionManager::TEST_DURABLE_CLIENT_CRASH = false;
@@ -475,7 +480,7 @@ void TcrConnectionManager::netDown() {
isNetDown = true;
// sleep for 15 seconds to allow ping and redundancy threads to pause.
- apache::geode::client::millisleep(15000);
+ std::this_thread::sleep_for(std::chrono::seconds(15));
{
ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_endpoints.mutex());
@@ -498,7 +503,7 @@ void TcrConnectionManager::revive() {
// sleep for 15 seconds to allow redundancy thread to reestablish
// connections.
- apache::geode::client::millisleep(15000);
+ std::this_thread::sleep_for(std::chrono::seconds(15));
}
int TcrConnectionManager::redundancy(volatile bool &isRunning) {
@@ -601,3 +606,6 @@ GfErrType TcrConnectionManager::sendSyncRequestRegisterInterest(
return m_redundancyManager->sendSyncRequestRegisterInterest(
request, reply, attemptFailover, endpoint, theHADM, region);
}
+} // namespace client
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/TcrEndpoint.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/TcrEndpoint.cpp b/src/cppcache/src/TcrEndpoint.cpp
index 4458930..8e99010 100644
--- a/src/cppcache/src/TcrEndpoint.cpp
+++ b/src/cppcache/src/TcrEndpoint.cpp
@@ -24,7 +24,13 @@
#include "Utils.hpp"
#include "DistributedSystemImpl.hpp"
-using namespace apache::geode::client;
+#include <thread>
+#include <chrono>
+
+namespace apache {
+namespace geode {
+namespace client {
+
#define throwException(ex) \
{ \
LOGFINEST("%s: %s", ex.getName(), ex.getMessage()); \
@@ -236,7 +242,7 @@ GfErrType TcrEndpoint::createNewConnection(
LOGINFO("Timeout in handshake with endpoint[%s]", m_name.c_str());
err = GF_TIMOUT;
m_needToConnectInLock = true; // while creating the connection
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
} catch (const GeodeIOException& ex) {
LOGINFO("IO error[%d] in handshake with endpoint[%s]: %s",
ACE_OS::last_error(), m_name.c_str(), ex.getMessage());
@@ -774,7 +780,7 @@ inline bool TcrEndpoint::handleIOException(const std::string& message,
m_needToConnectInLock = true;
return false;
}
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
return true;
}
@@ -989,7 +995,7 @@ GfErrType TcrEndpoint::sendRequestWithRetry(
connection only when not a sticky connection.
closeConnection( conn );
}*/
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
int32_t type = request.getMessageType();
epFailure = (type != TcrMessage::QUERY && type != TcrMessage::PUTALL &&
type != TcrMessage::PUT_ALL_WITH_CALLBACK &&
@@ -1336,3 +1342,7 @@ void TcrEndpoint::sendRequestForChunkedResponse(const TcrMessage& request,
void TcrEndpoint::closeFailedConnection(TcrConnection*& conn) {
closeConnection(conn);
}
+
+} // namespace client
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/Utils.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/Utils.cpp b/src/cppcache/src/Utils.cpp
index f6f4e61..bc0605d 100644
--- a/src/cppcache/src/Utils.cpp
+++ b/src/cppcache/src/Utils.cpp
@@ -16,20 +16,21 @@
*/
#include <cstdio>
+#include <chrono>
#include <ace/OS.h>
#include <ace/Recursive_Thread_Mutex.h>
#include <ace/INET_Addr.h>
#include "Utils.hpp"
-#include "NanoTimer.hpp"
namespace apache {
namespace geode {
namespace client {
int RandGen::operator()(size_t max) {
- unsigned int seed = static_cast<unsigned int>(NanoTimer::now());
+ unsigned int seed = static_cast<unsigned int>(
+ std::chrono::system_clock::now().time_since_epoch().count());
return ACE_OS::rand_r(&seed) % max;
}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/Utils.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/Utils.hpp b/src/cppcache/src/Utils.hpp
index 16904ca..8dbe76d 100644
--- a/src/cppcache/src/Utils.hpp
+++ b/src/cppcache/src/Utils.hpp
@@ -29,7 +29,6 @@
#include <geode/ExceptionTypes.hpp>
#include <geode/CacheableString.hpp>
#include <geode/DataOutput.hpp>
-#include "NanoTimer.hpp"
#include <geode/statistics/Statistics.hpp>
#include <geode/SystemProperties.hpp>
#include <geode/DistributedSystem.hpp>
@@ -37,6 +36,7 @@
#include <string>
#include <unordered_set>
#include <memory>
+#include <chrono>
#ifdef __GNUC__
extern "C" {
@@ -145,7 +145,9 @@ class CPPCACHE_EXPORT Utils {
if (DistributedSystem::getSystemProperties() != nullptr) {
return (DistributedSystem::getSystemProperties()
->getEnableTimeStatistics())
- ? NanoTimer::now()
+ ? std::chrono::duration_cast<std::chrono::nanoseconds>(
+ std::chrono::steady_clock::now().time_since_epoch())
+ .count()
: 0;
} else {
return 0;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/statistics/HostStatSampler.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/HostStatSampler.cpp b/src/cppcache/src/statistics/HostStatSampler.cpp
index 966187a..7f8788f 100644
--- a/src/cppcache/src/statistics/HostStatSampler.cpp
+++ b/src/cppcache/src/statistics/HostStatSampler.cpp
@@ -27,19 +27,18 @@
#include <ace/OS_NS_sys_stat.h>
#include <utility>
#include <vector>
+#include <chrono>
+#include <thread>
#include "HostStatSampler.hpp"
#include "HostStatHelper.hpp"
#include "StatArchiveWriter.hpp"
-#include <NanoTimer.hpp>
#include <geode/DistributedSystem.hpp>
#include <geode/SystemProperties.hpp>
#include <geode/Log.hpp>
#include "GeodeStatisticsFactory.hpp"
#include <ClientHealthStats.hpp>
#include <ClientProxyMembershipID.hpp>
-using namespace apache::geode::statistics;
-using namespace apache::geode::client;
namespace apache {
namespace geode {
@@ -59,8 +58,6 @@ typedef std::vector<std::pair<std::string, int64_t> > g_fileInfo;
} // namespace geode
} // namespace apache
-using namespace apache::geode::statistics::globals;
-
extern "C" {
int selector(const dirent* d) {
@@ -115,6 +112,15 @@ int comparator(const dirent** d1, const dirent** d2) {
}
}
+namespace apache {
+namespace geode {
+namespace statistics {
+
+using std::chrono::high_resolution_clock;
+using std::chrono::duration_cast;
+using std::chrono::milliseconds;
+using std::chrono::nanoseconds;
+
const char* HostStatSampler::NC_HSS_Thread = "NC HSS Thread";
HostStatSampler::HostStatSampler(const char* filePath, int64_t sampleIntervalMs,
@@ -128,17 +134,16 @@ HostStatSampler::HostStatSampler(const char* filePath, int64_t sampleIntervalMs,
m_archiver = nullptr;
m_samplerStats = new StatSamplerStats();
- ACE_Time_Value startTimeValue = ACE_OS::gettimeofday();
- m_startTime = startTimeValue.msec();
+ m_startTime = system_clock::now();
m_pid = ACE_OS::getpid();
m_statMngr = statMngr;
m_archiveFileName = filePath;
- g_statFile = filePath;
+ globals::g_statFile = filePath;
m_sampleRate = sampleIntervalMs;
rollIndex = 0;
m_archiveDiskSpaceLimit = statDiskSpaceLimit;
- g_spaceUsed = 0;
+ globals::g_spaceUsed = 0;
if (statDiskSpaceLimit != 0) {
m_isStatDiskSpaceEnabled = true;
@@ -171,24 +176,24 @@ HostStatSampler::HostStatSampler(const char* filePath, int64_t sampleIntervalMs,
m_archiveFileSizeLimit = m_archiveDiskSpaceLimit;
}
- g_statFileWithExt = initStatFileWithExt();
+ globals::g_statFileWithExt = initStatFileWithExt();
#ifdef _WIN32
// replace all '\' with '/' to make everything easier..
- size_t len = g_statFile.length() + 1;
+ size_t len = globals::g_statFile.length() + 1;
char* slashtmp = new char[len];
- ACE_OS::strncpy(slashtmp, g_statFile.c_str(), len);
- for (size_t i = 0; i < g_statFile.length(); i++) {
+ ACE_OS::strncpy(slashtmp, globals::g_statFile.c_str(), len);
+ for (size_t i = 0; i < globals::g_statFile.length(); i++) {
if (slashtmp[i] == '/') {
slashtmp[i] = '\\';
}
}
- g_statFile = slashtmp;
+ globals::g_statFile = slashtmp;
delete[] slashtmp;
slashtmp = nullptr;
#endif
- std::string dirname = ACE::dirname(g_statFile.c_str());
+ std::string dirname = ACE::dirname(globals::g_statFile.c_str());
// struct dirent **resultArray;
// int entries_count = ACE_OS::scandir(dirname.c_str(), &resultArray,
// selector, comparator);
@@ -219,14 +224,14 @@ HostStatSampler::HostStatSampler(const char* filePath, int64_t sampleIntervalMs,
resultArray = nullptr;
}*/
- FILE* existingFile = fopen(g_statFileWithExt.c_str(), "r");
+ FILE* existingFile = fopen(globals::g_statFileWithExt.c_str(), "r");
if (existingFile != nullptr && statFileLimit > 0) {
fclose(existingFile);
/* adongre
* CID 28820: Resource leak (RESOURCE_LEAK)
*/
existingFile = nullptr;
- changeArchive(g_statFileWithExt);
+ changeArchive(globals::g_statFileWithExt);
} else {
writeGfs();
}
@@ -337,7 +342,9 @@ std::vector<Statistics*>& HostStatSampler::getNewStatistics() {
int64_t HostStatSampler::getSystemId() { return m_pid; }
-int64_t HostStatSampler::getSystemStartTime() { return m_startTime; }
+system_clock::time_point HostStatSampler::getSystemStartTime() {
+ return m_startTime;
+}
std::string HostStatSampler::getSystemDirectoryPath() {
ACE_utsname u;
@@ -358,7 +365,7 @@ void HostStatSampler::changeArchive(std::string filename) {
}
filename = chkForGFSExt(filename);
if (m_archiver != nullptr) {
- g_previoussamplesize = m_archiver->getSampleSize();
+ globals::g_previoussamplesize = m_archiver->getSampleSize();
m_archiver->closeFile();
}
// create new file only when tis file has some data; otherwise reuse it
@@ -622,16 +629,16 @@ void HostStatSampler::doSample(std::string& archivefilename) {
if (m_archiveFileSizeLimit != 0) {
int64_t size = m_archiver->getSampleSize();
int64_t bytesWritten =
- m_archiver->bytesWritten(); // + g_previoussamplesize;
+ m_archiver->bytesWritten(); // + globals::g_previoussamplesize;
if (bytesWritten > (m_archiveFileSizeLimit - size)) {
// roll the archive
changeArchive(archivefilename);
}
}
- g_spaceUsed += m_archiver->bytesWritten();
+ globals::g_spaceUsed += m_archiver->bytesWritten();
// delete older stat files if disk limit is about to be exceeded.
if ((m_archiveDiskSpaceLimit != 0) &&
- (g_spaceUsed >=
+ (globals::g_spaceUsed >=
(m_archiveDiskSpaceLimit - m_archiver->getSampleSize()))) {
checkDiskLimit();
}
@@ -643,10 +650,10 @@ void HostStatSampler::doSample(std::string& archivefilename) {
}
void HostStatSampler::checkDiskLimit() {
- g_fileInfo fileInfo;
- g_spaceUsed = 0;
+ globals::g_fileInfo fileInfo;
+ globals::g_spaceUsed = 0;
char fullpath[512] = {0};
- std::string dirname = ACE::dirname(g_statFile.c_str());
+ std::string dirname = ACE::dirname(globals::g_statFile.c_str());
// struct dirent **resultArray;
// int entries_count = ACE_OS::scandir(dirname.c_str(), &resultArray,
// selector, comparator);
@@ -658,11 +665,11 @@ void HostStatSampler::checkDiskLimit() {
ACE_OS::snprintf(fullpath, 512, "%s%c%s", dirname.c_str(),
ACE_DIRECTORY_SEPARATOR_CHAR, sds[i]->d_name);
ACE_OS::stat(fullpath, &statBuf);
- g_fileInfoPair = std::make_pair(fullpath, statBuf.st_size);
- fileInfo.push_back(g_fileInfoPair);
- g_spaceUsed += fileInfo[i - 1].second;
+ globals::g_fileInfoPair = std::make_pair(fullpath, statBuf.st_size);
+ fileInfo.push_back(globals::g_fileInfoPair);
+ globals::g_spaceUsed += fileInfo[i - 1].second;
}
- g_spaceUsed += m_archiver->bytesWritten();
+ globals::g_spaceUsed += m_archiver->bytesWritten();
/*for(int i = 0; i < entries_count; i++) {
ACE_OS::free ( resultArray[i] );
}
@@ -673,11 +680,11 @@ void HostStatSampler::checkDiskLimit() {
sds.close();
}
int fileIndex = 0;
- while ((g_spaceUsed >
+ while ((globals::g_spaceUsed >
m_archiveDiskSpaceLimit) /*&& (fileIndex < entries_count)*/) {
int64_t fileSize = fileInfo[fileIndex].second;
if (ACE_OS::unlink(fileInfo[fileIndex].first.c_str()) == 0) {
- g_spaceUsed -= fileSize;
+ globals::g_spaceUsed -= fileSize;
} else {
LOGWARN("%s\t%s\n", "Could not delete",
fileInfo[fileIndex].first.c_str());
@@ -697,8 +704,8 @@ int32_t HostStatSampler::svc(void) {
if (!m_isStatDiskSpaceEnabled) {
changeArchive(archivefilename);
}
- int32_t msSpentWorking = 0;
- int32_t msRate = static_cast<int32_t>(getSampleRate());
+ auto msSpentWorking = milliseconds::zero();
+ auto samplingRate = milliseconds(getSampleRate());
bool gotexception = false;
int waitTime = 0;
while (!m_stopRequested) {
@@ -714,26 +721,23 @@ int32_t HostStatSampler::svc(void) {
gotexception = false;
changeArchive(archivefilename);
}
- int64_t sampleStartNanos = NanoTimer::now();
+
+ auto sampleStart = high_resolution_clock::now();
doSample(archivefilename);
- int64_t sampleEndNanos = NanoTimer::now();
- int64_t nanosSpentWorking = sampleEndNanos - sampleStartNanos;
+ nanoseconds spentWorking = high_resolution_clock::now() - sampleStart;
// updating the sampler statistics
- accountForTimeSpentWorking(nanosSpentWorking);
- msSpentWorking = static_cast<int32_t>(nanosSpentWorking / 1000000);
-
- // Continous check for m_stopRequested to sped up stop time.
- int32_t msToWait = msRate - msSpentWorking;
- while (msToWait > 0) {
- ACE_Time_Value sleepTime;
- sleepTime.msec(msToWait > 100 ? 100 : msToWait);
- ACE_OS::sleep(sleepTime);
- msToWait -= 100;
- if (m_stopRequested) {
- break;
- }
+ accountForTimeSpentWorking(spentWorking.count());
+
+ // TODO: replace with condition on m_stopRequested
+ auto sleepDuration =
+ samplingRate - duration_cast<milliseconds>(spentWorking);
+ static const auto wakeInterval = milliseconds(100);
+ while (!m_stopRequested && sleepDuration > milliseconds::zero()) {
+ std::this_thread::sleep_for(
+ sleepDuration > wakeInterval ? wakeInterval : sleepDuration);
+ sleepDuration -= wakeInterval;
}
} catch (Exception& e) {
// log the exception and let the thread exit.
@@ -764,3 +768,6 @@ int32_t HostStatSampler::svc(void) {
m_running = false;
return 0;
}
+} // namespace statistics
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/statistics/HostStatSampler.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/HostStatSampler.hpp b/src/cppcache/src/statistics/HostStatSampler.hpp
index a393815..7723799 100644
--- a/src/cppcache/src/statistics/HostStatSampler.hpp
+++ b/src/cppcache/src/statistics/HostStatSampler.hpp
@@ -22,6 +22,7 @@
#include <string>
#include <vector>
+#include <chrono>
#include <ace/Task.h>
#include <ace/Recursive_Thread_Mutex.h>
#include <geode/geode_globals.hpp>
@@ -50,6 +51,8 @@ namespace apache {
namespace geode {
namespace statistics {
+using std::chrono::system_clock;
+
class StatArchiveWriter;
class StatisticsManager;
/**
@@ -145,7 +148,7 @@ class CPPCACHE_EXPORT HostStatSampler : public ACE_Task_Base,
/**
* Returns the time this sampler's system was started.
*/
- int64_t getSystemStartTime();
+ system_clock::time_point getSystemStartTime();
/**
* Returns the path to this sampler's system directory; if it has one.
*/
@@ -212,7 +215,8 @@ class CPPCACHE_EXPORT HostStatSampler : public ACE_Task_Base,
StatisticsManager* m_statMngr;
int64_t m_pid;
- int64_t m_startTime;
+ system_clock::time_point m_startTime;
+
std::string initStatFileWithExt();
/**
* The archiveFile, after it exceeds archiveFileSizeLimit should be rolled
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/statistics/PoolStatsSampler.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/PoolStatsSampler.cpp b/src/cppcache/src/statistics/PoolStatsSampler.cpp
index 77a3f7b..96e5d78 100644
--- a/src/cppcache/src/statistics/PoolStatsSampler.cpp
+++ b/src/cppcache/src/statistics/PoolStatsSampler.cpp
@@ -21,10 +21,19 @@
#include <ThinClientPoolDM.hpp>
#include "GeodeStatisticsFactory.hpp"
#include <ClientHealthStats.hpp>
-#include <NanoTimer.hpp>
#include "HostStatHelper.hpp"
-using namespace apache::geode::statistics;
-using namespace apache::geode::client;
+#include <chrono>
+#include <thread>
+
+namespace apache {
+namespace geode {
+namespace statistics {
+
+using std::chrono::high_resolution_clock;
+using std::chrono::duration_cast;
+using std::chrono::milliseconds;
+using std::chrono::nanoseconds;
+
const char* PoolStatsSampler::NC_PSS_Thread = "NC PSS Thread";
PoolStatsSampler::PoolStatsSampler(int64_t sampleRate, CacheImpl* cache,
@@ -41,24 +50,20 @@ PoolStatsSampler::~PoolStatsSampler() {
int32_t PoolStatsSampler::svc() {
DistributedSystemImpl::setThreadName(NC_PSS_Thread);
- int32_t msSpentWorking = 0;
- int32_t msRate = static_cast<int32_t>(m_sampleRate);
+ auto msSpentWorking = milliseconds::zero();
+ auto samplingRate = milliseconds(m_sampleRate);
// ACE_Guard < ACE_Recursive_Thread_Mutex > _guard( m_lock );
while (!m_stopRequested) {
- int64_t sampleStartNanos = NanoTimer::now();
+ auto sampleStart = high_resolution_clock::now();
putStatsInAdminRegion();
- int64_t sampleEndNanos = NanoTimer::now();
- int64_t nanosSpentWorking = sampleEndNanos - sampleStartNanos;
- msSpentWorking = static_cast<int32_t>(nanosSpentWorking / 1000000);
- int32_t msToWait = msRate - msSpentWorking;
- while (msToWait > 0) {
- ACE_Time_Value sleepTime;
- sleepTime.msec(msToWait > 100 ? 100 : msToWait);
- ACE_OS::sleep(sleepTime);
- msToWait -= 100;
- if (m_stopRequested) {
- break;
- }
+ nanoseconds spentWorking = high_resolution_clock::now() - sampleStart;
+ auto sleepDuration =
+ samplingRate - duration_cast<milliseconds>(spentWorking);
+ static const auto wakeInterval = milliseconds(100);
+ while (!m_stopRequested && sleepDuration > milliseconds::zero()) {
+ std::this_thread::sleep_for(sleepDuration > wakeInterval ? wakeInterval
+ : sleepDuration);
+ sleepDuration -= wakeInterval;
}
}
return 0;
@@ -127,3 +132,6 @@ void PoolStatsSampler::putStatsInAdminRegion() {
LOGDEBUG("Exception occurred, trying again.");
}
}
+} // namespace statistics
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/statistics/StatArchiveWriter.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatArchiveWriter.cpp b/src/cppcache/src/statistics/StatArchiveWriter.cpp
index 03bd92e..90e79f2 100644
--- a/src/cppcache/src/statistics/StatArchiveWriter.cpp
+++ b/src/cppcache/src/statistics/StatArchiveWriter.cpp
@@ -26,10 +26,16 @@
#include "StatArchiveWriter.hpp"
#include "GeodeStatisticsFactory.hpp"
-#include <NanoTimer.hpp>
-using namespace apache::geode::client;
-using namespace apache::geode::statistics;
+namespace apache {
+namespace geode {
+namespace statistics {
+
+using std::chrono::steady_clock;
+using std::chrono::system_clock;
+using std::chrono::duration_cast;
+using std::chrono::milliseconds;
+using std::chrono::nanoseconds;
// Constructor and Member functions of StatDataOutput class
@@ -321,20 +327,19 @@ StatArchiveWriter::StatArchiveWriter(std::string outfile,
this->sampler = samplerArg;
// write the time, system property etc.
- this->previousTimeStamp = NanoTimer::now();
- this->previousTimeStamp += NANOS_PER_MILLI / 2;
- this->previousTimeStamp /= NANOS_PER_MILLI;
- ACE_Time_Value now = ACE_OS::gettimeofday();
- int64_t epochsec = now.sec();
- int64_t initialDate = epochsec * 1000;
+ this->previousTimeStamp = steady_clock::now();
this->dataBuffer->writeByte(HEADER_TOKEN);
this->dataBuffer->writeByte(ARCHIVE_VERSION);
- this->dataBuffer->writeLong(initialDate);
+ this->dataBuffer->writeLong(
+ duration_cast<milliseconds>(system_clock::now().time_since_epoch())
+ .count());
int64_t sysId = sampler->getSystemId();
this->dataBuffer->writeLong(sysId);
- int64_t sysStartTime = sampler->getSystemStartTime();
- this->dataBuffer->writeLong(sysStartTime);
+ this->dataBuffer->writeLong(
+ duration_cast<milliseconds>(
+ sampler->getSystemStartTime().time_since_epoch())
+ .count());
int32_t tzOffset = ACE_OS::timezone();
// offset in milli seconds
tzOffset = tzOffset * -1 * 1000;
@@ -342,7 +347,7 @@ StatArchiveWriter::StatArchiveWriter(std::string outfile,
struct tm *tm_val;
time_t clock = ACE_OS::time();
- tm_val = localtime(&clock);
+ tm_val = ACE_OS::localtime(&clock);
char buf[512] = {0};
ACE_OS::strftime(buf, sizeof(buf), "%Z", tm_val);
std::string tzId(buf);
@@ -389,7 +394,7 @@ int64_t StatArchiveWriter::bytesWritten() { return bytesWrittenToFile; }
int64_t StatArchiveWriter::getSampleSize() { return m_samplesize; }
-void StatArchiveWriter::sample(int64_t timeStamp) {
+void StatArchiveWriter::sample(const steady_clock::time_point &timeStamp) {
ACE_Guard<ACE_Recursive_Thread_Mutex> guard(sampler->getStatListMutex());
m_samplesize = dataBuffer->getBytesWritten();
@@ -408,10 +413,7 @@ void StatArchiveWriter::sample(int64_t timeStamp) {
m_samplesize = dataBuffer->getBytesWritten() - m_samplesize;
}
-void StatArchiveWriter::sample() {
- int64_t timestamp = NanoTimer::now();
- sample(timestamp);
-}
+void StatArchiveWriter::sample() { sample(steady_clock::now()); }
void StatArchiveWriter::close() {
sample();
@@ -512,13 +514,13 @@ void StatArchiveWriter::resampleResources() {
}
}
-void StatArchiveWriter::writeTimeStamp(int64_t timeStamp) {
- timeStamp += NANOS_PER_MILLI / 2;
- timeStamp /= NANOS_PER_MILLI;
- int64_t delta = timeStamp - this->previousTimeStamp;
+void StatArchiveWriter::writeTimeStamp(
+ const steady_clock::time_point &timeStamp) {
+ int32_t delta =
+ duration_cast<milliseconds>(timeStamp - this->previousTimeStamp).count();
if (delta > MAX_SHORT_TIMESTAMP) {
dataBuffer->writeShort(static_cast<int16_t>(INT_TIMESTAMP_TOKEN));
- dataBuffer->writeInt(static_cast<int32_t>(delta));
+ dataBuffer->writeInt(delta);
} else {
dataBuffer->writeShort(static_cast<uint16_t>(delta));
}
@@ -615,3 +617,6 @@ void StatArchiveWriter::writeResourceInst(StatDataOutput *dataOut,
dataOut->writeByte(static_cast<int8_t>(instId));
}
}
+} // namespace statistics
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/statistics/StatArchiveWriter.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatArchiveWriter.hpp b/src/cppcache/src/statistics/StatArchiveWriter.hpp
index 10b50a3..55f30cb 100644
--- a/src/cppcache/src/statistics/StatArchiveWriter.hpp
+++ b/src/cppcache/src/statistics/StatArchiveWriter.hpp
@@ -33,6 +33,7 @@
#include <geode/Log.hpp>
#include <geode/DataOutput.hpp>
#include <NonCopyable.hpp>
+#include <chrono>
using namespace apache::geode::client;
@@ -54,7 +55,6 @@ const int16_t ILLEGAL_RESOURCE_INST_ID_TOKEN = -1;
const int32_t MAX_SHORT_RESOURCE_INST_ID = 65535;
const int32_t MAX_SHORT_TIMESTAMP = 65534;
const int32_t INT_TIMESTAMP_TOKEN = 65535;
-const int64_t NANOS_PER_MILLI = 1000000;
/** @file
*/
@@ -62,6 +62,10 @@ const int64_t NANOS_PER_MILLI = 1000000;
namespace apache {
namespace geode {
namespace statistics {
+
+using std::chrono::system_clock;
+using std::chrono::steady_clock;
+
/**
* Some of the classes which are used by the StatArchiveWriter Class
* 1. StatDataOutput // Just a wrapper around DataOutput so that the number of
@@ -200,7 +204,7 @@ class CPPCACHE_EXPORT StatArchiveWriter {
private:
HostStatSampler *sampler;
StatDataOutput *dataBuffer;
- int64_t previousTimeStamp;
+ steady_clock::time_point previousTimeStamp;
int32_t resourceTypeId;
int32_t resourceInstId;
int32_t statResourcesModCount;
@@ -215,7 +219,7 @@ class CPPCACHE_EXPORT StatArchiveWriter {
void sampleResources();
void resampleResources();
void writeResourceInst(StatDataOutput *, int32_t);
- void writeTimeStamp(int64_t timeStamp);
+ void writeTimeStamp(const steady_clock::time_point &timeStamp);
void writeStatValue(StatisticDescriptor *f, int64_t v, DataOutput dataOut);
ResourceType *getResourceType(Statistics *);
bool resourceInstMapHas(Statistics *sp);
@@ -232,7 +236,7 @@ class CPPCACHE_EXPORT StatArchiveWriter {
* Archives a sample snapshot at the given timeStamp.
* @param timeStamp a value obtained using NanoTimer::now.
*/
- void sample(int64_t timeStamp);
+ void sample(const steady_clock::time_point &timeStamp);
/**
* Archives a sample snapshot at the current time.
*/
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/test/NanoTimerTest.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/test/NanoTimerTest.cpp b/src/cppcache/test/NanoTimerTest.cpp
deleted file mode 100644
index 7c10ab5..0000000
--- a/src/cppcache/test/NanoTimerTest.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <gtest/gtest.h>
-
-#include <NanoTimer.hpp>
-
-using namespace apache::geode::client;
-
-TEST(NanoTimerTest, ValidateSleep) {
- const int64_t before = NanoTimer::now();
- NanoTimer::sleep(3000000UL /* nano-seconds */);
- const int64_t after = NanoTimer::now();
- EXPECT_LE(3000000L /* nano-seconds */, (after - before))
- << "Slept at least three milli-seconds";
-}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/quickstart/cpp/DurableClient.cpp
----------------------------------------------------------------------
diff --git a/src/quickstart/cpp/DurableClient.cpp b/src/quickstart/cpp/DurableClient.cpp
index 909172a..b406237 100644
--- a/src/quickstart/cpp/DurableClient.cpp
+++ b/src/quickstart/cpp/DurableClient.cpp
@@ -83,7 +83,7 @@ void RunDurableClient() {
LOGINFO("Sent ReadyForEvents message to server");
// wait for some time to recieve events
- apache::geode::client::millisleep(1000);
+ std::this_thread::sleep_for(std::chrono::seconds(1));
// Close the Geode Cache with keepalive = true. Server will queue events
// for
[3/5] geode-native git commit: GEODE-2531: Replace HostAsm::atomic
with std::atomic.
Posted by jb...@apache.org.
GEODE-2531: Replace HostAsm::atomic with std::atomic.
Project: http://git-wip-us.apache.org/repos/asf/geode-native/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode-native/commit/0cc06f02
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/0cc06f02
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/0cc06f02
Branch: refs/heads/develop
Commit: 0cc06f027f2a0197b66ebd1f13207c67f2af7f93
Parents: 3305de7
Author: Jacob Barrett <jb...@pivotal.io>
Authored: Wed Feb 22 22:38:03 2017 -0800
Committer: Ernie Burghardt <eb...@pivotal.io>
Committed: Thu Jun 22 13:54:06 2017 -0700
----------------------------------------------------------------------
src/cppcache/include/geode/CacheStatistics.hpp | 4 +-
src/cppcache/include/geode/geode_globals.hpp | 4 +
src/cppcache/src/AtomicInc.hpp | 90 ---------
src/cppcache/src/CMakeLists.txt | 7 -
src/cppcache/src/CacheStatistics.cpp | 5 +-
src/cppcache/src/ConcurrentEntriesMap.cpp | 7 +-
src/cppcache/src/ConcurrentEntriesMap.hpp | 7 +-
src/cppcache/src/HostAsm.cpp | 136 -------------
src/cppcache/src/HostAsm.hpp | 197 -------------------
src/cppcache/src/LRUEntriesMap.cpp | 2 +-
src/cppcache/src/LRUEntriesMap.hpp | 5 +-
src/cppcache/src/LRULocalDestroyAction.hpp | 1 +
src/cppcache/src/MapEntry.hpp | 16 +-
src/cppcache/src/MapSegment.cpp | 2 +-
src/cppcache/src/MapSegment.hpp | 4 +-
src/cppcache/src/TXId.cpp | 2 +-
src/cppcache/src/TXId.hpp | 4 +-
src/cppcache/src/TcrConnection.cpp | 8 +-
src/cppcache/src/TcrConnection.hpp | 3 +-
src/cppcache/src/TcrEndpoint.hpp | 7 +-
src/cppcache/src/TcrMessage.hpp | 4 +-
src/cppcache/src/ThinClientPoolDM.cpp | 43 ++--
src/cppcache/src/ThinClientPoolDM.hpp | 4 +-
src/cppcache/src/hostsolaris.asm | 105 ----------
.../src/statistics/AtomicStatisticsImpl.cpp | 35 ++--
.../src/statistics/AtomicStatisticsImpl.hpp | 14 +-
src/cppcache/src/statistics/HostStatHelper.cpp | 2 +-
.../src/statistics/StatisticsManager.cpp | 2 -
src/tests/cpp/fwklib/ClientTask.hpp | 18 +-
src/tests/cpp/fwklib/PerfFwk.hpp | 1 -
src/tests/cpp/fwklib/PoolHelper.hpp | 2 +-
src/tests/cpp/fwklib/RegionHelper.hpp | 2 +-
src/tests/cpp/fwklib/Service.cpp | 2 +-
src/tests/cpp/fwklib/Service.hpp | 12 +-
src/tests/cpp/fwklib/UDPIpc.hpp | 20 +-
35 files changed, 120 insertions(+), 657 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/include/geode/CacheStatistics.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/include/geode/CacheStatistics.hpp b/src/cppcache/include/geode/CacheStatistics.hpp
index f14fd82..afbb82a 100644
--- a/src/cppcache/include/geode/CacheStatistics.hpp
+++ b/src/cppcache/include/geode/CacheStatistics.hpp
@@ -102,8 +102,8 @@ class CPPCACHE_EXPORT CacheStatistics {
virtual void setLastAccessedTime(uint32_t lat);
virtual void setLastModifiedTime(uint32_t lmt);
- volatile uint32_t m_lastAccessTime;
- volatile uint32_t m_lastModifiedTime;
+ std::atomic<uint32_t> m_lastAccessTime;
+ std::atomic<uint32_t> m_lastModifiedTime;
friend class LocalRegion;
};
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/include/geode/geode_globals.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/include/geode/geode_globals.hpp b/src/cppcache/include/geode/geode_globals.hpp
index 9c112b2..a22cfdd 100644
--- a/src/cppcache/include/geode/geode_globals.hpp
+++ b/src/cppcache/include/geode/geode_globals.hpp
@@ -96,8 +96,12 @@
#define __has_cpp_attribute(x) 0
#endif
+<<<<<<< HEAD
#if __cplusplus >= 201402L
#if __has_cpp_attribute(deprecated)
+=======
+#if __cplusplus >= 201402L && __has_cpp_attribute(deprecated)
+>>>>>>> GEODE-2531: Replace HostAsm::atomic with std::atomic.
// C++14 standard deprecated attribute
#define __DEPRECATED__(msg) [[deprecated(msg)]]
#else
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/AtomicInc.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/AtomicInc.hpp b/src/cppcache/src/AtomicInc.hpp
deleted file mode 100644
index 36ce2c2..0000000
--- a/src/cppcache/src/AtomicInc.hpp
+++ /dev/null
@@ -1,90 +0,0 @@
-#pragma once
-
-#ifndef GEODE_ATOMICINC_H_
-#define GEODE_ATOMICINC_H_
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <geode/geode_globals.hpp>
-
-#include "HostAsm.hpp"
-
-namespace apache {
-namespace geode {
-namespace client {
-
-/**
- * @brief Atomic type wrapper for thread safe arithmetic limited to addition.
- */
-class CPPCACHE_EXPORT AtomicInc {
- private:
- volatile int32_t m_value;
-
- public:
- /** @brief Initialize m_value to c. */
- AtomicInc(const int32_t c = 0) : m_value(c) {}
- /** @brief reset m_value to c. */
- void resetValue(const int32_t c = 0) { m_value = c; }
-
- /** @brief Atomically pre-increment m_value. */
- int32_t operator++(void) {
- // return ++m_value;
- return HostAsm::atomicAdd(m_value, 1);
- }
-
- /** @brief Atomically post-increment m_value. */
- int32_t operator++(int) {
- // return m_value++;
- return HostAsm::atomicAddPostfix(m_value, 1);
- }
-
- /** @brief Atomically increment m_value by rhs. */
- int32_t operator+=(const int32_t &rhs) {
- // return m_value += rhs;
- return HostAsm::atomicAdd(m_value, rhs);
- }
-
- /** @brief Atomically pre-decrement m_value. */
- int32_t operator--(void) {
- // return --m_value;
- return HostAsm::atomicAdd(m_value, -1);
- }
-
- /** @brief Atomically post-decrement m_value. */
- int32_t operator--(int) {
- // return m_value--;
- return HostAsm::atomicAddPostfix(m_value, -1);
- }
-
- /** @brief Atomically decrement m_value by rhs. */
- int32_t operator-=(const int32_t &rhs) {
- // return m_value -= rhs;
- return HostAsm::atomicAdd(m_value, -1 * rhs);
- }
-
- /** @brief Explicitly return m_value. */
- int32_t value(void) const {
- // return m_value;
- return m_value;
- }
-};
-} // namespace client
-} // namespace geode
-} // namespace apache
-
-#endif // GEODE_ATOMICINC_H_
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/cppcache/src/CMakeLists.txt b/src/cppcache/src/CMakeLists.txt
index e92c6d7..07c6ad9 100644
--- a/src/cppcache/src/CMakeLists.txt
+++ b/src/cppcache/src/CMakeLists.txt
@@ -83,13 +83,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
demangle
kstat
)
- if (CMAKE_SYSTEM_PROCESSOR STREQUAL "sparc")
- set(CMAKE_ASM_COMPILER fbe)
- set(CMAKE_ASM_SOURCE_FILE_EXTENSIONS asm)
- set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -m64 -K PIC -L -s -P -o <OBJECT> <SOURCE>")
- enable_language(ASM)
- set(SOURCES_ALL ${SOURCES_ALL} hostsolaris.asm)
- endif()
endif()
if (${WIN32})
target_link_libraries(_apache-geode INTERFACE
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/CacheStatistics.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/CacheStatistics.cpp b/src/cppcache/src/CacheStatistics.cpp
index 994346b..d825946 100644
--- a/src/cppcache/src/CacheStatistics.cpp
+++ b/src/cppcache/src/CacheStatistics.cpp
@@ -16,7 +16,6 @@
*/
#include <geode/CacheStatistics.hpp>
-#include <HostAsm.hpp>
using namespace apache::geode::client;
@@ -28,11 +27,11 @@ CacheStatistics::CacheStatistics() {
CacheStatistics::~CacheStatistics() {}
void CacheStatistics::setLastModifiedTime(uint32_t lmt) {
- HostAsm::atomicSet(m_lastModifiedTime, lmt);
+ m_lastModifiedTime = lmt;
}
void CacheStatistics::setLastAccessedTime(uint32_t lat) {
- HostAsm::atomicSet(m_lastAccessTime, lat);
+ m_lastAccessTime = lat;
}
uint32_t CacheStatistics::getLastModifiedTime() const {
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/ConcurrentEntriesMap.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/ConcurrentEntriesMap.cpp b/src/cppcache/src/ConcurrentEntriesMap.cpp
index ea21d14..c79d4c2 100644
--- a/src/cppcache/src/ConcurrentEntriesMap.cpp
+++ b/src/cppcache/src/ConcurrentEntriesMap.cpp
@@ -17,7 +17,6 @@
#include "ConcurrentEntriesMap.hpp"
#include "RegionInternal.hpp"
#include "TableOfPrimes.hpp"
-#include "HostAsm.hpp"
#include <algorithm>
@@ -170,7 +169,7 @@ void ConcurrentEntriesMap::values(VectorOfCacheable& result) const {
}
}
-uint32_t ConcurrentEntriesMap::size() const { return m_size.value(); }
+uint32_t ConcurrentEntriesMap::size() const { return m_size; }
int ConcurrentEntriesMap::addTrackerForEntry(const CacheableKeyPtr& key,
CacheablePtr& oldValue,
@@ -200,7 +199,7 @@ int ConcurrentEntriesMap::addTrackerForAllEntries(
m_segments[index].addTrackerForAllEntries(updateCounterMap);
}
if (addDestroyTracking) {
- return HostAsm::atomicAdd(m_numDestroyTrackers, 1);
+ return ++m_numDestroyTrackers;
}
return 0;
}
@@ -209,7 +208,7 @@ void ConcurrentEntriesMap::removeDestroyTracking() {
// This function is disabled if concurrency checks are enabled. The versioning
// changes takes care of the version and no need for tracking the entry
if (m_concurrencyChecksEnabled) return;
- if (HostAsm::atomicAdd(m_numDestroyTrackers, -1) == 0) {
+ if (--m_numDestroyTrackers == 0) {
for (int index = 0; index < m_concurrency; ++index) {
m_segments[index].removeDestroyTracking();
}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/ConcurrentEntriesMap.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/ConcurrentEntriesMap.hpp b/src/cppcache/src/ConcurrentEntriesMap.hpp
index 5494f8b..94e6a34 100644
--- a/src/cppcache/src/ConcurrentEntriesMap.hpp
+++ b/src/cppcache/src/ConcurrentEntriesMap.hpp
@@ -20,10 +20,11 @@
* limitations under the License.
*/
+#include <atomic>
#include <geode/geode_globals.hpp>
#include "EntriesMap.hpp"
#include "MapSegment.hpp"
-#include "AtomicInc.hpp"
+
#include "ExpMapEntry.hpp"
#include <geode/RegionEntry.hpp>
@@ -39,9 +40,9 @@ class CPPCACHE_EXPORT ConcurrentEntriesMap : public EntriesMap {
protected:
uint8_t m_concurrency;
MapSegment* m_segments;
- AtomicInc m_size;
+ std::atomic<uint32_t> m_size;
RegionInternal* m_region;
- volatile int m_numDestroyTrackers;
+ std::atomic<int32_t> m_numDestroyTrackers;
bool m_concurrencyChecksEnabled;
// TODO: hashcode() is invoked 3-4 times -- need a better
// implementation (STLport hash_map?) that will invoke it only once
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/HostAsm.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/HostAsm.cpp b/src/cppcache/src/HostAsm.cpp
deleted file mode 100644
index 6a65249..0000000
--- a/src/cppcache/src/HostAsm.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "HostAsm.hpp"
-#include <ace/Atomic_Op_T.h>
-#include <ace/Recursive_Thread_Mutex.h>
-#ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-#endif
-
-using namespace apache::geode::client;
-
-// TODO refactor - why do we have our own atomic methods? why not use C++11?
-
-#if defined(_LINUX) || defined(_X86_SOLARIS)
-
-typedef long LONG;
-
-inline uint32_t InterlockedCompareExchange(volatile LONG* dest, uint32_t exch,
- uint32_t comp) {
-#if defined(_LINUX)
- uint32_t old;
-
- __asm__ __volatile__("lock; cmpxchgl %2, %0"
- : "=m"(*dest), "=a"(old)
- : "r"(exch), "m"(*dest), "a"(comp));
- return (old);
-#endif
-#if defined(_X86_SOLARIS)
- uint32_t old;
- old = atomic_cas_32((volatile uint32_t*)dest, comp, exch);
- return (old);
-#endif
-}
-
-#endif
-
-#ifdef _SPARC_SOLARIS
-typedef long LONG;
-extern "C" {
-int32_t InterlockedCompareExchange(volatile LONG*, int32_t, int32_t);
-}
-#endif
-
-void HostAsm::atomicAnd(volatile uint32_t& ctr, uint32_t mask) {
-#if defined(_MACOSX)
- OSAtomicAnd32Barrier(mask, &ctr);
-#else
- bool success = false;
- while (!success) {
- uint32_t oldValue = ctr;
- uint32_t newValue = oldValue & mask;
- volatile LONG* signedctr = (volatile LONG*)&ctr;
- if (InterlockedCompareExchange(signedctr, newValue, oldValue) == oldValue) {
- return;
- }
- }
-#endif
-}
-// if return value is same as valuetoCompare that means you succeed, otherwise
-// some other thread change this value
-uint32_t HostAsm::atomicCompareAndExchange(volatile uint32_t& oldValue,
- uint32_t newValue,
- uint32_t valueToCompare) {
-#if defined(_MACOSX)
- if (OSAtomicCompareAndSwap32Barrier(
- valueToCompare, newValue,
- reinterpret_cast<volatile int32_t*>(&oldValue))) {
- return valueToCompare;
- } else {
- return oldValue;
- }
-#else
- volatile LONG* signedctr = (volatile LONG*)&oldValue;
- uint32_t retVal =
- InterlockedCompareExchange(signedctr, newValue, valueToCompare);
-
- return retVal;
-#endif
-}
-
-void HostAsm::atomicOr(volatile uint32_t& ctr, uint32_t mask) {
-#if defined(_MACOSX)
- OSAtomicOr32Barrier(mask, &ctr);
-#else
- bool success = false;
- while (!success) {
- uint32_t oldValue = ctr;
- uint32_t newValue = oldValue | mask;
- volatile LONG* signedctr = (volatile LONG*)&ctr;
- if (InterlockedCompareExchange(signedctr, newValue, oldValue) == oldValue) {
- return;
- }
- }
-#endif
-}
-
-void HostAsm::atomicSet(volatile uint32_t& data, uint32_t newValue) {
-// TODO MACOSX this entire function makes no sense unless it is just to force
-// memory barriers
-#if defined(_MACOSX)
- uint32_t oldValue;
- do {
- oldValue = data;
- } while (!OSAtomicCompareAndSwap32Barrier(
- oldValue, newValue, reinterpret_cast<volatile int32_t*>(&data)));
-
-#else
- bool success = false;
- while (!success) {
- uint32_t oldValue = data;
- volatile LONG* longData = (volatile LONG*)&data;
- if (InterlockedCompareExchange(longData, newValue, oldValue) == oldValue) {
- return;
- }
- }
-#endif
-}
-#ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
-#pragma clang diagnostic pop
-#endif
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/HostAsm.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/HostAsm.hpp b/src/cppcache/src/HostAsm.hpp
deleted file mode 100644
index 3fe59a4..0000000
--- a/src/cppcache/src/HostAsm.hpp
+++ /dev/null
@@ -1,197 +0,0 @@
-#pragma once
-
-#ifndef GEODE_HOSTASM_H_
-#define GEODE_HOSTASM_H_
-
-#ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
-#endif
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
-
-This file wraps the assembly spinlock routines, and related atomic update
-routines in the class apache::geode::client::util::util_impl::Host. Some ace is
-included.
-
-*/
-
-#include "config.h"
-#include <geode/geode_globals.hpp>
-#include <ace/ACE.h>
-#include <ace/Time_Value.h>
-#include <ace/OS_NS_time.h>
-#include <ace/OS_NS_sys_time.h>
-#include <ace/Thread.h>
-#ifdef _X86_SOLARIS
-#include <ace/Thread.h>
-#include <sys/atomic.h>
-#endif
-#if defined(_MACOSX)
-#include <libkern/OSAtomic.h>
-#endif
-/**
- * @file
- */
-
-namespace apache {
-namespace geode {
-namespace client {
-
-
-#ifdef _SPARC_SOLARIS
-// implemented in hostsolaris.asm
-extern "C" {
-int32_t InterlockedExchangeAdd(volatile int32_t*, int32_t);
-// int64_t InterlockedExchangeAddLong(volatile int64_t *, int64_t);
-}
-#endif
-/*
-#ifdef _X86_SOLARIS
- extern "C" {
-typedef long LONG;
- int32_t InterlockedExchangeAdd(volatile int32_t *, int32_t);
-int32_t InterlockedCompareExchange(volatile LONG*, int32_t, int32_t);
-}
-#endif*/
-/**
- * hold static wrappers for spinlocks and atomic updates..
- */
-class CPPCACHE_EXPORT HostAsm {
- public:
-
-#if defined(_LINUX) || defined(_X86_SOLARIS)
- inline static int32_t InterlockedExchangeAdd(volatile int32_t* val,
- int32_t add) {
-#if defined(_LINUX)
- int32_t ret;
- __asm__ __volatile__("lock; xaddl %0, %1"
- : "=r"(ret), "=m"(*val)
- : "0"(add), "m"(*val));
-
- return (ret);
-#endif
-#if defined(_X86_SOLARIS)
- int32_t ret = *val;
- atomic_add_32((volatile uint32_t*)val, add);
- return ret + add;
-#endif
- }
-// _SOLARIS case is handled in hostsolaris.asm
-#endif
-
- // _SOLARIS case is handled in hostsolaris.asm
-
- /**
- * Name - atomicAdd
- * Purpose -
- * Add 'increment' to the counter pointed to be 'ctrPtr'.
- * Returns the value of the counter after the addition
- */
- inline static int32_t atomicAdd(volatile int32_t& counter, int32_t delta) {
-#ifdef _WIN32
- return InterlockedExchangeAdd((volatile LONG*)(&counter), delta) + delta;
-#endif
-
-#ifdef _X86_SOLARIS
- int32_t ret = counter;
- atomic_add_32((volatile uint32_t*)&counter, delta);
- return ret + delta;
-#endif
-
-#if defined(_LINUX) || defined(_SPARC_SOLARIS)
- return InterlockedExchangeAdd(&counter, delta) + delta;
-#endif
-
-#if defined(_MACOSX)
- return OSAtomicAdd32Barrier(delta, &counter);
-#endif
- }
-
- /**
- * Name - atomicAddPostfix
- * Purpose -
- * Add 'increment' to the counter pointed to be 'ctrPtr'.
- * Returns the value of the counter before the addition
- */
- inline static int32_t atomicAddPostfix(volatile int32_t& counter,
- int32_t delta) {
-#if defined(_WIN32)
- return InterlockedExchangeAdd((volatile LONG*)(&counter), delta);
-#elif defined(_X86_SOLARIS)
- int32_t ret = counter;
- atomic_add_32((volatile uint32_t*)(&counter), delta);
- return ret;
-#elif defined(_LINUX) || defined(_SPARC_SOLARIS)
- return InterlockedExchangeAdd(&counter, delta);
-#elif defined(_MACOSX)
- int32_t ret = counter;
- OSAtomicAdd32Barrier(delta, &counter);
- return ret;
-#else
-#error Port incomplete
-#endif
- }
-
- /**
- * Name - AtomicAnd
- * Atomically AND the mask value into the given address
- */
- static void atomicAnd(volatile uint32_t& ctrField, uint32_t mask);
-
- static uint32_t atomicCompareAndExchange(volatile uint32_t& oldValue,
- uint32_t newValue,
- uint32_t valueToCompare);
-
- /**
- * Name - AtomicOr
- * Atomically OR the mask value into the given address
- */
- static void atomicOr(volatile uint32_t& ctrField, uint32_t mask);
-
- /**
- * Atomically set masked bits to 1 in data.
- */
- inline static void atomicSetBits(volatile uint32_t& data, uint32_t mask) {
- return atomicOr(data, mask);
- }
-
- /**
- * Atomically set value of data to the given value.
- */
- static void atomicSet(volatile uint32_t& data, uint32_t newValue);
-
- /**
- * Atomically set masked bits to 0 in data.
- */
- inline static void atomicClearBits(volatile uint32_t& data, uint32_t mask) {
- return atomicAnd(data, ~mask);
- }
-
-};
-} // namespace client
-} // namespace geode
-} // namespace apache
-
-#ifdef __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
-#pragma clang diagnostic pop
-#endif
-
-#endif // GEODE_HOSTASM_H_
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/LRUEntriesMap.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/LRUEntriesMap.cpp b/src/cppcache/src/LRUEntriesMap.cpp
index b9e72a2..5ecefec 100644
--- a/src/cppcache/src/LRUEntriesMap.cpp
+++ b/src/cppcache/src/LRUEntriesMap.cpp
@@ -182,7 +182,7 @@ GfErrType LRUEntriesMap::evictionHelper() {
void LRUEntriesMap::processLRU(int32_t numEntriesToEvict) {
int32_t evicted = 0;
for (int32_t i = 0; i < numEntriesToEvict; i++) {
- if (m_validEntries.value() > 0 && static_cast<int32_t>(size()) > 0) {
+ if (m_validEntries > 0 && size() > 0) {
if (evictionHelper() == GF_NOERR) {
evicted++;
}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/LRUEntriesMap.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/LRUEntriesMap.hpp b/src/cppcache/src/LRUEntriesMap.hpp
index 7188c6a..498bd90 100644
--- a/src/cppcache/src/LRUEntriesMap.hpp
+++ b/src/cppcache/src/LRUEntriesMap.hpp
@@ -20,6 +20,7 @@
#ifndef GEODE_LRUENTRIESMAP_H_
#define GEODE_LRUENTRIESMAP_H_
+#include <atomic>
#include <geode/geode_globals.hpp>
#include <geode/Cache.hpp>
#include "ConcurrentEntriesMap.hpp"
@@ -68,7 +69,7 @@ class CPPCACHE_EXPORT LRUEntriesMap : public ConcurrentEntriesMap,
int64_t m_currentMapSize;
spinlock_mutex m_mapInfoLock;
std::string m_name;
- AtomicInc m_validEntries;
+ std::atomic<uint32_t> m_validEntries;
bool m_heapLRUEnabled;
public:
@@ -127,7 +128,7 @@ class CPPCACHE_EXPORT LRUEntriesMap : public ConcurrentEntriesMap,
}
}
- inline uint32_t validEntriesSize() const { return m_validEntries.value(); }
+ inline uint32_t validEntriesSize() const { return m_validEntries; }
inline void adjustLimit(uint32_t limit) { m_limit = limit; }
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/LRULocalDestroyAction.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/LRULocalDestroyAction.hpp b/src/cppcache/src/LRULocalDestroyAction.hpp
index c0337d0..a86bdf7 100644
--- a/src/cppcache/src/LRULocalDestroyAction.hpp
+++ b/src/cppcache/src/LRULocalDestroyAction.hpp
@@ -20,6 +20,7 @@
* limitations under the License.
*/
+#include <atomic>
#include <geode/geode_globals.hpp>
#include "LRUAction.hpp"
#include "RegionInternal.hpp"
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/MapEntry.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/MapEntry.hpp b/src/cppcache/src/MapEntry.hpp
index 23d3b51..52fb299 100644
--- a/src/cppcache/src/MapEntry.hpp
+++ b/src/cppcache/src/MapEntry.hpp
@@ -20,12 +20,14 @@
* limitations under the License.
*/
+#include <atomic>
+
#include <geode/geode_globals.hpp>
#include <geode/Cacheable.hpp>
#include <geode/CacheableKey.hpp>
#include <memory>
#include <geode/ExceptionTypes.hpp>
-#include "HostAsm.hpp"
+
#include "CacheImpl.hpp"
#include "ExpiryTaskManager.hpp"
#include "RegionInternal.hpp"
@@ -65,16 +67,16 @@ class CPPCACHE_EXPORT ExpEntryProperties {
// the costly gettimeofday call in MapSegment spinlock
inline void initStartTime() {
uint32_t currTime = static_cast<uint32_t>(ACE_OS::gettimeofday().sec());
- HostAsm::atomicSet(m_lastModifiedTime, currTime);
- HostAsm::atomicSet(m_lastAccessTime, currTime);
+ m_lastModifiedTime = currTime;
+ m_lastAccessTime = currTime;
}
inline void updateLastAccessTime(uint32_t currTime) {
- HostAsm::atomicSet(m_lastAccessTime, currTime);
+ m_lastAccessTime = currTime;
}
inline void updateLastModifiedTime(uint32_t currTime) {
- HostAsm::atomicSet(m_lastModifiedTime, currTime);
+ m_lastModifiedTime = currTime;
}
inline void setExpiryTaskId(long id) { m_expiryTaskId = id; }
@@ -93,9 +95,9 @@ class CPPCACHE_EXPORT ExpEntryProperties {
private:
/** last access time in secs, 32bit.. */
- volatile uint32_t m_lastAccessTime;
+ std::atomic<uint32_t> m_lastAccessTime;
/** last modified time in secs, 32bit.. */
- volatile uint32_t m_lastModifiedTime;
+ std::atomic<uint32_t> m_lastModifiedTime;
/** The expiry task id for this particular entry.. **/
long m_expiryTaskId;
};
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/MapSegment.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/MapSegment.cpp b/src/cppcache/src/MapSegment.cpp
index e3b39a6..efa5f92 100644
--- a/src/cppcache/src/MapSegment.cpp
+++ b/src/cppcache/src/MapSegment.cpp
@@ -42,7 +42,7 @@ MapSegment::~MapSegment() {
}
void MapSegment::open(RegionInternal* region, const EntryFactory* entryFactory,
- uint32_t size, volatile int* destroyTrackers,
+ uint32_t size, std::atomic<int32_t>* destroyTrackers,
bool concurrencyChecksEnabled) {
m_map = new CacheableKeyHashMap();
uint32_t mapSize = TableOfPrimes::nextLargerPrime(size, m_primeIndex);
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/MapSegment.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/MapSegment.hpp b/src/cppcache/src/MapSegment.hpp
index 495bc95..94609d6 100644
--- a/src/cppcache/src/MapSegment.hpp
+++ b/src/cppcache/src/MapSegment.hpp
@@ -92,7 +92,7 @@ class CPPCACHE_EXPORT MapSegment {
// number of operations that are tracking destroys
// the m_destroyedKeys contains the set for which destroys
// have been received as long as this number is greater than zero
- volatile int* m_numDestroyTrackers;
+ std::atomic<int32_t>* m_numDestroyTrackers;
MapOfUpdateCounters m_destroyedKeys;
uint32_t m_rehashCount;
@@ -217,7 +217,7 @@ class CPPCACHE_EXPORT MapSegment {
* Used when allocated in arrays by EntriesMap implementations.
*/
void open(RegionInternal* region, const EntryFactory* entryFactory,
- uint32_t size, volatile int* destroyTrackers,
+ uint32_t size, std::atomic<int32_t>* destroyTrackers,
bool concurrencyChecksEnabled);
void close();
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/TXId.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/TXId.cpp b/src/cppcache/src/TXId.cpp
index e300465..57703f7 100644
--- a/src/cppcache/src/TXId.cpp
+++ b/src/cppcache/src/TXId.cpp
@@ -27,7 +27,7 @@ namespace apache {
namespace geode {
namespace client {
-AtomicInc TXId::m_transactionId = 1;
+std::atomic<int32_t> TXId::m_transactionId(1);
TXId::TXId() : m_TXId(m_transactionId++) {}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/TXId.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/TXId.hpp b/src/cppcache/src/TXId.hpp
index de811b9..54aa2cc 100644
--- a/src/cppcache/src/TXId.hpp
+++ b/src/cppcache/src/TXId.hpp
@@ -29,7 +29,7 @@
#include <geode/geode_types.hpp>
#include <geode/TransactionId.hpp>
#include <geode/DataOutput.hpp>
-#include "AtomicInc.hpp"
+#include <atomic>
namespace apache {
namespace geode {
@@ -46,7 +46,7 @@ class TXId : public apache::geode::client::TransactionId {
private:
const int32_t m_TXId;
- static AtomicInc m_transactionId;
+ static std::atomic<int32_t> m_transactionId;
TXId& operator=(const TXId&);
TXId(const TXId&);
};
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/TcrConnection.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/TcrConnection.cpp b/src/cppcache/src/TcrConnection.cpp
index 1d018a6..f11db0c 100644
--- a/src/cppcache/src/TcrConnection.cpp
+++ b/src/cppcache/src/TcrConnection.cpp
@@ -1575,8 +1575,7 @@ bool TcrConnection::setAndGetBeingUsed(volatile bool isBeingUsed,
if (!forTransaction) {
if (isBeingUsed) {
if (m_isUsed == 1 || m_isUsed == 2) return false;
- retVal = HostAsm::atomicCompareAndExchange(m_isUsed, 1, currentValue);
- if (retVal == currentValue) return true;
+ if (m_isUsed.compare_exchange_strong(currentValue, 1)) return true;
return false;
} else {
m_isUsed = 0;
@@ -1590,9 +1589,8 @@ bool TcrConnection::setAndGetBeingUsed(volatile bool isBeingUsed,
if (m_isUsed == 2) { // transaction thread has set, reused it
return true;
}
- retVal = HostAsm::atomicCompareAndExchange(
- m_isUsed, 2 /*for transaction*/, currentValue);
- if (retVal == currentValue) return true;
+ if (m_isUsed.compare_exchange_strong(currentValue, 2 /*for transaction*/))
+ return true;
return false;
} else {
// m_isUsed = 0;//this will done by releasing the connection by
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/TcrConnection.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/TcrConnection.hpp b/src/cppcache/src/TcrConnection.hpp
index 547799c..9e8d873 100644
--- a/src/cppcache/src/TcrConnection.hpp
+++ b/src/cppcache/src/TcrConnection.hpp
@@ -20,6 +20,7 @@
* limitations under the License.
*/
+#include <atomic>
#include <ace/Semaphore.h>
#include <geode/geode_globals.hpp>
#include <geode/ExceptionTypes.hpp>
@@ -400,7 +401,7 @@ class CPPCACHE_EXPORT TcrConnection {
TcrConnection(const TcrConnection&);
TcrConnection& operator=(const TcrConnection&);
volatile bool m_isBeingUsed;
- volatile uint32_t m_isUsed;
+ std::atomic<uint32_t> m_isUsed;
ThinClientPoolDM* m_poolDM;
};
} // namespace client
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/TcrEndpoint.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/TcrEndpoint.hpp b/src/cppcache/src/TcrEndpoint.hpp
index 0dc6da5..117535b 100644
--- a/src/cppcache/src/TcrEndpoint.hpp
+++ b/src/cppcache/src/TcrEndpoint.hpp
@@ -23,6 +23,7 @@
#include <geode/geode_globals.hpp>
#include <string>
#include <list>
+#include <atomic>
#include <ace/Recursive_Thread_Mutex.h>
#include <ace/Semaphore.h>
#include <geode/geode_base.hpp>
@@ -173,9 +174,7 @@ class CPPCACHE_EXPORT TcrEndpoint {
int32_t numberOfTimesFailed() { return m_numberOfTimesFailed; }
- void addConnRefCounter(int count) {
- HostAsm::atomicAdd(m_noOfConnRefs, count);
- }
+ void addConnRefCounter(int count) { m_noOfConnRefs += count; }
int getConnRefCounter() { return m_noOfConnRefs; }
virtual uint16_t getDistributedMemberID() { return m_distributedMemId; }
@@ -256,7 +255,7 @@ class CPPCACHE_EXPORT TcrEndpoint {
TcrEndpoint(const TcrEndpoint&);
TcrEndpoint& operator=(const TcrEndpoint&);
// number of connections to this endpoint
- volatile int32_t m_noOfConnRefs;
+ std::atomic<int32_t> m_noOfConnRefs;
uint16_t m_distributedMemId;
protected:
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/TcrMessage.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/TcrMessage.hpp b/src/cppcache/src/TcrMessage.hpp
index 240a968..30e95e0 100644
--- a/src/cppcache/src/TcrMessage.hpp
+++ b/src/cppcache/src/TcrMessage.hpp
@@ -21,7 +21,7 @@
*/
#include <geode/geode_globals.hpp>
-#include "AtomicInc.hpp"
+#include <atomic>
#include <geode/Cacheable.hpp>
#include <geode/CacheableKey.hpp>
#include <geode/CacheableString.hpp>
@@ -513,7 +513,7 @@ class CPPCACHE_EXPORT TcrMessage {
SerializablePtr readCacheableBytes(DataInput& input, int lenObj);
SerializablePtr readCacheableString(DataInput& input, int lenObj);
- static AtomicInc m_transactionId;
+ static std::atomic<int32_t> m_transactionId;
static TcrMessagePing* m_pingMsg;
static TcrMessage* m_closeConnMsg;
static TcrMessage* m_allEPDisconnected;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/ThinClientPoolDM.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/ThinClientPoolDM.cpp b/src/cppcache/src/ThinClientPoolDM.cpp
index e13fb3f..8205ba6 100644
--- a/src/cppcache/src/ThinClientPoolDM.cpp
+++ b/src/cppcache/src/ThinClientPoolDM.cpp
@@ -478,7 +478,7 @@ void ThinClientPoolDM::cleanStaleConnections(volatile bool& isRunning) {
_nextIdle.sec() + 1);
}
- LOGDEBUG("Pool size is %d, pool counter is %d", size(), m_poolSize);
+ LOGDEBUG("Pool size is %d, pool counter is %d", size(), m_poolSize.load());
}
void ThinClientPoolDM::cleanStickyConnections(volatile bool& isRunning) {}
@@ -511,7 +511,7 @@ void ThinClientPoolDM::restoreMinConnections(volatile bool& isRunning) {
}
LOGDEBUG("Restored %d connections", restored);
- LOGDEBUG("Pool size is %d, pool counter is %d", size(), m_poolSize);
+ LOGDEBUG("Pool size is %d, pool counter is %d", size(), m_poolSize.load());
}
int ThinClientPoolDM::manageConnectionsInternal(volatile bool& isRunning) {
@@ -606,8 +606,7 @@ GfErrType ThinClientPoolDM::sendRequestToAllServers(
ResultCollectorPtr& rs, CacheableStringPtr& exceptionPtr) {
GfErrType err = GF_NOERR;
- HostAsm::atomicAdd(m_clientOps, 1);
- getStats().setCurClientOps(m_clientOps);
+ getStats().setCurClientOps(++m_clientOps);
auto resultCollectorLock = std::make_shared<ACE_Recursive_Thread_Mutex>();
@@ -679,8 +678,7 @@ GfErrType ThinClientPoolDM::sendRequestToAllServers(
rs->endResults();
}
- HostAsm::atomicAdd(m_clientOps, -1);
- getStats().setCurClientOps(m_clientOps);
+ getStats().setCurClientOps(--m_clientOps);
getStats().incSucceedClientOps();
delete[] fePtrList;
@@ -813,7 +811,7 @@ void ThinClientPoolDM::destroy(bool keepAlive) {
}
// closing all the thread local connections ( sticky).
LOGDEBUG("ThinClientPoolDM::destroy( ): closing FairQueue, pool size = %d",
- m_poolSize);
+ m_poolSize.load());
close();
LOGDEBUG("ThinClientPoolDM::destroy( ): after close ");
@@ -843,7 +841,7 @@ void ThinClientPoolDM::destroy(bool keepAlive) {
m_isDestroyed);
}
if (m_poolSize != 0) {
- LOGFINE("Pool connection size is not zero %d", m_poolSize);
+ LOGFINE("Pool connection size is not zero %d", m_poolSize.load());
}
}
@@ -1311,8 +1309,7 @@ GfErrType ThinClientPoolDM::sendSyncRequest(
LOGDEBUG("ThinClientPoolDM::sendSyncRequest: ....%d %s",
request.getMessageType(), m_poolName.c_str());
// Increment clientOps
- HostAsm::atomicAdd(m_clientOps, 1);
- getStats().setCurClientOps(m_clientOps);
+ getStats().setCurClientOps(++m_clientOps);
GfErrType error = GF_NOTCON;
@@ -1435,8 +1432,7 @@ GfErrType ThinClientPoolDM::sendSyncRequest(
// lets assume all connection are in use will happen
if (queueErr == GF_NOERR) {
queueErr = GF_ALL_CONNECTIONS_IN_USE_EXCEPTION;
- HostAsm::atomicAdd(m_clientOps, -1);
- getStats().setCurClientOps(m_clientOps);
+ getStats().setCurClientOps(--m_clientOps);
getStats().incFailedClientOps();
return queueErr;
} else if (queueErr == GF_IOERR) {
@@ -1563,8 +1559,7 @@ GfErrType ThinClientPoolDM::sendSyncRequest(
}
if (!attemptFailover || error == GF_NOERR) {
- HostAsm::atomicAdd(m_clientOps, -1);
- getStats().setCurClientOps(m_clientOps);
+ getStats().setCurClientOps(--m_clientOps);
if (error == GF_NOERR) {
getStats().incSucceedClientOps(); /*inc Id for clientOs stat*/
} else if (error == GF_TIMOUT) {
@@ -1583,8 +1578,7 @@ GfErrType ThinClientPoolDM::sendSyncRequest(
firstTry = false;
} // While
- HostAsm::atomicAdd(m_clientOps, -1);
- getStats().setCurClientOps(m_clientOps);
+ getStats().setCurClientOps(--m_clientOps);
if (error == GF_NOERR) {
getStats().incSucceedClientOps();
@@ -1715,7 +1709,7 @@ GfErrType ThinClientPoolDM::createPoolConnectionToAEndPoint(
LOGFINER(
"ThinClientPoolDM::createPoolConnectionToAEndPoint( ): current pool "
"size has reached limit %d, %d",
- m_poolSize, max);
+ m_poolSize.load(), max);
return error;
}
}
@@ -1748,10 +1742,10 @@ GfErrType ThinClientPoolDM::createPoolConnectionToAEndPoint(
}
void ThinClientPoolDM::reducePoolSize(int num) {
- LOGFINE("removing connection %d , pool-size =%d", num, m_poolSize);
- HostAsm::atomicAdd(m_poolSize, -1 * num);
- if (m_poolSize == 0) {
- if (m_cliCallbackTask != nullptr) m_cliCallbackSema.release();
+ LOGFINE("removing connection %d , pool-size =%d", num, m_poolSize.load());
+ m_poolSize -= num;
+ if (m_poolSize <= 0) {
+ if (m_cliCallbackTask != NULL) m_cliCallbackSema.release();
}
}
GfErrType ThinClientPoolDM::createPoolConnection(
@@ -1768,7 +1762,7 @@ GfErrType ThinClientPoolDM::createPoolConnection(
LOGDEBUG(
"ThinClientPoolDM::createPoolConnection( ): current pool size has "
"reached limit %d, %d, %d",
- m_poolSize, max, min);
+ m_poolSize.load(), max, min);
conn = nullptr;
{
@@ -1776,7 +1770,7 @@ GfErrType ThinClientPoolDM::createPoolConnection(
LOGDEBUG(
"ThinClientPoolDM::createPoolConnection( ): current pool size has "
"reached limit %d, %d",
- m_poolSize, max);
+ m_poolSize.load(), max);
maxConnLimit = true;
return error;
}
@@ -1831,8 +1825,7 @@ GfErrType ThinClientPoolDM::createPoolConnection(
}
} else {
ep->setConnected();
- ++m_poolSize; // already increased
- if (m_poolSize > min) {
+ if (++m_poolSize > min) {
getStats().incLoadCondConnects();
}
// Update Stats
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/ThinClientPoolDM.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/ThinClientPoolDM.hpp b/src/cppcache/src/ThinClientPoolDM.hpp
index cc5d41e..73802f7 100644
--- a/src/cppcache/src/ThinClientPoolDM.hpp
+++ b/src/cppcache/src/ThinClientPoolDM.hpp
@@ -399,7 +399,7 @@ class ThinClientPoolDM
volatile ThinClientLocatorHelper* m_locHelper;
- volatile int32_t m_poolSize; // Actual Size of Pool
+ std::atomic<int32_t> m_poolSize; // Actual Size of Pool
int m_numRegions;
// for selectEndpoint
@@ -421,7 +421,7 @@ class ThinClientPoolDM
int manageConnectionsInternal(volatile bool& isRunning);
void cleanStaleConnections(volatile bool& isRunning);
void restoreMinConnections(volatile bool& isRunning);
- volatile int32_t m_clientOps; // Actual Size of Pool
+ std::atomic<int32_t> m_clientOps; // Actual Size of Pool
statistics::PoolStatsSampler* m_PoolStatsSampler;
ClientMetadataService* m_clientMetadataService;
friend class CacheImpl;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/hostsolaris.asm
----------------------------------------------------------------------
diff --git a/src/cppcache/src/hostsolaris.asm b/src/cppcache/src/hostsolaris.asm
deleted file mode 100644
index 7a12bde..0000000
--- a/src/cppcache/src/hostsolaris.asm
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*========================================================================
- *
- * Name - InterlockedCompareExchange --
- *
- * Purpose -
- * The function returns the initial value of the Destination parameter.
- * The function compares the Destination value with the Comparand value.
- * If the Destination value is equal to the Comparand value, the Exchange
- * value is stored in the address specified by Destination.
- * Otherwise, no operation is performed.
- *
- * membar not used
- *
- *========================================================================
- */
- .seg "text"
- .proc 12
- .global InterlockedCompareExchange
- .type InterlockedCompareExchange, #function
-InterlockedCompareExchange:
-
- cas [%o0],%o2,%o1 ! /* atomic CAS, with read value -> retval */
- retl
- mov %o1,%o0 ! /* retval = 1 IFF tmp == 0 */
-
-/*========================================================================
- *
- * Name - InterlockedExchangeAdd -- Gemfire name was HostAsmAtomicAdd
- *
- * Purpose -
- * Add 'increment' to the counter pointed to be 'ctrPtr'.
- * Returns the old value.
- *
- * membar not used
- *
- *========================================================================
- */
- .proc 12
- .global InterlockedExchangeAdd
- .type InterlockedExchangeAdd, #function
-InterlockedExchangeAdd:
- ! %o0 = ctrPtr
- ! %o1 = increment
-retryAdd: ! do {
- ld [%o0],%o2 ! %o2 = *ctrPtr
- add %o2,%o1,%o3 ! %o3 = %o2 + increment
- cas [%o0],%o2,%o3 ! if (%o2 == *ctrPtr)
- ! tmp = *ctrPtr, *ctrPtr = %o3, %o3 = tmp
- ! else
- ! %o3 = *ctrPtr
- cmp %o2,%o3 !
- bne retryAdd ! } while (%o2 != %o3)
- nop ! fix for bug 22851
- retl
- mov %o3,%o0 ! return old value of *ctrPtr in %o0
-
-/*========================================================================
- *
- * Name - InterlockedExchangeAddLong -- Gemfire name was HostAsmAtomicAddLong
- *
- * Purpose -
- * Handels 64 bit Pointer for v9 architecture
- * Add 'increment' to the counter pointed to be 'ctrPtr'.
- * Returns the old value.
- *
- * membar not used
- *
- *========================================================================
- */
- .proc 12
- .global InterlockedExchangeAddLong
- .type InterlockedExchangeAddLong, #function
-InterlockedExchangeAddLong:
- ! %o0 = ctrPtr
- ! %o1 = increment
-retryAddLong: ! do {
- ldx [%o0],%o2 ! %o2 = *ctrPtr
- add %o2,%o1,%o3 ! %o3 = %o2 + increment
- casx [%o0],%o2,%o3 ! if (%o2 == *ctrPtr)
- ! tmp = *ctrPtr, *ctrPtr = %o3, %o3 = tmp
- ! else
- ! %o3 = *ctrPtr
- cmp %o2,%o3 !
- bne retryAddLong ! } while (%o2 != %o3)
- nop ! fix for bug 22851
- retl
- mov %o3,%o0 ! return old value of *ctrPtr in %o0
-
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/statistics/AtomicStatisticsImpl.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/AtomicStatisticsImpl.cpp b/src/cppcache/src/statistics/AtomicStatisticsImpl.cpp
index 710b584..3a6e28c 100644
--- a/src/cppcache/src/statistics/AtomicStatisticsImpl.cpp
+++ b/src/cppcache/src/statistics/AtomicStatisticsImpl.cpp
@@ -17,14 +17,16 @@
#include <geode/geode_globals.hpp>
-#include <ace/Atomic_Op_T.h>
-#include <ace/Recursive_Thread_Mutex.h>
+#include <atomic>
+
#include <ace/OS_NS_stdio.h>
#include "AtomicStatisticsImpl.hpp"
#include "StatisticsTypeImpl.hpp"
#include "StatisticDescriptorImpl.hpp"
-using namespace apache::geode::statistics;
+namespace apache {
+namespace geode {
+namespace statistics {
/**
* An implementation of {@link Statistics} that stores its statistics
* in local memory and supports atomic operations.
@@ -94,8 +96,7 @@ AtomicStatisticsImpl::AtomicStatisticsImpl(StatisticsType* typeArg,
int32_t doubleCount = statsType->getDoubleStatCount();
if (intCount > 0) {
- intStorage =
- new ACE_Atomic_Op<ACE_Recursive_Thread_Mutex, int32_t>[intCount];
+ intStorage = new std::atomic<int32_t>[ intCount ];
for (int32_t i = 0; i < intCount; i++) {
intStorage[i] = 0; // Un-initialized state
}
@@ -104,8 +105,7 @@ AtomicStatisticsImpl::AtomicStatisticsImpl(StatisticsType* typeArg,
intStorage = nullptr;
}
if (longCount > 0) {
- longStorage =
- new ACE_Atomic_Op<ACE_Recursive_Thread_Mutex, int64_t>[longCount];
+ longStorage = new std::atomic<int64_t>[ longCount ];
for (int32_t i = 0; i < longCount; i++) {
longStorage[i] = 0; // Un-initialized state
}
@@ -114,8 +114,7 @@ AtomicStatisticsImpl::AtomicStatisticsImpl(StatisticsType* typeArg,
longStorage = nullptr;
}
if (doubleCount > 0) {
- doubleStorage =
- new ACE_Atomic_Op<ACE_Recursive_Thread_Mutex, double>[doubleCount];
+ doubleStorage = new std::atomic<double>[ doubleCount ];
for (int32_t i = 0; i < doubleCount; i++) {
doubleStorage[i] = 0; // Un-initialized state
}
@@ -210,7 +209,7 @@ int32_t AtomicStatisticsImpl::_getInt(int32_t offset) {
throw IllegalArgumentException(s);
}
- return intStorage[offset].value();
+ return intStorage[offset];
}
int64_t AtomicStatisticsImpl::_getLong(int32_t offset) {
@@ -221,7 +220,7 @@ int64_t AtomicStatisticsImpl::_getLong(int32_t offset) {
offset);
throw IllegalArgumentException(s);
}
- return longStorage[offset].value();
+ return longStorage[offset];
}
double AtomicStatisticsImpl::_getDouble(int32_t offset) {
@@ -233,7 +232,7 @@ double AtomicStatisticsImpl::_getDouble(int32_t offset) {
offset);
throw IllegalArgumentException(s);
}
- return doubleStorage[offset].value();
+ return doubleStorage[offset];
}
int64_t AtomicStatisticsImpl::_getRawBits(StatisticDescriptor* statDscp) {
@@ -319,7 +318,13 @@ double AtomicStatisticsImpl::_incDouble(int32_t offset, double delta) {
throw IllegalArgumentException(s);
}
- return (doubleStorage[offset] += delta);
+ double expected = doubleStorage[offset];
+ double value;
+ do {
+ value = expected + delta;
+ } while (!doubleStorage[offset].compare_exchange_weak(expected, value));
+
+ return value;
}
/**************************Base class methods ********************/
@@ -533,3 +538,7 @@ int32_t AtomicStatisticsImpl::getDoubleId(StatisticDescriptor* descriptor) {
dynamic_cast<StatisticDescriptorImpl*>(descriptor);
return realDescriptor->checkDouble();
}
+
+} // namespace statistics
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/statistics/AtomicStatisticsImpl.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/AtomicStatisticsImpl.hpp b/src/cppcache/src/statistics/AtomicStatisticsImpl.hpp
index 93a1a9c..755be18 100644
--- a/src/cppcache/src/statistics/AtomicStatisticsImpl.hpp
+++ b/src/cppcache/src/statistics/AtomicStatisticsImpl.hpp
@@ -21,9 +21,9 @@
*/
#include <geode/geode_globals.hpp>
-#include <ace/Atomic_Op_T.h>
-#include <ace/Recursive_Thread_Mutex.h>
-#include <HostAsm.hpp>
+
+#include <atomic>
+
#include <geode/statistics/Statistics.hpp>
#include "StatisticsTypeImpl.hpp"
#include <geode/statistics/StatisticsFactory.hpp>
@@ -67,13 +67,13 @@ class AtomicStatisticsImpl : public Statistics, private NonCopyable {
/****************************************************************************/
/** An array containing the values of the int32_t statistics */
- ACE_Atomic_Op<ACE_Recursive_Thread_Mutex, int32_t>* intStorage;
+ std::atomic<int32_t>* intStorage;
/** An array containing the values of the int64_t statistics */
- ACE_Atomic_Op<ACE_Recursive_Thread_Mutex, int64_t>* longStorage;
+ std::atomic<int64_t>* longStorage;
/** An array containing the values of the double statistics */
- ACE_Atomic_Op<ACE_Recursive_Thread_Mutex, double>* doubleStorage;
+ std::atomic<double>* doubleStorage;
///////////////////////Private Methods//////////////////////////
bool isOpen();
@@ -230,7 +230,7 @@ class AtomicStatisticsImpl : public Statistics, private NonCopyable {
}; // class
-} // namespace client
+} // namespace statistics
} // namespace geode
} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/statistics/HostStatHelper.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/HostStatHelper.cpp b/src/cppcache/src/statistics/HostStatHelper.cpp
index 4767ce5..d2a330f 100644
--- a/src/cppcache/src/statistics/HostStatHelper.cpp
+++ b/src/cppcache/src/statistics/HostStatHelper.cpp
@@ -16,7 +16,7 @@
*/
#include <geode/geode_globals.hpp>
-
+#include "config.h"
#include <ace/OS_NS_sys_utsname.h>
#include "HostStatHelper.hpp"
#include "GeodeStatisticsFactory.hpp"
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/cppcache/src/statistics/StatisticsManager.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatisticsManager.cpp b/src/cppcache/src/statistics/StatisticsManager.cpp
index daab20a..bc81a33 100644
--- a/src/cppcache/src/statistics/StatisticsManager.cpp
+++ b/src/cppcache/src/statistics/StatisticsManager.cpp
@@ -18,8 +18,6 @@
#include <geode/geode_globals.hpp>
-#include <ace/Atomic_Op_T.h>
-#include <ace/Recursive_Thread_Mutex.h>
#include <ace/OS.h>
#include <ace/Thread_Mutex.h>
#include <ace/Time_Value.h>
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/tests/cpp/fwklib/ClientTask.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/ClientTask.hpp b/src/tests/cpp/fwklib/ClientTask.hpp
index 77ac203..2c6a032 100644
--- a/src/tests/cpp/fwklib/ClientTask.hpp
+++ b/src/tests/cpp/fwklib/ClientTask.hpp
@@ -21,7 +21,7 @@
*/
#include <geode/GeodeCppCache.hpp>
-#include <AtomicInc.hpp>
+#include <atomic>
#include "fwklib/PerfFwk.hpp"
#include "fwklib/FwkObjects.hpp"
@@ -34,9 +34,9 @@ namespace testframework {
class ClientTask {
private:
- AtomicInc m_TotalIters;
- AtomicInc m_passCount;
- AtomicInc m_failCount;
+ std::atomic<int32_t> m_TotalIters;
+ std::atomic<int32_t> m_passCount;
+ std::atomic<int32_t> m_failCount;
protected:
bool m_Exit;
@@ -55,13 +55,13 @@ class ClientTask {
m_Run = true;
m_Iterations = 0;
m_Loop = -1;
- m_TotalIters.resetValue(0);
+ m_TotalIters = 0;
}
void passed() { m_passCount++; }
void failed() { m_failCount++; }
- int32_t getPassCount() { return m_passCount.value(); }
- int32_t getFailCount() { return m_failCount.value(); }
+ int32_t getPassCount() { return m_passCount; }
+ int32_t getFailCount() { return m_failCount; }
// Defined by subclasses to implement the task functionality.
// The id parameter is intended to be the thread id,
@@ -92,12 +92,12 @@ class ClientTask {
void addIters(int32_t iters) { m_TotalIters += iters; }
// Get total iterations.
- int32_t getIters() { return m_TotalIters.value(); }
+ int32_t getIters() { return m_TotalIters; }
// Set the number of iterations the test should do.
void setIterations(int32_t iterations) {
m_Iterations = iterations;
- m_TotalIters = AtomicInc();
+ m_TotalIters = 0;
}
// Used to terminate tasks being run by threads
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/tests/cpp/fwklib/PerfFwk.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/PerfFwk.hpp b/src/tests/cpp/fwklib/PerfFwk.hpp
index 4f8c97f..346bcbb 100644
--- a/src/tests/cpp/fwklib/PerfFwk.hpp
+++ b/src/tests/cpp/fwklib/PerfFwk.hpp
@@ -25,7 +25,6 @@
#include <string>
#include <map>
-#include "AtomicInc.hpp"
#include <geode/DataOutput.hpp>
#include <geode/DataInput.hpp>
#include "FwkException.hpp"
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/tests/cpp/fwklib/PoolHelper.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/PoolHelper.hpp b/src/tests/cpp/fwklib/PoolHelper.hpp
index 17ef93e..2d7d1a4 100644
--- a/src/tests/cpp/fwklib/PoolHelper.hpp
+++ b/src/tests/cpp/fwklib/PoolHelper.hpp
@@ -21,7 +21,7 @@
*/
#include <geode/GeodeCppCache.hpp>
-#include <AtomicInc.hpp>
+
#include "fwklib/FrameworkTest.hpp"
#include "fwklib/FwkObjects.hpp"
#include "fwklib/FwkStrCvt.hpp"
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/tests/cpp/fwklib/RegionHelper.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/RegionHelper.hpp b/src/tests/cpp/fwklib/RegionHelper.hpp
index f0c08fb..451d228 100644
--- a/src/tests/cpp/fwklib/RegionHelper.hpp
+++ b/src/tests/cpp/fwklib/RegionHelper.hpp
@@ -21,7 +21,7 @@
*/
#include <geode/GeodeCppCache.hpp>
-#include <AtomicInc.hpp>
+
#include "fwklib/FrameworkTest.hpp"
#include "fwklib/FwkObjects.hpp"
#include "fwklib/FwkStrCvt.hpp"
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/tests/cpp/fwklib/Service.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/Service.cpp b/src/tests/cpp/fwklib/Service.cpp
index ded804d..d338137 100644
--- a/src/tests/cpp/fwklib/Service.cpp
+++ b/src/tests/cpp/fwklib/Service.cpp
@@ -31,7 +31,7 @@ Service::Service(int32_t threadCnt)
flags |= THR_INHERIT_SCHED;
#endif
- m_busy.resetValue(0);
+ m_busy = 0;
activate(flags, threadCnt, forceActive);
}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/tests/cpp/fwklib/Service.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/Service.hpp b/src/tests/cpp/fwklib/Service.hpp
index d803d29..859533a 100644
--- a/src/tests/cpp/fwklib/Service.hpp
+++ b/src/tests/cpp/fwklib/Service.hpp
@@ -21,7 +21,7 @@
*/
#include <geode/geode_base.hpp>
-#include <AtomicInc.hpp>
+#include <atomic>
#include "fwklib/FwkLog.hpp"
#include "ace/Task.h"
@@ -64,7 +64,7 @@ class Service : public ACE_Task_Base {
private:
uint32_t m_ThreadCount;
volatile bool m_run;
- AtomicInc m_busy;
+ std::atomic<uint32_t> m_busy;
ACE_Thread_Mutex m_Mutex;
ACE_DLList<ServiceTask> m_TaskQueue;
@@ -88,12 +88,8 @@ class Service : public ACE_Task_Base {
int32_t runThreaded(ServiceTask* task, uint32_t threads);
- inline uint32_t getBusyCount() {
- return static_cast<uint32_t>(m_busy.value());
- }
- inline uint32_t getIdleCount() {
- return m_ThreadCount - static_cast<uint32_t>(m_busy.value());
- }
+ inline uint32_t getBusyCount() { return m_busy; }
+ inline uint32_t getIdleCount() { return m_ThreadCount - m_busy; }
inline void stopThreads() {
m_run = false;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/0cc06f02/src/tests/cpp/fwklib/UDPIpc.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/UDPIpc.hpp b/src/tests/cpp/fwklib/UDPIpc.hpp
index 64c9500..68b9ad9 100644
--- a/src/tests/cpp/fwklib/UDPIpc.hpp
+++ b/src/tests/cpp/fwklib/UDPIpc.hpp
@@ -32,6 +32,7 @@
#include <ace/SOCK_Dgram.h>
#include <ace/TSS_T.h>
+#include <atomic>
#include <string>
#include <list>
@@ -150,9 +151,9 @@ class UDPMessageClient {
class UDPMessageQueues : public SharedTaskObject {
private:
- AtomicInc m_cntInbound;
- AtomicInc m_cntOutbound;
- AtomicInc m_cntProcessed;
+ std::atomic<int32_t> m_cntInbound;
+ std::atomic<int32_t> m_cntOutbound;
+ std::atomic<int32_t> m_cntProcessed;
SafeQueue<UDPMessage> m_inbound;
SafeQueue<UDPMessage> m_outbound;
@@ -162,12 +163,9 @@ class UDPMessageQueues : public SharedTaskObject {
public:
UDPMessageQueues(std::string label) : m_label(label) {}
~UDPMessageQueues() {
- FWKINFO(m_label << "MessageQueues::Inbound count: "
- << m_cntInbound.value());
- FWKINFO(m_label << "MessageQueues::Processed count: "
- << m_cntProcessed.value());
- FWKINFO(m_label << "MessageQueues::Outbound count: "
- << m_cntOutbound.value());
+ FWKINFO(m_label << "MessageQueues::Inbound count: " << m_cntInbound);
+ FWKINFO(m_label << "MessageQueues::Processed count: " << m_cntProcessed);
+ FWKINFO(m_label << "MessageQueues::Outbound count: " << m_cntOutbound);
FWKINFO(m_label << "MessageQueues::Inbound still queued: "
<< m_inbound.size());
FWKINFO(m_label << "MessageQueues::Outbound still queued: "
@@ -201,7 +199,7 @@ class Receiver : public ServiceTask {
ACE_TSS<ACE_SOCK_Dgram> m_io;
int32_t m_basePort;
ACE_thread_t m_listener;
- AtomicInc m_offset;
+ std::atomic<int32_t> m_offset;
std::list<std::string> m_addrs;
UDPMessageQueues* m_queues;
ACE_Thread_Mutex m_mutex;
@@ -275,7 +273,7 @@ class Responder : public ServiceTask {
private:
ACE_TSS<ACE_SOCK_Dgram> m_io;
int32_t m_basePort;
- AtomicInc m_offset;
+ std::atomic<int32_t> m_offset;
UDPMessageQueues* m_queues;
public:
[2/5] geode-native git commit: GEODE-2494: Replace SpinLock with
spinlock_mutex.
Posted by jb...@apache.org.
GEODE-2494: Replace SpinLock with spinlock_mutex.
- Replace some spin lock protected values with atomic.
- 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/3305de70
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/3305de70
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/3305de70
Branch: refs/heads/develop
Commit: 3305de7073aaf4e579ce9e2e22c8f256f145f51b
Parents: b1a9af5
Author: Jacob Barrett <jb...@pivotal.io>
Authored: Wed Feb 22 21:29:49 2017 -0800
Committer: Ernie Burghardt <eb...@pivotal.io>
Committed: Thu Jun 22 13:33:00 2017 -0700
----------------------------------------------------------------------
src/cppcache/integration-test/testSpinLock.cpp | 46 ++--
src/cppcache/src/CacheImpl.hpp | 1 -
src/cppcache/src/CqQueryVsdStats.cpp | 54 ++--
src/cppcache/src/CqQueryVsdStats.hpp | 24 +-
src/cppcache/src/CqServiceVsdStats.cpp | 55 ++--
src/cppcache/src/CqServiceVsdStats.hpp | 21 +-
src/cppcache/src/EventId.cpp | 35 ++-
src/cppcache/src/EventId.hpp | 1 -
src/cppcache/src/HostAsm.cpp | 2 -
src/cppcache/src/HostAsm.hpp | 252 -------------------
src/cppcache/src/LRUEntriesMap.cpp | 15 +-
src/cppcache/src/LRUEntriesMap.hpp | 15 +-
src/cppcache/src/LRUList.cpp | 24 +-
src/cppcache/src/LRUList.hpp | 30 +--
src/cppcache/src/LocalRegion.hpp | 1 -
src/cppcache/src/MapSegment.cpp | 70 +++---
src/cppcache/src/MapSegment.hpp | 10 +-
src/cppcache/src/PoolStatistics.cpp | 23 +-
src/cppcache/src/PoolStatistics.hpp | 29 ++-
src/cppcache/src/RegionStats.cpp | 53 +++-
src/cppcache/src/RegionStats.hpp | 24 +-
src/cppcache/src/SerializationRegistry.cpp | 51 ++--
src/cppcache/src/SerializationRegistry.hpp | 2 +-
src/cppcache/src/SpinLock.cpp | 37 ---
src/cppcache/src/SpinLock.hpp | 122 ---------
src/cppcache/src/TcrEndpoint.hpp | 1 -
src/cppcache/src/hostsolaris.asm | 83 ------
.../src/util/concurrent/spinlock_mutex.hpp | 51 ++++
src/tests/cpp/fwk/UdpIpc.cpp | 17 +-
src/tests/cpp/fwklib/FrameworkTest.cpp | 28 ++-
src/tests/cpp/fwklib/FrameworkTest.hpp | 6 +-
src/tests/cpp/fwklib/GsRandom.cpp | 22 +-
src/tests/cpp/fwklib/GsRandom.hpp | 6 +-
src/tests/cpp/fwklib/MersenneTwister.cpp | 7 +-
src/tests/cpp/fwklib/MersenneTwister.hpp | 4 +-
src/tests/cpp/security/Security.cpp | 47 ++--
src/tests/cpp/security/Security.hpp | 2 +-
37 files changed, 458 insertions(+), 813 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/integration-test/testSpinLock.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/testSpinLock.cpp b/src/cppcache/integration-test/testSpinLock.cpp
index cfaa810..7c13441 100644
--- a/src/cppcache/integration-test/testSpinLock.cpp
+++ b/src/cppcache/integration-test/testSpinLock.cpp
@@ -20,28 +20,23 @@
#include "fw_dunit.hpp"
#include <geode/GeodeCppCache.hpp>
+#include <mutex>
+#include <util/concurrent/spinlock_mutex.hpp>
+
#include <Condition.hpp>
#include <ace/Task.h>
#include <ace/Time_Value.h>
#include <ace/Guard_T.h>
-namespace apache {
-namespace geode {
-namespace client {
+namespace {
-CPPCACHE_EXPORT void* testSpinLockCreate();
-CPPCACHE_EXPORT void testSpinLockAcquire(void* lock);
-CPPCACHE_EXPORT void testSpinLockRelease(void* lock);
-} // namespace client
-} // namespace geode
-} // namespace apache
+using apache::geode::util::concurrent::spinlock_mutex;
DUNIT_TASK(s1p1, Basic)
{
- void* lock = apache::geode::client::testSpinLockCreate();
- apache::geode::client::testSpinLockAcquire(lock);
- apache::geode::client::testSpinLockRelease(lock);
+ spinlock_mutex s;
+ { std::lock_guard<spinlock_mutex> lk(s); }
}
END_TASK(Basic)
@@ -49,7 +44,7 @@ perf::Semaphore* triggerA;
perf::Semaphore* triggerB;
perf::Semaphore* triggerM;
-void* lock;
+spinlock_mutex lock;
ACE_Time_Value* btime;
class ThreadA : public ACE_Task_Base {
@@ -57,11 +52,12 @@ class ThreadA : public ACE_Task_Base {
ThreadA() : ACE_Task_Base() {}
int svc() {
- apache::geode::client::testSpinLockAcquire(lock);
- LOG("ThreadA: Acquired lock x.");
- triggerM->release();
- triggerA->acquire();
- apache::geode::client::testSpinLockRelease(lock);
+ {
+ std::lock_guard<spinlock_mutex> lk(lock);
+ LOG("ThreadA: Acquired lock x.");
+ triggerM->release();
+ triggerA->acquire();
+ }
LOG("ThreadA: Released lock.");
return 0;
}
@@ -73,11 +69,12 @@ class ThreadB : public ACE_Task_Base {
int svc() {
triggerB->acquire();
- apache::geode::client::testSpinLockAcquire(lock);
- btime = new ACE_Time_Value(ACE_OS::gettimeofday());
- LOG("ThreadB: Acquired lock.");
- triggerM->release();
- apache::geode::client::testSpinLockRelease(lock); // for cleanly ness.
+ {
+ std::lock_guard<spinlock_mutex> lk(lock);
+ btime = new ACE_Time_Value(ACE_OS::gettimeofday());
+ LOG("ThreadB: Acquired lock.");
+ triggerM->release();
+ }
return 0;
}
};
@@ -88,8 +85,6 @@ DUNIT_TASK(s1p1, TwoThreads)
triggerB = new perf::Semaphore(0);
triggerM = new perf::Semaphore(0);
- lock = apache::geode::client::testSpinLockCreate();
-
ThreadA* threadA = new ThreadA();
ThreadB* threadB = new ThreadB();
@@ -159,3 +154,4 @@ DUNIT_TASK(s1p1, Cond)
XASSERT(delta.msec() >= (delay.msec() - 50));
}
ENDTASK
+} // namespace
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/CacheImpl.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/CacheImpl.hpp b/src/cppcache/src/CacheImpl.hpp
index 540d32c..6de340e 100644
--- a/src/cppcache/src/CacheImpl.hpp
+++ b/src/cppcache/src/CacheImpl.hpp
@@ -27,7 +27,6 @@
#include <geode/CacheAttributes.hpp>
#include <geode/DistributedSystem.hpp>
#include "MapWithLock.hpp"
-#include "SpinLock.hpp"
#include <ace/ACE.h>
#include <ace/Condition_Recursive_Thread_Mutex.h>
#include <ace/Time_Value.h>
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/CqQueryVsdStats.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/CqQueryVsdStats.cpp b/src/cppcache/src/CqQueryVsdStats.cpp
index c666720..ceb40a6 100644
--- a/src/cppcache/src/CqQueryVsdStats.cpp
+++ b/src/cppcache/src/CqQueryVsdStats.cpp
@@ -20,11 +20,14 @@
#include "CqQueryVsdStats.hpp"
//#include "StatisticsFactory.hpp"
-#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,25 +35,17 @@ 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 = nullptr;
-SpinLock CqQueryStatType::m_singletonLock;
-SpinLock CqQueryStatType::m_statTypeLock;
-
-void CqQueryStatType::clean() {
- SpinLockGuard guard(m_singletonLock);
- if (single != nullptr) {
- delete single;
- single = nullptr;
- }
-}
+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);
@@ -81,19 +76,14 @@ StatisticsType* CqQueryStatType::getStatType() {
return statsType;
}
-CqQueryStatType* CqQueryStatType::getInstance() {
- SpinLockGuard guard(m_singletonLock);
- if (single == nullptr) {
- 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,9 +98,9 @@ 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 != nullptr);
@@ -119,10 +109,10 @@ CqQueryVsdStats::CqQueryVsdStats(const char* cqqueryName) {
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);
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/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/3305de70/src/cppcache/src/CqServiceVsdStats.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/CqServiceVsdStats.cpp b/src/cppcache/src/CqServiceVsdStats.cpp
index fd6e1d5..08f331b 100644
--- a/src/cppcache/src/CqServiceVsdStats.cpp
+++ b/src/cppcache/src/CqServiceVsdStats.cpp
@@ -20,11 +20,14 @@
#include "CqServiceVsdStats.hpp"
//#include "StatisticsFactory.hpp"
-#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,25 +35,17 @@ 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 = nullptr;
-SpinLock CqServiceStatType::m_singletonLock;
-SpinLock CqServiceStatType::m_statTypeLock;
-
-void CqServiceStatType::clean() {
- SpinLockGuard guard(m_singletonLock);
- if (single != nullptr) {
- delete single;
- single = nullptr;
- }
-}
+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);
@@ -87,19 +82,13 @@ StatisticsType* CqServiceStatType::getStatType() {
return statsType;
}
-CqServiceStatType* CqServiceStatType::getInstance() {
- SpinLockGuard guard(m_singletonLock);
- if (single == nullptr) {
- 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,9 +104,9 @@ 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 != nullptr);
@@ -126,11 +115,11 @@ CqServiceVsdStats::CqServiceVsdStats(const char* cqServiceName) {
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);
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/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;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/EventId.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/EventId.cpp b/src/cppcache/src/EventId.cpp
index a987b76..6f944a6 100644
--- a/src/cppcache/src/EventId.cpp
+++ b/src/cppcache/src/EventId.cpp
@@ -18,31 +18,29 @@
#include "EventId.hpp"
#include "GeodeTypeIdsImpl.hpp"
#include "ClientProxyMembershipID.hpp"
-#include <ace/TSS_T.h>
-#include <ace/OS.h>
-#include <ace/INET_Addr.h>
+#include <cstring>
+#include <atomic>
namespace apache {
namespace geode {
namespace client {
-// to be used only with ACE_TSS<> or WinTSS<>
class EventIdTSS {
private:
- static SpinLock s_eidThrIdLock;
- static int64_t s_eidThrId;
+ static std::atomic<int64_t> s_eidThrId;
int64_t m_eidThrTSS;
int64_t m_eidSeqTSS;
+ ~EventIdTSS() = default;
+ EventIdTSS(const EventIdTSS&) = delete;
+ EventIdTSS& operator=(const EventIdTSS&) = delete;
+
public:
// this should get called just once per thread due to first access to TSS
EventIdTSS() {
- {
- SpinLockGuard _guard(s_eidThrIdLock);
- m_eidThrTSS = ++s_eidThrId;
- }
+ m_eidThrTSS = ++s_eidThrId;
m_eidSeqTSS = 0;
}
@@ -52,13 +50,12 @@ class EventIdTSS {
inline int64_t getSeqNum() { return m_eidSeqTSS - 1; }
- static ACE_TSS<EventIdTSS> s_eventId;
+ static thread_local EventIdTSS s_eventId;
}; // class EventIdTSS
-SpinLock EventIdTSS::s_eidThrIdLock;
-int64_t EventIdTSS::s_eidThrId = 0;
-ACE_TSS<EventIdTSS> EventIdTSS::s_eventId;
+std::atomic<int64_t> EventIdTSS::s_eidThrId;
+thread_local EventIdTSS EventIdTSS::s_eventId;
void EventId::toData(DataOutput& output) const {
// This method is always expected to write out nonstatic distributed
@@ -162,18 +159,18 @@ EventId::EventId(bool doInit, uint32_t reserveSize,
}
for (uint32_t i = 0; i < reserveSize; i++) {
- EventIdTSS::s_eventId->getAndIncEidSeq();
+ EventIdTSS::s_eventId.getAndIncEidSeq();
}
}
void EventId::initFromTSS() {
- m_eidThr = EventIdTSS::s_eventId->getEidThr();
- m_eidSeq = EventIdTSS::s_eventId->getAndIncEidSeq();
+ m_eidThr = EventIdTSS::s_eventId.getEidThr();
+ m_eidSeq = EventIdTSS::s_eventId.getAndIncEidSeq();
}
void EventId::initFromTSS_SameThreadIdAndSameSequenceId() {
- m_eidThr = EventIdTSS::s_eventId->getEidThr();
- m_eidSeq = EventIdTSS::s_eventId->getSeqNum();
+ m_eidThr = EventIdTSS::s_eventId.getEidThr();
+ m_eidSeq = EventIdTSS::s_eventId.getSeqNum();
}
EventId::~EventId() {}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/EventId.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/EventId.hpp b/src/cppcache/src/EventId.hpp
index 92d17a6..cae6bdd 100644
--- a/src/cppcache/src/EventId.hpp
+++ b/src/cppcache/src/EventId.hpp
@@ -24,7 +24,6 @@
#include <geode/geode_types.hpp>
#include <geode/Cacheable.hpp>
#include "GeodeTypeIdsImpl.hpp"
-#include "SpinLock.hpp"
#include <geode/DataOutput.hpp>
#include <string>
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/HostAsm.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/HostAsm.cpp b/src/cppcache/src/HostAsm.cpp
index 763256b..6a65249 100644
--- a/src/cppcache/src/HostAsm.cpp
+++ b/src/cppcache/src/HostAsm.cpp
@@ -25,8 +25,6 @@
using namespace apache::geode::client;
-int32_t HostAsm::m_SpinCount = 0;
-
// TODO refactor - why do we have our own atomic methods? why not use C++11?
#if defined(_LINUX) || defined(_X86_SOLARIS)
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/HostAsm.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/HostAsm.hpp b/src/cppcache/src/HostAsm.hpp
index 770cb5d..3fe59a4 100644
--- a/src/cppcache/src/HostAsm.hpp
+++ b/src/cppcache/src/HostAsm.hpp
@@ -55,37 +55,10 @@ namespace apache {
namespace geode {
namespace client {
-typedef volatile uint32_t SpinLockField;
-
-/* These should be defined the same as their HOST_LOCK counterparts. */
-#if defined(FLG_SOLARIS_UNIX)
-
-// StaticSpinLock assumes that SpinLock values are initialized to zero!
-
-/* no longer using the ldstub instruction, now using cas */
-/* Use the high order 4 bytes of the word as the lock */
-enum { SPINLOCK_SET_INT = 0xf0000000 };
-enum { SPINLOCK_SET_BYTE = 0xf0 };
-enum { SPINLOCK_CLEAR_INT = 0 };
-enum { SPINLOCK_CLEAR_BYTE = 0 };
-
-#else
-
-// StaticSpinLock assumes that SpinLock values are initialized to zero!
-
-/* default Windows and x86 Linux */
-enum { SPINLOCK_SET_INT = 1 };
-enum { SPINLOCK_SET_BYTE = 1 };
-enum { SPINLOCK_CLEAR_INT = 0 };
-enum { SPINLOCK_CLEAR_BYTE = 0 };
-
-#endif
#ifdef _SPARC_SOLARIS
// implemented in hostsolaris.asm
extern "C" {
-void HostAsmUnlock(int32_t, SpinLockField*);
-bool HostAsmTryLock(SpinLockField*, int32_t, uint32_t);
int32_t InterlockedExchangeAdd(volatile int32_t*, int32_t);
// int64_t InterlockedExchangeAddLong(volatile int64_t *, int64_t);
}
@@ -103,136 +76,6 @@ int32_t InterlockedCompareExchange(volatile LONG*, int32_t, int32_t);
*/
class CPPCACHE_EXPORT HostAsm {
public:
- enum HostSleepConsts {
- SPIN_MIN_SLEEP = 250,
- SPIN_SLEEP_LIMIT = 5000,
- SPIN_COUNT = 3000
- };
-
- static void spinLockInit(SpinLockField& lockField) {
- // StaticSpinLock assumes that SpinLock values are initialized to zero!
- lockField = SPINLOCK_CLEAR_INT;
- }
-
- /**
- * Get exclusive access to the lock, return when the lock is granted.
- */
- inline static void spinLockAcquire(SpinLockField& lockField) {
-#if defined(_MACOSX)
- OSSpinLockLock(reinterpret_cast<volatile int32_t*>(&lockField));
-#else
- uint32_t lockVal = SPINLOCK_SET_INT;
- int32_t spinCount = HostAsm::getSpinCount();
- if (!HostAsm::_tryLock(lockField, spinCount, lockVal)) {
- ACE_OS::thr_yield();
- if (!HostAsm::_tryLock(lockField, spinCount, lockVal)) {
- uint32_t lock_sleepTime = SPIN_MIN_SLEEP;
- do {
- HostAsm::nanoSleep(lock_sleepTime);
- if (lock_sleepTime < SPIN_SLEEP_LIMIT) {
- lock_sleepTime++;
- }
- } while (!HostAsm::_tryLock(lockField, spinCount, lockVal));
- }
- }
-#endif
- }
-
- inline static int32_t getCpuCount() {
-#ifdef _WIN32
- SYSTEM_INFO si;
- GetSystemInfo(&si);
- return si.dwNumberOfProcessors;
-#else
- return static_cast<int32_t>(sysconf(_SC_NPROCESSORS_ONLN));
-#endif
- }
-
- inline static void nanoSleep(uint32_t time) {
- timespec nanos;
- nanos.tv_sec = 0;
- nanos.tv_nsec = time;
- timespec remaining;
- remaining.tv_sec = 0;
- remaining.tv_nsec = 0;
- ACE_OS::nanosleep(&nanos, &remaining);
- }
-
- inline static int64_t currentTimeMs() {
- return ACE_OS::gettimeofday().msec();
- }
-
-#if 0 // Unused
- /**
- * Try to get exclusive access to the lock in the specified amount of time.
- * Return whether the lock is granted.
- */
- inline static bool spinLockTryAcquire(SpinLockField& lockField,
- int32_t msTimeout)
- {
-#if defined(_MACOSX)
- return OSSpinLockTry((volatile int32_t *) &lockField);
-#else
- uint32_t lockVal = SPINLOCK_SET_INT;
- int32_t spinCount = HostAsm::getSpinCount();
- int64_t startTime = HostAsm::currentTimeMs();
- if (!HostAsm::_tryLock(lockField, spinCount, lockVal)) {
- ACE_OS::thr_yield();
- if (!HostAsm::_tryLock(lockField, spinCount, lockVal)) {
- uint32_t lock_sleepTime = SPIN_MIN_SLEEP;
- do {
- HostAsm::nanoSleep(lock_sleepTime);
- if (lock_sleepTime < SPIN_SLEEP_LIMIT) {
- lock_sleepTime++;
- }
- if (HostAsm::currentTimeMs() - startTime > (int64_t)msTimeout) {
- return false;
- }
- } while (!HostAsm::_tryLock(lockField, spinCount, lockVal));
- }
- }
- return true;
-#endif
- }
-#endif
-
- /**
- * Name - SpinUnlock
- * Purpose -
- * Release the specified spinlock.
- */
- inline static void spinLockRelease(SpinLockField& lockField) {
-#ifdef _WIN32
- InterlockedExchange((volatile LONG*)(&lockField), SPINLOCK_CLEAR_BYTE);
-#elif defined(_LINUX) /*|| defined(_X86_SOLARIS)*/
-
- int oldval = SPINLOCK_CLEAR_BYTE;
- __asm__ __volatile__("xchg %0, %1"
- : "=q"(oldval), "=m"(lockField)
- : "0"(oldval)
- : "memory");
-#elif defined(_SPARC_SOLARIS)
- SpinLockField* lockPtr = &lockField;
- HostAsmUnlock(SPINLOCK_CLEAR_BYTE, lockPtr);
-#elif defined(_X86_SOLARIS)
- // atomic_cas_32((volatile uin32_t*)&lockField, 1, 0);
- atomic_cas_32(&lockField, 1, 0);
-#elif defined(_MACOSX)
- OSSpinLockUnlock(reinterpret_cast<volatile int32_t*>(&lockField));
-#else
-#error Port incomplete.
-#endif
- }
-
- static int32_t m_SpinCount;
-
- inline static int32_t getSpinCount() {
- if (HostAsm::m_SpinCount == 0) {
- HostAsm::m_SpinCount =
- (HostAsm::getCpuCount() == 1 ? 1 : int32_t(SPIN_COUNT));
- }
- return HostAsm::m_SpinCount;
- }
#if defined(_LINUX) || defined(_X86_SOLARIS)
inline static int32_t InterlockedExchangeAdd(volatile int32_t* val,
@@ -342,101 +185,6 @@ class CPPCACHE_EXPORT HostAsm {
return atomicAnd(data, ~mask);
}
- private:
-#if !defined(_MACOSX)
- inline static bool _tryLock(SpinLockField& lockField, int32_t count,
- uint32_t lockVal) {
- GF_DEV_ASSERT(count > 0);
-#if defined(_LINUX)
- int oldval = 1; // Set to 1, since we use 0 as success.
- do {
- oldval = 1;
- __asm__ __volatile__(
- "lock\n"
- "xchg %0,%1"
- : "=q"(oldval), "=m"(lockField)
- : "0"(SPINLOCK_SET_BYTE)
- : "memory");
- if (oldval == 0) {
- return true;
- }
- __asm__ __volatile__("pause");
- count--;
- } while (count > 0);
- if (oldval == 0) {
- return true;
- }
- return false;
-#elif defined(_SPARC_SOLARIS)
- SpinLockField* lockPtr = &lockField;
- return HostAsmTryLock(lockPtr, count, lockVal);
-#elif defined(_X86_SOLARIS)
- SpinLockField* lockPtr = &lockField;
- do {
- if (*lockPtr == SPINLOCK_CLEAR_INT) {
- // if oldValue is zero, then it must have been updated to 1
- // else if CAS was unsuccessful then it will still be locked i.e. 1
- if (atomic_cas_32(lockPtr, 0, 1) == 0) {
- return true;
- }
- }
- // yield the thread if required to avoid tight spin
- ACE_Thread::yield();
- count--;
- } while (count > 0);
- return false;
-#elif defined(_WIN32)
- SpinLockField* lockPtr = &lockField;
- SpinLockField prevValue;
- // SpinLockField prevCopy;
- prevValue = *lockPtr;
- do {
- if (prevValue == SPINLOCK_CLEAR_INT) {
- if (InterlockedCompareExchangeAcquire((volatile LONG*)lockPtr, lockVal,
- SPINLOCK_CLEAR_INT) ==
- SPINLOCK_CLEAR_INT) {
- return true;
- }
- } else {
-#if defined(_MANAGED)
- Sleep(0);
-#else
- YieldProcessor();
- YieldProcessor();
- YieldProcessor();
- YieldProcessor();
- YieldProcessor();
-#endif
- }
- // Fancy atomic read, equivalent to prevValue = *lockPtr
- prevValue = InterlockedExchangeAdd((volatile LONG*)(lockPtr), 0);
- } while (--count >= 0);
- return false;
-/*
-if(count--) {
- return false;
-}
-prevCopy = prevValue;
-if(prevValue == SPINLOCK_CLEAR_INT) {
- prevValue = InterlockedCompareExchangeAcquire(
- (volatile LONG*)lockPtr, lockVal, prevValue);
-} else {
- //Fancy atomic read, equivalent to prevValue = *lockPtr
- prevValue = InterlockedExchangeAdd((volatile LONG*)(lockPtr), 0);
-
- //This might be slightly faster
- //prevValue = InterlockedCompareExchange((volatile LONG*)lockPtr,
- // prevValue, prevValue);
-}
-} while( prevCopy != prevValue );
-return true;
-*/
-#else
-#error Port impcomplete
-#endif
- return true;
- }
-#endif // !defined(_MACOSX)
};
} // namespace client
} // namespace geode
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/LRUEntriesMap.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/LRUEntriesMap.cpp b/src/cppcache/src/LRUEntriesMap.cpp
index ef705c3..b9e72a2 100644
--- a/src/cppcache/src/LRUEntriesMap.cpp
+++ b/src/cppcache/src/LRUEntriesMap.cpp
@@ -20,6 +20,9 @@
#include "MapSegment.hpp"
#include "CacheImpl.hpp"
+#include <mutex>
+#include "util/concurrent/spinlock_mutex.hpp"
+
namespace apache {
namespace geode {
namespace client {
@@ -48,11 +51,6 @@ class CPPCACHE_EXPORT TestMapAction : public virtual LRUAction {
virtual LRUAction::Action getType() { return LRUAction::LOCAL_DESTROY; }
friend class LRUAction;
};
-} // namespace client
-} // namespace geode
-} // namespace apache
-
-using namespace apache::geode::client;
LRUEntriesMap::LRUEntriesMap(EntryFactory* entryFactory, RegionInternal* region,
const LRUAction::Action& lruAction,
@@ -297,7 +295,7 @@ GfErrType LRUEntriesMap::put(const CacheableKeyPtr& key,
}
}
// SpinLock& lock = segmentRPtr->getSpinLock();
- // SpinLockGuard mapGuard( lock );
+ // std::lock_guard<spinlock_mutex> mapGuard( lock );
// TODO: when can newValue be a token ??
if (CacheableToken::isToken(newValue) && !isOldValueToken) {
@@ -490,7 +488,7 @@ void LRUEntriesMap::updateMapSize(int64_t size) {
// by all the callers
if (m_evictionControllerPtr != nullptr) {
{
- SpinLockGuard __guard(m_mapInfoLock);
+ std::lock_guard<spinlock_mutex> __guard(m_mapInfoLock);
m_currentMapSize += size;
}
m_evictionControllerPtr->updateRegionHeapInfo(size);
@@ -511,3 +509,6 @@ CacheablePtr LRUEntriesMap::getFromDisk(const CacheableKeyPtr& key,
}
return tmpObj;
}
+} // namespace client
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/LRUEntriesMap.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/LRUEntriesMap.hpp b/src/cppcache/src/LRUEntriesMap.hpp
index c92f4fd..7188c6a 100644
--- a/src/cppcache/src/LRUEntriesMap.hpp
+++ b/src/cppcache/src/LRUEntriesMap.hpp
@@ -1,8 +1,3 @@
-#pragma once
-
-#ifndef GEODE_LRUENTRIESMAP_H_
-#define GEODE_LRUENTRIESMAP_H_
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -20,6 +15,11 @@
* limitations under the License.
*/
+#pragma once
+
+#ifndef GEODE_LRUENTRIESMAP_H_
+#define GEODE_LRUENTRIESMAP_H_
+
#include <geode/geode_globals.hpp>
#include <geode/Cache.hpp>
#include "ConcurrentEntriesMap.hpp"
@@ -27,7 +27,8 @@
#include "LRUList.hpp"
#include "LRUMapEntry.hpp"
#include "MapEntryT.hpp"
-#include "SpinLock.hpp"
+
+#include "util/concurrent/spinlock_mutex.hpp"
#include "NonCopyable.hpp"
@@ -65,7 +66,7 @@ class CPPCACHE_EXPORT LRUEntriesMap : public ConcurrentEntriesMap,
PersistenceManagerPtr m_pmPtr;
EvictionController* m_evictionControllerPtr;
int64_t m_currentMapSize;
- SpinLock m_mapInfoLock;
+ spinlock_mutex m_mapInfoLock;
std::string m_name;
AtomicInc m_validEntries;
bool m_heapLRUEnabled;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/LRUList.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/LRUList.cpp b/src/cppcache/src/LRUList.cpp
index 343a18a..9a24286 100644
--- a/src/cppcache/src/LRUList.cpp
+++ b/src/cppcache/src/LRUList.cpp
@@ -15,12 +15,15 @@
* limitations under the License.
*/
#include "LRUList.hpp"
-#include "SpinLock.hpp"
+#include "util/concurrent/spinlock_mutex.hpp"
-using namespace apache::geode::client;
+#include <mutex>
-#define LOCK_HEAD SpinLockGuard headLockGuard(m_headLock)
-#define LOCK_TAIL SpinLockGuard tailLockGuard(m_tailLock)
+namespace apache {
+namespace geode {
+namespace client {
+
+using util::concurrent::spinlock_mutex;
template <typename TEntry, typename TCreateEntry>
LRUList<TEntry, TCreateEntry>::LRUList() : m_headLock(), m_tailLock() {
@@ -43,7 +46,7 @@ LRUList<TEntry, TCreateEntry>::~LRUList() {
template <typename TEntry, typename TCreateEntry>
void LRUList<TEntry, TCreateEntry>::appendEntry(const LRUListEntryPtr& entry) {
- LOCK_TAIL;
+ std::lock_guard<spinlock_mutex> lk(m_tailLock);
LRUListNode* aNode = new LRUListNode(entry);
m_tailNode->setNextLRUListNode(aNode);
@@ -52,7 +55,7 @@ void LRUList<TEntry, TCreateEntry>::appendEntry(const LRUListEntryPtr& entry) {
template <typename TEntry, typename TCreateEntry>
void LRUList<TEntry, TCreateEntry>::appendNode(LRUListNode* aNode) {
- LOCK_TAIL;
+ std::lock_guard<spinlock_mutex> lk(m_tailLock);
GF_D_ASSERT(aNode != nullptr);
@@ -97,13 +100,14 @@ void LRUList<TEntry, TCreateEntry>::getLRUEntry(LRUListEntryPtr& result) {
template <typename TEntry, typename TCreateEntry>
typename LRUList<TEntry, TCreateEntry>::LRUListNode*
LRUList<TEntry, TCreateEntry>::getHeadNode(bool& isLast) {
- LOCK_HEAD;
+ std::lock_guard<spinlock_mutex> lk(m_headLock);
LRUListNode* result = m_headNode;
LRUListNode* nextNode;
{
- LOCK_TAIL;
+ std::lock_guard<spinlock_mutex> lk(m_tailLock);
+
nextNode = m_headNode->getNextLRUListNode();
if (nextNode == nullptr) {
// last one in the list...
@@ -126,3 +130,7 @@ LRUList<TEntry, TCreateEntry>::getHeadNode(bool& isLast) {
return result;
}
+
+} // namespace client
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/LRUList.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/LRUList.hpp b/src/cppcache/src/LRUList.hpp
index 66e5210..71342f9 100644
--- a/src/cppcache/src/LRUList.hpp
+++ b/src/cppcache/src/LRUList.hpp
@@ -20,17 +20,21 @@
* limitations under the License.
*/
+#include <atomic>
+
#include <geode/geode_globals.hpp>
#include <memory>
-#include "SpinLock.hpp"
+
+#include "util/concurrent/spinlock_mutex.hpp"
namespace apache {
namespace geode {
namespace client {
+
// Bit mask for recently used
-#define RECENTLY_USED_BITS 1ul
+#define RECENTLY_USED_BITS 1u
// Bit mask for evicted
-#define EVICTED_BITS 2ul
+#define EVICTED_BITS 2u
/**
* @brief This class encapsulates LRU specific properties for a LRUList node.
@@ -39,13 +43,9 @@ class CPPCACHE_EXPORT LRUEntryProperties {
public:
inline LRUEntryProperties() : m_bits(0), m_persistenceInfo(nullptr) {}
- inline void setRecentlyUsed() {
- HostAsm::atomicSetBits(m_bits, RECENTLY_USED_BITS);
- }
+ inline void setRecentlyUsed() { m_bits |= RECENTLY_USED_BITS; }
- inline void clearRecentlyUsed() {
- HostAsm::atomicClearBits(m_bits, RECENTLY_USED_BITS);
- }
+ inline void clearRecentlyUsed() { m_bits &= ~RECENTLY_USED_BITS; }
inline bool testRecentlyUsed() const {
return (m_bits & RECENTLY_USED_BITS) == RECENTLY_USED_BITS;
@@ -55,9 +55,9 @@ class CPPCACHE_EXPORT LRUEntryProperties {
return (m_bits & EVICTED_BITS) == EVICTED_BITS;
}
- inline void setEvicted() { HostAsm::atomicSetBits(m_bits, EVICTED_BITS); }
+ inline void setEvicted() { m_bits |= EVICTED_BITS; }
- inline void clearEvicted() { HostAsm::atomicClearBits(m_bits, EVICTED_BITS); }
+ inline void clearEvicted() { m_bits &= ~EVICTED_BITS; }
inline void* getPersistenceInfo() const { return m_persistenceInfo; }
@@ -70,10 +70,12 @@ class CPPCACHE_EXPORT LRUEntryProperties {
inline LRUEntryProperties(bool noInit) {}
private:
- volatile uint32_t m_bits;
+ std::atomic<uint32_t> m_bits;
void* m_persistenceInfo;
};
+using util::concurrent::spinlock_mutex;
+
/**
* @brief Maintains a list of entries returning them through head in
* approximate LRU order. The <code>TEntry</code> template argument
@@ -142,8 +144,8 @@ class LRUList {
*/
LRUListNode* getHeadNode(bool& isLast);
- SpinLock m_headLock;
- SpinLock m_tailLock;
+ spinlock_mutex m_headLock;
+ spinlock_mutex m_tailLock;
LRUListNode* m_headNode;
LRUListNode* m_tailNode;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/LocalRegion.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/LocalRegion.hpp b/src/cppcache/src/LocalRegion.hpp
index dca7386..7d5a139 100644
--- a/src/cppcache/src/LocalRegion.hpp
+++ b/src/cppcache/src/LocalRegion.hpp
@@ -45,7 +45,6 @@
#include "RegionInternal.hpp"
#include "RegionStats.hpp"
#include "EntriesMapFactory.hpp"
-#include "SpinLock.hpp"
#include "SerializationRegistry.hpp"
#include "MapWithLock.hpp"
#include "CacheableToken.hpp"
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/MapSegment.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/MapSegment.cpp b/src/cppcache/src/MapSegment.cpp
index 6492dc1..e3b39a6 100644
--- a/src/cppcache/src/MapSegment.cpp
+++ b/src/cppcache/src/MapSegment.cpp
@@ -19,16 +19,20 @@
#include "TrackedMapEntry.hpp"
#include "RegionInternal.hpp"
#include "TableOfPrimes.hpp"
-#include "SpinLock.hpp"
#include "Utils.hpp"
#include "ThinClientPoolDM.hpp"
#include "ThinClientRegion.hpp"
#include "TombstoneExpiryHandler.hpp"
#include <ace/OS.h>
#include "ace/Time_Value.h"
-using namespace apache::geode::client;
-#define _GF_GUARD_SEGMENT SpinLockGuard mapGuard(m_spinlock)
+#include <mutex>
+#include "util/concurrent/spinlock_mutex.hpp"
+
+namespace apache {
+namespace geode {
+namespace client {
+
#define _VERSION_TAG_NULL_CHK \
(versionTag != nullptr && versionTag.get() != nullptr)
bool MapSegment::boolVal = false;
@@ -54,7 +58,7 @@ void MapSegment::open(RegionInternal* region, const EntryFactory* entryFactory,
void MapSegment::close() { m_map->close(); }
void MapSegment::clear() {
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
m_map->unbind_all();
}
@@ -66,11 +70,11 @@ GfErrType MapSegment::create(const CacheableKeyPtr& key,
const CacheablePtr& newValue, MapEntryImplPtr& me,
CacheablePtr& oldValue, int updateCount,
int destroyTracker, VersionTagPtr versionTag) {
- long taskid = -1;
+ int64_t taskid = -1;
TombstoneExpiryHandler* handler = nullptr;
GfErrType err = GF_NOERR;
{
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
// if size is greater than 75 percent of prime, rehash
uint32_t mapSize = TableOfPrimes::getPrime(m_primeIndex);
if (((m_map->current_size() * 75) / 100) > mapSize) {
@@ -133,11 +137,11 @@ GfErrType MapSegment::put(const CacheableKeyPtr& key,
CacheablePtr& oldValue, int updateCount,
int destroyTracker, bool& isUpdate,
VersionTagPtr versionTag, DataInput* delta) {
- long taskid = -1;
+ int64_t taskid = -1;
TombstoneExpiryHandler* handler = nullptr;
GfErrType err = GF_NOERR;
{
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
// if size is greater than 75 percent of prime, rehash
uint32_t mapSize = TableOfPrimes::getPrime(m_primeIndex);
if (((m_map->current_size() * 75) / 100) > mapSize) {
@@ -199,7 +203,7 @@ GfErrType MapSegment::put(const CacheableKeyPtr& key,
GfErrType MapSegment::invalidate(const CacheableKeyPtr& key,
MapEntryImplPtr& me, CacheablePtr& oldValue,
VersionTagPtr versionTag, bool& isTokenAdded) {
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
int status;
isTokenAdded = false;
GfErrType err = GF_NOERR;
@@ -245,7 +249,7 @@ GfErrType MapSegment::invalidate(const CacheableKeyPtr& key,
GfErrType MapSegment::removeWhenConcurrencyEnabled(
const CacheableKeyPtr& key, CacheablePtr& oldValue, MapEntryImplPtr& me,
int updateCount, VersionTagPtr versionTag, bool afterRemote,
- bool& isEntryFound, long expiryTaskID, TombstoneExpiryHandler* handler,
+ bool& isEntryFound, int64_t expiryTaskID, TombstoneExpiryHandler* handler,
bool& expTaskSet) {
GfErrType err = GF_NOERR;
int status;
@@ -316,23 +320,20 @@ GfErrType MapSegment::remove(const CacheableKeyPtr& key, CacheablePtr& oldValue,
MapEntryImplPtr& me, int updateCount,
VersionTagPtr versionTag, bool afterRemote,
bool& isEntryFound) {
- // _GF_GUARD_SEGMENT;
int status;
MapEntryPtr entry;
if (m_concurrencyChecksEnabled) {
TombstoneExpiryHandler* handler;
- long id = m_tombstoneList->getExpiryTask(&handler);
+ int64_t id = m_tombstoneList->getExpiryTask(&handler);
bool expTaskSet = false;
GfErrType err;
{
- _GF_GUARD_SEGMENT;
- // if (m_concurrencyChecksEnabled)
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
err = removeWhenConcurrencyEnabled(key, oldValue, me, updateCount,
versionTag, afterRemote, isEntryFound,
id, handler, expTaskSet);
}
- // if (m_concurrencyChecksEnabled){
if (!expTaskSet) {
CacheImpl::expiryTaskManager->cancelTask(id);
delete handler;
@@ -340,7 +341,7 @@ GfErrType MapSegment::remove(const CacheableKeyPtr& key, CacheablePtr& oldValue,
return err;
}
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
CacheablePtr value;
if ((status = m_map->unbind(key, entry)) == -1) {
// didn't unbind, probably no entry...
@@ -377,7 +378,7 @@ bool MapSegment::unguardedRemoveActualEntry(const CacheableKeyPtr& key,
bool MapSegment::unguardedRemoveActualEntryWithoutCancelTask(
const CacheableKeyPtr& key, TombstoneExpiryHandler*& handler,
- long& taskid) {
+ int64_t& taskid) {
MapEntryPtr entry;
taskid = m_tombstoneList->eraseEntryFromTombstoneListWithoutCancelTask(
key, m_region, handler);
@@ -389,7 +390,7 @@ bool MapSegment::unguardedRemoveActualEntryWithoutCancelTask(
bool MapSegment::removeActualEntry(const CacheableKeyPtr& key,
bool cancelTask) {
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
return unguardedRemoveActualEntry(key, cancelTask);
}
/**
@@ -397,7 +398,7 @@ bool MapSegment::removeActualEntry(const CacheableKeyPtr& key,
*/
bool MapSegment::getEntry(const CacheableKeyPtr& key, MapEntryImplPtr& result,
CacheablePtr& value) {
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
int status;
MapEntryPtr entry;
if ((status = m_map->find(key, entry)) == -1) {
@@ -422,7 +423,7 @@ bool MapSegment::getEntry(const CacheableKeyPtr& key, MapEntryImplPtr& result,
* @brief return true if there exists an entry for the key.
*/
bool MapSegment::containsKey(const CacheableKeyPtr& key) {
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
MapEntryPtr mePtr;
int status;
if ((status = m_map->find(key, mePtr)) == -1) {
@@ -441,7 +442,7 @@ bool MapSegment::containsKey(const CacheableKeyPtr& key) {
* @brief return the all the keys in the provided list.
*/
void MapSegment::keys(VectorOfCacheableKey& result) {
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
for (CacheableKeyHashMap::iterator iter = m_map->begin();
iter != m_map->end(); iter++) {
CacheablePtr valuePtr;
@@ -456,9 +457,7 @@ void MapSegment::keys(VectorOfCacheableKey& result) {
* @brief return all the entries in the provided list.
*/
void MapSegment::entries(VectorOfRegionEntry& result) {
- _GF_GUARD_SEGMENT;
- // printf("total_size)=%u, current_size=%u\n",
- // m_map->total_size(), m_map->current_size());
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
for (CacheableKeyHashMap::iterator iter = m_map->begin();
iter != m_map->end(); iter++) {
CacheableKeyPtr keyPtr;
@@ -480,7 +479,7 @@ void MapSegment::entries(VectorOfRegionEntry& result) {
* @brief return all values in the provided list.
*/
void MapSegment::values(VectorOfCacheable& result) {
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
for (CacheableKeyHashMap::iterator iter = m_map->begin();
iter != m_map->end(); iter++) {
CacheablePtr valuePtr;
@@ -514,7 +513,7 @@ int MapSegment::addTrackerForEntry(const CacheableKeyPtr& key,
CacheablePtr& oldValue, bool addIfAbsent,
bool failIfPresent, bool incUpdateCount) {
if (m_concurrencyChecksEnabled) return -1;
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
MapEntryPtr entry;
MapEntryPtr newEntry;
int status;
@@ -561,7 +560,7 @@ int MapSegment::addTrackerForEntry(const CacheableKeyPtr& key,
// changes takes care of the version and no need for tracking the entry
void MapSegment::removeTrackerForEntry(const CacheableKeyPtr& key) {
if (m_concurrencyChecksEnabled) return;
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
MapEntryPtr entry;
int status;
if ((status = m_map->find(key, entry)) != -1) {
@@ -576,7 +575,7 @@ void MapSegment::removeTrackerForEntry(const CacheableKeyPtr& key) {
void MapSegment::addTrackerForAllEntries(
MapOfUpdateCounters& updateCounterMap) {
if (m_concurrencyChecksEnabled) return;
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
MapEntryPtr newEntry;
CacheableKeyPtr key;
for (CacheableKeyHashMap::iterator iter = m_map->begin();
@@ -595,7 +594,7 @@ void MapSegment::addTrackerForAllEntries(
// changes takes care of the version and no need for tracking the entry
void MapSegment::removeDestroyTracking() {
if (m_concurrencyChecksEnabled) return;
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
m_destroyedKeys.clear();
}
@@ -712,11 +711,11 @@ GfErrType MapSegment::putForTrackedEntry(
}
}
void MapSegment::reapTombstones(std::map<uint16_t, int64_t>& gcVersions) {
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
m_tombstoneList->reapTombstones(gcVersions);
}
void MapSegment::reapTombstones(CacheableHashSetPtr removedKeys) {
- _GF_GUARD_SEGMENT;
+ std::lock_guard<spinlock_mutex> lk(m_spinlock);
m_tombstoneList->reapTombstones(removedKeys);
}
@@ -731,12 +730,6 @@ GfErrType MapSegment::isTombstone(CacheableKeyPtr key, MapEntryImplPtr& me,
}
mePtr = entry->getImplPtr();
- /* adongre - Coverity II
- * CID 29204: Dereference before null check (REVERSE_INULL)
- * Dereferencing pointer "mePtr". [show details]
- * Fix : Aded a check for null ptr
- */
-
if (!mePtr) {
result = false;
return GF_NOERR;
@@ -774,3 +767,6 @@ GfErrType MapSegment::isTombstone(CacheableKeyPtr key, MapEntryImplPtr& me,
}
}
}
+} // namespace client
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/MapSegment.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/MapSegment.hpp b/src/cppcache/src/MapSegment.hpp
index 75d2c03..495bc95 100644
--- a/src/cppcache/src/MapSegment.hpp
+++ b/src/cppcache/src/MapSegment.hpp
@@ -26,7 +26,6 @@
#include "MapEntry.hpp"
#include <geode/RegionEntry.hpp>
#include <geode/VectorT.hpp>
-#include "SpinLock.hpp"
#include "MapWithLock.hpp"
#include "CacheableToken.hpp"
#include <geode/Delta.hpp>
@@ -41,6 +40,9 @@
#include <ace/Versioned_Namespace.h>
#include "TombstoneList.hpp"
#include <unordered_map>
+
+#include "util/concurrent/spinlock_mutex.hpp"
+
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
template <>
@@ -83,7 +85,7 @@ class CPPCACHE_EXPORT MapSegment {
// index of the current prime in the primes table
uint32_t m_primeIndex;
- SpinLock m_spinlock;
+ spinlock_mutex m_spinlock;
ACE_Recursive_Thread_Mutex m_segmentMutex;
bool m_concurrencyChecksEnabled;
@@ -185,7 +187,7 @@ class CPPCACHE_EXPORT MapSegment {
GfErrType removeWhenConcurrencyEnabled(
const CacheableKeyPtr& key, CacheablePtr& oldValue, MapEntryImplPtr& me,
int updateCount, VersionTagPtr versionTag, bool afterRemote,
- bool& isEntryFound, long expiryTaskID, TombstoneExpiryHandler* handler,
+ bool& isEntryFound, int64_t expiryTaskID, TombstoneExpiryHandler* handler,
bool& expTaskSet);
public:
@@ -297,7 +299,7 @@ class CPPCACHE_EXPORT MapSegment {
bool unguardedRemoveActualEntryWithoutCancelTask(
const CacheableKeyPtr& key, TombstoneExpiryHandler*& handler,
- long& taskid);
+ int64_t& taskid);
bool unguardedRemoveActualEntry(const CacheableKeyPtr& key,
bool cancelTask = true);
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/PoolStatistics.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/PoolStatistics.cpp b/src/cppcache/src/PoolStatistics.cpp
index c7f2b0d..9aa477a 100644
--- a/src/cppcache/src/PoolStatistics.cpp
+++ b/src/cppcache/src/PoolStatistics.cpp
@@ -20,33 +20,38 @@
#include "PoolStatistics.hpp"
//#include "StatisticsFactory.hpp"
-#include <ace/Thread_Mutex.h>
#include <ace/Singleton.h>
+#include <mutex>
+
+#include "util/concurrent/spinlock_mutex.hpp"
+
////////////////////////////////////////////////////////////////////////////////
namespace apache {
namespace geode {
namespace client {
-using namespace apache::geode::statistics;
+using statistics::StatisticsFactory;
+using statistics::StatisticsManager;
+using util::concurrent::spinlock_mutex;
////////////////////////////////////////////////////////////////////////////////
PoolStatType* PoolStatType::single = nullptr;
-SpinLock PoolStatType::m_singletonLock;
-SpinLock PoolStatType::m_statTypeLock;
+spinlock_mutex PoolStatType::m_singletonLock;
+spinlock_mutex PoolStatType::m_statTypeLock;
void PoolStatType::clean() {
- SpinLockGuard guard(m_singletonLock);
- if (single != nullptr) {
+ std::lock_guard<spinlock_mutex> guard(m_singletonLock);
+ if (single) {
delete single;
single = nullptr;
}
}
StatisticsType* PoolStatType::getStatType() {
- SpinLockGuard guard(m_statTypeLock);
+ std::lock_guard<spinlock_mutex> guard(m_statTypeLock);
StatisticsFactory* factory = StatisticsFactory::getExistingInstance();
GF_D_ASSERT(!!factory);
@@ -179,8 +184,8 @@ StatisticsType* PoolStatType::getStatType() {
}
PoolStatType* PoolStatType::getInstance() {
- SpinLockGuard guard(m_singletonLock);
- if (single == nullptr) {
+ std::lock_guard<spinlock_mutex> guard(m_singletonLock);
+ if (!single) {
single = new PoolStatType();
}
return single;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/PoolStatistics.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/PoolStatistics.hpp b/src/cppcache/src/PoolStatistics.hpp
index e107b44..c882cfc 100644
--- a/src/cppcache/src/PoolStatistics.hpp
+++ b/src/cppcache/src/PoolStatistics.hpp
@@ -1,10 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#pragma once
#ifndef GEODE_POOLSTATISTICS_H_
#define GEODE_POOLSTATISTICS_H_
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
@@ -24,13 +40,16 @@
#include <geode/statistics/Statistics.hpp>
#include <geode/statistics/StatisticsFactory.hpp>
#include <statistics/StatisticsManager.hpp>
-#include "SpinLock.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 PoolStats {
public:
@@ -165,8 +184,8 @@ class PoolStats {
class PoolStatType {
private:
static PoolStatType* single;
- static SpinLock m_singletonLock;
- static SpinLock m_statTypeLock;
+ static spinlock_mutex m_singletonLock;
+ static spinlock_mutex m_statTypeLock;
public:
static PoolStatType* getInstance();
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/RegionStats.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/RegionStats.cpp b/src/cppcache/src/RegionStats.cpp
index 26bebbd..cff6e0e 100644
--- a/src/cppcache/src/RegionStats.cpp
+++ b/src/cppcache/src/RegionStats.cpp
@@ -23,8 +23,12 @@
#include <ace/Thread_Mutex.h>
#include <ace/Singleton.h>
-const char* statsName = (const char*)"RegionStatistics";
-const char* statsDesc = (const char*)"Statistics for this region";
+#include <mutex>
+
+#include "util/concurrent/spinlock_mutex.hpp"
+
+const char* statsName = "RegionStatistics";
+const char* statsDesc = "Statistics for this region";
////////////////////////////////////////////////////////////////////////////////
@@ -32,17 +36,18 @@ namespace apache {
namespace geode {
namespace client {
-using namespace apache::geode::statistics;
+using statistics::StatisticsFactory;
+using util::concurrent::spinlock_mutex;
////////////////////////////////////////////////////////////////////////////////
RegionStatType* RegionStatType::single = nullptr;
-SpinLock RegionStatType::m_singletonLock;
-SpinLock RegionStatType::m_statTypeLock;
+spinlock_mutex RegionStatType::m_singletonLock;
+spinlock_mutex RegionStatType::m_statTypeLock;
void RegionStatType::clean() {
- SpinLockGuard guard(m_singletonLock);
- if (single != nullptr) {
+ std::lock_guard<spinlock_mutex> guard(m_singletonLock);
+ if (single) {
delete single;
single = nullptr;
}
@@ -50,7 +55,7 @@ void RegionStatType::clean() {
StatisticsType* RegionStatType::getStatType() {
const bool largerIsBetter = true;
- SpinLockGuard guard(m_statTypeLock);
+ std::lock_guard<spinlock_mutex> guard(m_statTypeLock);
StatisticsFactory* factory = StatisticsFactory::getExistingInstance();
GF_D_ASSERT(!!factory);
@@ -185,14 +190,40 @@ StatisticsType* RegionStatType::getStatType() {
}
RegionStatType* RegionStatType::getInstance() {
- SpinLockGuard guard(m_singletonLock);
- if (single == nullptr) {
+ std::lock_guard<spinlock_mutex> guard(m_singletonLock);
+ if (!single) {
single = new RegionStatType();
}
return single;
}
-RegionStatType::RegionStatType() {}
+RegionStatType::RegionStatType()
+ : m_destroysId(0),
+ m_createsId(0),
+ m_putsId(0),
+ m_putTimeId(0),
+ m_putAllId(0),
+ m_putAllTimeId(0),
+ m_removeAllId(0),
+ m_removeAllTimeId(0),
+ m_getsId(0),
+ m_getTimeId(0),
+ m_getAllId(0),
+ m_getAllTimeId(0),
+ m_hitsId(0),
+ m_missesId(0),
+ m_entriesId(0),
+ m_overflowsId(0),
+ m_retrievesId(0),
+ m_nonSingleHopId(0),
+ m_metaDataRefreshId(0),
+ m_LoaderCallsCompletedId(0),
+ m_LoaderCallTimeId(0),
+ m_WriterCallsCompletedId(0),
+ m_WriterCallTimeId(0),
+ m_ListenerCallsCompletedId(0),
+ m_ListenerCallTimeId(0),
+ m_clearsId(0) {}
////////////////////////////////////////////////////////////////////////////////
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/RegionStats.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/RegionStats.hpp b/src/cppcache/src/RegionStats.hpp
index d7aba22..f37ca1b 100644
--- a/src/cppcache/src/RegionStats.hpp
+++ b/src/cppcache/src/RegionStats.hpp
@@ -1,8 +1,3 @@
-#pragma once
-
-#ifndef GEODE_REGIONSTATS_H_
-#define GEODE_REGIONSTATS_H_
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -20,19 +15,24 @@
* limitations under the License.
*/
+#pragma once
+
+#ifndef GEODE_REGIONSTATS_H_
+#define GEODE_REGIONSTATS_H_
+
#include <geode/geode_globals.hpp>
#include <geode/statistics/Statistics.hpp>
#include <geode/statistics/StatisticsFactory.hpp>
-#include "SpinLock.hpp"
-//#include "NanoTimer.hpp"
-//#include <SystemProperties.hpp>
-//#include <../DistributedSystem.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 RegionStats {
public:
@@ -125,8 +125,8 @@ class CPPCACHE_EXPORT RegionStats {
class RegionStatType {
private:
static RegionStatType* single;
- static SpinLock m_singletonLock;
- static SpinLock m_statTypeLock;
+ static spinlock_mutex m_singletonLock;
+ static spinlock_mutex m_statTypeLock;
public:
static RegionStatType* getInstance();
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/SerializationRegistry.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/SerializationRegistry.cpp b/src/cppcache/src/SerializationRegistry.cpp
index 2c148d0..a4e593c 100644
--- a/src/cppcache/src/SerializationRegistry.cpp
+++ b/src/cppcache/src/SerializationRegistry.cpp
@@ -33,7 +33,6 @@
#include "EventId.hpp"
#include <geode/Properties.hpp>
#include <geode/ExceptionTypes.hpp>
-#include "SpinLock.hpp"
#include <geode/RegionAttributes.hpp>
#include "CacheableObjectPartList.hpp"
#include "ClientConnectionResponse.hpp"
@@ -59,6 +58,9 @@
#include "NonCopyable.hpp"
+#include <mutex>
+#include "util/concurrent/spinlock_mutex.hpp"
+
namespace apache {
namespace geode {
namespace client {
@@ -81,9 +83,9 @@ class TheTypeMap : private NonCopyable, private NonAssignable {
IdToFactoryMap* m_map;
IdToFactoryMap* m_map2; // to hold Fixed IDs since GFE 5.7.
StrToPdxFactoryMap* m_pdxTypemap;
- SpinLock m_mapLock;
- SpinLock m_map2Lock;
- SpinLock m_pdxTypemapLock;
+ spinlock_mutex m_mapLock;
+ spinlock_mutex m_map2Lock;
+ spinlock_mutex m_pdxTypemapLock;
public:
TheTypeMap();
@@ -166,29 +168,29 @@ class TheTypeMap : private NonCopyable, private NonAssignable {
}
inline void clear() {
- SpinLockGuard guard(m_mapLock);
+ std::lock_guard<spinlock_mutex> guard(m_mapLock);
m_map->unbind_all();
- SpinLockGuard guard2(m_map2Lock);
+ std::lock_guard<spinlock_mutex> guard2(m_map2Lock);
m_map2->unbind_all();
- SpinLockGuard guard3(m_pdxTypemapLock);
+ std::lock_guard<spinlock_mutex> guard3(m_pdxTypemapLock);
m_pdxTypemap->unbind_all();
}
inline void find(int64_t id, TypeFactoryMethod& func) {
- SpinLockGuard guard(m_mapLock);
+ std::lock_guard<spinlock_mutex> guard(m_mapLock);
m_map->find(id, func);
}
inline void find2(int64_t id, TypeFactoryMethod& func) {
- SpinLockGuard guard(m_map2Lock);
+ std::lock_guard<spinlock_mutex> guard(m_map2Lock);
m_map2->find(id, func);
}
inline void bind(TypeFactoryMethod func) {
Serializable* obj = func();
- SpinLockGuard guard(m_mapLock);
+ std::lock_guard<spinlock_mutex> guard(m_mapLock);
int64_t compId = static_cast<int64_t>(obj->typeId());
if (compId == GeodeTypeIdsImpl::CacheableUserData ||
compId == GeodeTypeIdsImpl::CacheableUserData2 ||
@@ -217,7 +219,7 @@ class TheTypeMap : private NonCopyable, private NonAssignable {
}
inline void rebind(int64_t compId, TypeFactoryMethod func) {
- SpinLockGuard guard(m_mapLock);
+ std::lock_guard<spinlock_mutex> guard(m_mapLock);
int bindRes = m_map->rebind(compId, func);
if (bindRes == -1) {
LOGERROR(
@@ -231,13 +233,13 @@ class TheTypeMap : private NonCopyable, private NonAssignable {
}
inline void unbind(int64_t compId) {
- SpinLockGuard guard(m_mapLock);
+ std::lock_guard<spinlock_mutex> guard(m_mapLock);
m_map->unbind(compId);
}
inline void bind2(TypeFactoryMethod func) {
Serializable* obj = func();
- SpinLockGuard guard(m_map2Lock);
+ std::lock_guard<spinlock_mutex> guard(m_map2Lock);
int8_t dsfid = obj->DSFID();
int64_t compId = 0;
@@ -268,18 +270,18 @@ class TheTypeMap : private NonCopyable, private NonAssignable {
}
inline void rebind2(int64_t compId, TypeFactoryMethod func) {
- SpinLockGuard guard(m_map2Lock);
+ std::lock_guard<spinlock_mutex> guard(m_map2Lock);
m_map2->rebind(compId, func);
}
inline void unbind2(int64_t compId) {
- SpinLockGuard guard(m_map2Lock);
+ std::lock_guard<spinlock_mutex> guard(m_map2Lock);
m_map2->unbind(compId);
}
inline void bindPdxType(TypeFactoryMethodPdx func) {
PdxSerializable* obj = func();
- SpinLockGuard guard(m_pdxTypemapLock);
+ std::lock_guard<spinlock_mutex> guard(m_pdxTypemapLock);
const char* objFullName = obj->getClassName();
int bindRes = m_pdxTypemap->bind(objFullName, func);
@@ -302,13 +304,14 @@ class TheTypeMap : private NonCopyable, private NonAssignable {
}
}
- inline void findPdxType(char* objFullName, TypeFactoryMethodPdx& func) {
- SpinLockGuard guard(m_pdxTypemapLock);
+ inline void findPdxType(const char* objFullName, TypeFactoryMethodPdx& func) {
+ std::lock_guard<spinlock_mutex> guard(m_pdxTypemapLock);
m_pdxTypemap->find(objFullName, func);
}
- inline void rebindPdxType(char* objFullName, TypeFactoryMethodPdx func) {
- SpinLockGuard guard(m_pdxTypemapLock);
+ inline void rebindPdxType(const char* objFullName,
+ TypeFactoryMethodPdx func) {
+ std::lock_guard<spinlock_mutex> guard(m_pdxTypemapLock);
int bindRes = m_pdxTypemap->rebind(objFullName, func);
if (bindRes == -1) {
LOGERROR(
@@ -321,8 +324,8 @@ class TheTypeMap : private NonCopyable, private NonAssignable {
}
}
- inline void unbindPdxType(char* objFullName) {
- SpinLockGuard guard(m_pdxTypemapLock);
+ inline void unbindPdxType(const char* objFullName) {
+ std::lock_guard<spinlock_mutex> guard(m_pdxTypemapLock);
m_pdxTypemap->unbind(objFullName);
}
};
@@ -456,13 +459,13 @@ void SerializationRegistry::init() {
theTypeMap::instance()->setup();
}
-PdxSerializablePtr SerializationRegistry::getPdxType(char* className) {
+PdxSerializablePtr SerializationRegistry::getPdxType(const char* className) {
TypeFactoryMethodPdx objectType = nullptr;
theTypeMap::instance()->findPdxType(className, objectType);
PdxSerializablePtr pdxObj;
if (nullptr == objectType) {
try {
- pdxObj = std::make_shared<PdxWrapper>((const char*)className);
+ pdxObj = std::make_shared<PdxWrapper>(className);
} catch (const Exception&) {
LOGERROR(
"Unregistered class %s during PDX deserialization: Did the "
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/SerializationRegistry.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/SerializationRegistry.hpp b/src/cppcache/src/SerializationRegistry.hpp
index 846b7cc..33cc86b 100644
--- a/src/cppcache/src/SerializationRegistry.hpp
+++ b/src/cppcache/src/SerializationRegistry.hpp
@@ -146,7 +146,7 @@ class CPPCACHE_EXPORT SerializationRegistry {
static int32_t GetEnumValue(SerializablePtr enumInfo);
static SerializablePtr GetEnum(int32_t val);
- static PdxSerializablePtr getPdxType(char* className);
+ static PdxSerializablePtr getPdxType(const char* className);
private:
static PoolPtr getPool();
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/SpinLock.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/SpinLock.cpp b/src/cppcache/src/SpinLock.cpp
deleted file mode 100644
index 797f0d5..0000000
--- a/src/cppcache/src/SpinLock.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <geode/geode_globals.hpp>
-
-#include "SpinLock.hpp"
-
-namespace apache {
-namespace geode {
-namespace client {
-
-void* testSpinLockCreate() { return (void*)new SpinLock(); }
-
-void testSpinLockAcquire(void* lock) {
- (reinterpret_cast<SpinLock*>(lock))->acquire();
-}
-
-void testSpinLockRelease(void* lock) {
- (reinterpret_cast<SpinLock*>(lock))->release();
-}
-} // namespace client
-} // namespace geode
-} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/SpinLock.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/SpinLock.hpp b/src/cppcache/src/SpinLock.hpp
deleted file mode 100644
index d91b7b3..0000000
--- a/src/cppcache/src/SpinLock.hpp
+++ /dev/null
@@ -1,122 +0,0 @@
-#pragma once
-
-#ifndef GEODE_SPINLOCK_H_
-#define GEODE_SPINLOCK_H_
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "HostAsm.hpp"
-
-#ifdef DEBUG
-#define GF_SAFELOCK 1
-#else
-#define GF_SAFELOCK 0
-#endif
-
-namespace apache {
-namespace geode {
-namespace client {
-
-/**
- * For an object that needs to be protected by spinlock, declare a field of type
- * SpinLock. To protect the operation, use a SpinLockGuard on the stack to
- * automatically lock and then release when the stack is unwound..
- */
-class CPPCACHE_EXPORT SpinLock {
- public:
- SpinLock()
- : m_lockField(0)
-#if GF_SAFELOCK
- ,
- m_ownerId(0)
-#endif
- {
- HostAsm::spinLockInit(m_lockField);
- }
-
- ~SpinLock() {}
-
- void acquire() {
-#if GF_SAFELOCK
- int32_t ownerId = (int32_t)ACE_OS::thr_self();
- GF_R_ASSERT(
- (ownerId == 0) ||
- (ownerId !=
- m_ownerId)); // detect attempt to lock something I already have.
-#endif
- HostAsm::spinLockAcquire(m_lockField);
-#if GF_SAFELOCK
- m_ownerId = ownerId;
-#endif
- }
-
- void release() {
-#if GF_SAFELOCK
- m_ownerId = 0;
-#endif
- HostAsm::spinLockRelease(m_lockField);
- }
-
- private:
- SpinLockField m_lockField;
-#if GF_SAFELOCK
- int32_t m_ownerId;
-#endif
-};
-
-/**
- * Example:
- * class Foo {
- * private:
- *
- * SpinLock m_lock;
- *
- * public:
- *
- * Bool doSomething( )
- * { SpinLockGuard __guard( m_lock );
- * if ( ?? ) {
- * return false;
- * } else {
- * if ( ?? ) throw ??
- * return true;
- * }
- * }
- * };
- *
- * The lock is automatically released no matter what return path is taken.
- */
-class SpinLockGuard {
- public:
- SpinLockGuard(SpinLock& spinlock) : m_lock(spinlock) { m_lock.acquire(); }
-
- ~SpinLockGuard() { m_lock.release(); }
-
- private:
- SpinLock& m_lock;
-};
-
-// Test function
-CPPCACHE_EXPORT void* testSpinLockCreate();
-CPPCACHE_EXPORT void testSpinLockAcquire(void* lock);
-CPPCACHE_EXPORT void testSpinLockRelease(void* lock);
-} // namespace client
-} // namespace geode
-} // namespace apache
-
-#endif // GEODE_SPINLOCK_H_
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/TcrEndpoint.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/TcrEndpoint.hpp b/src/cppcache/src/TcrEndpoint.hpp
index aa7ecb7..0dc6da5 100644
--- a/src/cppcache/src/TcrEndpoint.hpp
+++ b/src/cppcache/src/TcrEndpoint.hpp
@@ -30,7 +30,6 @@
#include "Set.hpp"
#include "TcrConnection.hpp"
#include "Task.hpp"
-#include "SpinLock.hpp"
namespace apache {
namespace geode {
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/hostsolaris.asm
----------------------------------------------------------------------
diff --git a/src/cppcache/src/hostsolaris.asm b/src/cppcache/src/hostsolaris.asm
index 03ae101..7a12bde 100644
--- a/src/cppcache/src/hostsolaris.asm
+++ b/src/cppcache/src/hostsolaris.asm
@@ -103,86 +103,3 @@ retryAddLong: ! do {
retl
mov %o3,%o0 ! return old value of *ctrPtr in %o0
-/*========================================================================
- *
- * Name - HostAsmUnlock
- *
- * Purpose -
- * Unlock the specified lock.
- *
- *========================================================================
- */
- .proc 16
- .global HostAsmUnlock
- .type HostAsmUnlock, #function
-HostAsmUnlock:
- membar #StoreStore | #LoadStore | #StoreLoad | #LoadLoad
- retl
- st %o0,[%o1] ! store word, 32 bit
-! st %g0,[%o0] ! store word, 32 bit
-
-/*========================================================================
- *
- * Name - HostAsmTryLock
- *
- * bool HostAsmTryLock(SpinLockField *lockPtr, int32_t count, uint32_t lockVal);
- * Purpose -
- * Try to get access to the specified lock. If it succeeds in getting
- * the lock in the number of tries specified in by count,
- * TRUE is returned. If the lock is not available with the count
- * tries, it returns FALSE.
- *
- *========================================================================
- */
- .seg "text"
- .proc 16
- .global HostAsmTryLock
- .type HostAsmTryLock, #function
-HostAsmTryLock:
- ! %o0 = lockPtr
- ! %o1 = count
- ! %o2 = lock value to store
-
- ld [%o0],%o3 ! load *lockPtr
- tst %o3 ! test if 0
- bne spinLoop ! if not 0 we must spin
- mov %o2, %o3 ! branch delay slot, new value into o3
-tryLock:
- ! %o0 = memPtr
- ! %g0 = oldValue (zero)
- ! %o3 = newValue
- ! if (%g0 == *memPtr)
- ! tmp = *memPtr, *memPtr = %o3, %o3 = tmp
- ! else
- ! %o3 = *memPtr
- cas [%o0], %g0, %o3
-
- tst %o3 ! what was value in lock word
- be,a return ! if 0 go to return
- mov 1,%o3 ! set return value
-
-
-
-spinLoop:
- ld [%o0],%o3 ! load *lockPtr
- tst %o3 ! test if 0
- be tryLock ! if 0 we can retry the atomic swap
- mov %o2, %o3 ! branch delay slot, new value into o3
-
- nop ! delay to limit frequency of probing
- nop ! shared memory
- nop
- nop
- nop
-
- dec %o1 ! count--
- tst %o1 ! test count
- bg spinLoop ! count > 0 go to spinLoop
- nop ! branch delay slot
-
- mov 0,%o3 ! fail because count ran out
-
-return:
- membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad
- retl
- add %g0,%o3,%o0 ! move result to %o0 for return
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/cppcache/src/util/concurrent/spinlock_mutex.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/util/concurrent/spinlock_mutex.hpp b/src/cppcache/src/util/concurrent/spinlock_mutex.hpp
new file mode 100644
index 0000000..ab59159
--- /dev/null
+++ b/src/cppcache/src/util/concurrent/spinlock_mutex.hpp
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#ifndef GEODE_UTIL_CONCURRENT_SPINLOCK_MUTEX_H_
+#define GEODE_UTIL_CONCURRENT_SPINLOCK_MUTEX_H_
+
+#include <atomic>
+
+namespace apache {
+namespace geode {
+namespace util {
+namespace concurrent {
+
+class spinlock_mutex final {
+ private:
+ std::atomic_flag flag = ATOMIC_FLAG_INIT;
+
+ public:
+ void lock() {
+ while (flag.test_and_set(std::memory_order_acquire)) continue;
+ }
+
+ void unlock() { flag.clear(std::memory_order_release); }
+
+ spinlock_mutex() = default;
+ spinlock_mutex(const spinlock_mutex &) = delete;
+ spinlock_mutex &operator=(const spinlock_mutex &) = delete;
+};
+
+} /* namespace concurrent */
+} /* namespace util */
+} /* namespace geode */
+} /* namespace apache */
+
+#endif /* GEODE_UTIL_CONCURRENT_SPINLOCK_MUTEX_H_ */
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/tests/cpp/fwk/UdpIpc.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwk/UdpIpc.cpp b/src/tests/cpp/fwk/UdpIpc.cpp
index 983df96..a06679e 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/3305de70/src/tests/cpp/fwklib/FrameworkTest.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/FrameworkTest.cpp b/src/tests/cpp/fwklib/FrameworkTest.cpp
index 83a7948..d2af77f 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;
// ----------------------------------------------------------------------------
@@ -44,7 +50,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();
@@ -244,7 +252,7 @@ void FrameworkTest::cacheInitialize(PropertiesPtr& props,
if (isPdxSerialized) {
cacheFactory->setPdxReadSerialized(isPdxSerialized);
}
- } catch (Exception e) {
+ } catch (Exception& e) {
FWKEXCEPTION(
"DistributedSystem::connect encountered Exception: " << e.getMessage());
}
@@ -255,9 +263,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());
}
@@ -274,7 +282,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());
@@ -533,3 +541,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/3305de70/src/tests/cpp/fwklib/FrameworkTest.hpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/FrameworkTest.hpp b/src/tests/cpp/fwklib/FrameworkTest.hpp
index 5856eee..ccf32e2 100644
--- a/src/tests/cpp/fwklib/FrameworkTest.hpp
+++ b/src/tests/cpp/fwklib/FrameworkTest.hpp
@@ -26,11 +26,15 @@
#include "fwklib/ClientTask.hpp"
#include "fwklib/FwkBBClient.hpp"
+#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;
public:
FrameworkTest(const char* initArgs);
http://git-wip-us.apache.org/repos/asf/geode-native/blob/3305de70/src/tests/cpp/fwklib/GsRandom.cpp
----------------------------------------------------------------------
diff --git a/src/tests/cpp/fwklib/GsRandom.cpp b/src/tests/cpp/fwklib/GsRandom.cpp
index ae1c240..c90a602 100644
--- a/src/tests/cpp/fwklib/GsRandom.cpp
+++ b/src/tests/cpp/fwklib/GsRandom.cpp
@@ -17,13 +17,21 @@
#include "GsRandom.hpp"
-using namespace apache::geode::client;
-using namespace apache::geode::client::testframework;
+#include <cstring>
+#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 +44,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 +124,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/3305de70/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/3305de70/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/3305de70/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: