From d59495110dc5d4924b43926d33c5d29b0103d0e0 Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Thu, 12 Oct 2017 22:28:35 +0100 Subject: [PATCH 1/2] Make sure all singletons are set to null and make env a global ptr --- xmrstak/backend/amd/minethd.cpp | 2 +- xmrstak/backend/nvidia/minethd.cpp | 2 +- xmrstak/misc/environment.hpp | 41 +++++++++++++----------------- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/xmrstak/backend/amd/minethd.cpp b/xmrstak/backend/amd/minethd.cpp index 84f0055..5ca10d3 100644 --- a/xmrstak/backend/amd/minethd.cpp +++ b/xmrstak/backend/amd/minethd.cpp @@ -65,7 +65,7 @@ __declspec(dllexport) #endif std::vector* xmrstak_start_backend(uint32_t threadOffset, miner_work& pWork, environment& env) { - environment::inst() = env; + environment::inst(&env); return amd::minethd::thread_starter(threadOffset, pWork); } } // extern "C" diff --git a/xmrstak/backend/nvidia/minethd.cpp b/xmrstak/backend/nvidia/minethd.cpp index a4aa519..fcd01cd 100644 --- a/xmrstak/backend/nvidia/minethd.cpp +++ b/xmrstak/backend/nvidia/minethd.cpp @@ -112,7 +112,7 @@ __declspec(dllexport) #endif std::vector* xmrstak_start_backend(uint32_t threadOffset, miner_work& pWork, environment& env) { - environment::inst() = env; + environment::inst(&env); return nvidia::minethd::thread_starter(threadOffset, pWork); } } // extern "C" diff --git a/xmrstak/misc/environment.hpp b/xmrstak/misc/environment.hpp index 6140d7d..87c512a 100644 --- a/xmrstak/misc/environment.hpp +++ b/xmrstak/misc/environment.hpp @@ -12,35 +12,30 @@ class params; struct environment { + static inline environment& inst(environment* init = nullptr) + { + static environment* env = nullptr; - static environment& inst() - { - static environment env; - return env; - } - - environment& operator=(const environment& env) - { - this->pPrinter = env.pPrinter; - this->pglobalStates = env.pglobalStates; - this->pJconfConfig = env.pJconfConfig; - this->pExecutor = env.pExecutor; - this->pParams = env.pParams; - return *this; + if(env == nullptr) + { + if(init != nullptr) + env = new environment; + else + env = init; + } + + return *env; } - - environment() : pPrinter(nullptr), pglobalStates(nullptr) + environment() { } - - printer* pPrinter; - globalStates* pglobalStates; - jconf* pJconfConfig; - executor* pExecutor; - params* pParams; - + printer* pPrinter = nullptr; + globalStates* pglobalStates = nullptr; + jconf* pJconfConfig = nullptr; + executor* pExecutor = nullptr; + params* pParams = nullptr; }; } // namepsace xmrstak From 76aa1678477f6b1ac90977ff80f0b4b7237f75cf Mon Sep 17 00:00:00 2001 From: fireice-uk Date: Fri, 13 Oct 2017 17:13:44 +0100 Subject: [PATCH 2/2] doh! != instead of == --- xmrstak/misc/environment.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmrstak/misc/environment.hpp b/xmrstak/misc/environment.hpp index 87c512a..cd3ce9a 100644 --- a/xmrstak/misc/environment.hpp +++ b/xmrstak/misc/environment.hpp @@ -18,7 +18,7 @@ struct environment if(env == nullptr) { - if(init != nullptr) + if(init == nullptr) env = new environment; else env = init;