diff --git a/retesteth/Options.cpp b/retesteth/Options.cpp index a4d51cd45..8770bff75 100644 --- a/retesteth/Options.cpp +++ b/retesteth/Options.cpp @@ -27,6 +27,7 @@ #include #include #include +#include using namespace std; using namespace test; @@ -475,6 +476,9 @@ Options::Options(int argc, const char** argv) BOOST_THROW_EXCEPTION( InvalidOption("--seed could be used only with --createRandomTest \n")); } + + if (threadCount == 1) + dataobject::GCP_SPointer::DISABLETHREADSAFE(); } Options const& Options::get(int argc, const char** argv) diff --git a/retesteth/dataObject/SPointer.cpp b/retesteth/dataObject/SPointer.cpp index e0c69a062..5132a5b25 100644 --- a/retesteth/dataObject/SPointer.cpp +++ b/retesteth/dataObject/SPointer.cpp @@ -2,28 +2,43 @@ #include #include - namespace dataobject { +bool G_IS_THREADSAFE = true; +std::mutex GCP_SPointerBase::g_spRefAccessMutex; + +void disableThreadsafe() +{ + G_IS_THREADSAFE = false; +} + // To debug exceptions as breakpoints does not work from header void throwException(std::string const& _ex) { throw SPointerException(_ex); } -std::mutex g_spMutexAdd; -std::mutex g_spMutexDel; void GCP_SPointerBase::AddRef() { // very heavy. use thread unsafe pointer preferably - std::lock_guard lock(g_spMutexAdd); - _nRef++; + if (G_IS_THREADSAFE) + { + std::lock_guard lock(g_spRefAccessMutex); + _nRef++; + } + else + _nRef++; } int GCP_SPointerBase::DelRef() { - std::lock_guard lock(g_spMutexDel); - _nRef--; + if (G_IS_THREADSAFE) + { + std::lock_guard lock(g_spRefAccessMutex); + _nRef--; + } + else + _nRef--; return _nRef; } diff --git a/retesteth/dataObject/SPointer.h b/retesteth/dataObject/SPointer.h index d9129aee4..8505d7a52 100644 --- a/retesteth/dataObject/SPointer.h +++ b/retesteth/dataObject/SPointer.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include namespace dataobject { @@ -25,6 +26,7 @@ struct SPointerException : virtual std::exception }; void throwException(std::string const& _ex); +void disableThreadsafe(); template class GCP_SPointer; @@ -35,6 +37,8 @@ class GCP_SPointerBase bool _isEmpty; void AddRef(); int DelRef(); + static std::mutex g_spRefAccessMutex; + public: GCP_SPointerBase() : _nRef(0), _isEmpty(false) {} @@ -66,6 +70,7 @@ class GCP_SPointer } public: + static void DISABLETHREADSAFE() { disableThreadsafe(); }; explicit GCP_SPointer() : _pointee(nullptr) {} GCP_SPointer(int) : _pointee(nullptr) {} explicit GCP_SPointer(T* pointee)