1
0
Fork 0
forked from lthn/blockchain

guarded other static objects whichg might lead to errors in deinitialization

This commit is contained in:
cryptozoidberg 2020-05-17 23:15:50 +02:00
parent 131f4a8347
commit a4b5af479e
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
7 changed files with 18 additions and 8 deletions

View file

@ -1205,7 +1205,7 @@ namespace log_space
//get_enabled_channels not thread-safe, at the moment leave it like this because it's configured in main, before other threads started
static std::set<std::string>& get_enabled_channels()
{
static std::set<std::string> genabled_channels;
static epee::static_helpers::wrapper<std::set<std::string>> genabled_channels;
return genabled_channels;
}

View file

@ -31,7 +31,7 @@
#pragma once
#include <memory>
#include "static_helpers.h"
template<class owned_object_t>
class abstract_singleton
@ -39,7 +39,7 @@ class abstract_singleton
static std::shared_ptr<owned_object_t> get_set_instance_internal(bool is_need_set = false, owned_object_t* pnew_obj = nullptr)
{
static std::shared_ptr<owned_object_t> val_pobj;
static epee::static_helpers::wrapper<std::shared_ptr<owned_object_t>> val_pobj;
if (is_need_set)
val_pobj.reset(pnew_obj);

View file

@ -33,6 +33,10 @@
#include <boost/thread.hpp>
#include "include_base_utils.h"
#include "auto_val_init.h"
#define DEFINE_SECURE_STATIC_VAR(type, var) static epee::static_helpers::wrapper<type> var##inst; \
static type& var = var##inst;
namespace epee
{
namespace static_helpers

View file

@ -259,14 +259,14 @@ namespace tools
static void handle_signal()
{
static std::mutex m_mutex;
static epee::static_helpers::wrapper<std::mutex> m_mutex;
std::unique_lock<std::mutex> lock(m_mutex);
m_handler();
}
static void handle_fatal_signal(int sig_number, void* address)
{
static std::mutex m_mutex_fatal;
static epee::static_helpers::wrapper<std::mutex> m_mutex_fatal;
std::unique_lock<std::mutex> lock(m_mutex_fatal);
m_fatal_handler(sig_number, address);
uninstall_fatal();

View file

@ -83,7 +83,7 @@ namespace plain_wallet
std::string get_set_working_dir(bool need_to_set = false, const std::string val = "")
{
static std::string working_dir;
DEFINE_SECURE_STATIC_VAR(std::string, working_dir);
if (need_to_set)
working_dir = val;
return working_dir;

View file

@ -513,7 +513,7 @@ void wallets_manager::main_worker(const po::variables_map& m_vm)
{
wo.second.major_stop = true;
wo.second.stop_for_refresh = true;
wo.second.w.unlocked_get()->stop();
wo.second.stop();
if(!dont_save_wallet_at_stop)
wo.second.w->get()->store();
@ -1824,8 +1824,9 @@ void wallets_manager::wallet_vs_options::worker_func()
}
LOG_PRINT_GREEN("[WALLET_HANDLER] Wallet thread thread stopped", LOG_LEVEL_0);
}
wallets_manager::wallet_vs_options::~wallet_vs_options()
void wallets_manager::wallet_vs_options::stop()
{
w.unlocked_get()->stop();
do_mining = false;
major_stop = true;
stop_for_refresh = true;
@ -1833,6 +1834,10 @@ wallets_manager::wallet_vs_options::~wallet_vs_options()
if (miner_thread.joinable())
miner_thread.join();
}
wallets_manager::wallet_vs_options::~wallet_vs_options()
{
stop();
}
std::string wallets_manager::get_wallet_log_prefix(size_t wallet_id) const
{

View file

@ -80,6 +80,7 @@ public:
std::thread miner_thread;
void worker_func();
void stop();
std::string get_log_prefix() const { return std::string("[") + epee::string_tools::num_to_string_fast(wallet_id) + ":" + w->get()->get_log_prefix() + "]"; }
~wallet_vs_options();
};