From b937a2c915861900d047d4d4a24af31c454e3540 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 11 Mar 2016 12:25:28 +0000 Subject: [PATCH] Use boost::thread instead of std::thread and all other associated IPC --- contrib/epee/include/console_handler.h | 16 ++++++++-------- .../epee/include/net/abstract_tcp_server2.h | 6 +++--- .../epee/include/net/abstract_tcp_server2.inl | 4 ++-- contrib/epee/include/syncobj.h | 12 ++++++------ contrib/otshell_utils/lib_common1.hpp | 9 +++++---- contrib/otshell_utils/utils.cpp | 9 +++++---- contrib/otshell_utils/utils.hpp | 12 ++++++------ src/blockchain_db/berkeleydb/db_bdb.cpp | 2 +- src/blockchain_db/berkeleydb/db_bdb.h | 8 ++++---- src/common/util.h | 4 ++-- src/crypto/crypto.cpp | 13 ++++++------- src/crypto/crypto.h | 7 ++++--- src/cryptonote_core/blockchain.cpp | 6 +++--- .../cryptonote_protocol_handler.h | 2 +- src/daemonizer/windows_service.cpp | 4 ++-- src/daemonizer/windows_service_runner.h | 2 +- src/p2p/data_logger.cpp | 18 +++++++++--------- src/p2p/data_logger.hpp | 9 +++++---- src/p2p/net_node.inl | 2 +- src/p2p/network_throttle-detail.cpp | 2 +- src/p2p/network_throttle.cpp | 18 +++++++++--------- src/p2p/network_throttle.hpp | 12 ++++++------ src/simplewallet/simplewallet.cpp | 14 +++++++------- src/simplewallet/simplewallet.h | 6 +++--- src/wallet/wallet2.cpp | 10 +++++----- src/wallet/wallet2.h | 2 +- src/wallet/wallet_errors.h | 1 + 27 files changed, 107 insertions(+), 103 deletions(-) diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h index d76d7930c..95b986ff5 100644 --- a/contrib/epee/include/console_handler.h +++ b/contrib/epee/include/console_handler.h @@ -65,7 +65,7 @@ namespace epee if (state_eos == m_read_status) return false; - std::unique_lock lock(m_response_mutex); + boost::unique_lock lock(m_response_mutex); while (state_init == m_read_status) { m_response_cv.wait(lock); @@ -104,7 +104,7 @@ namespace epee private: bool start_read() { - std::unique_lock lock(m_request_mutex); + boost::unique_lock lock(m_request_mutex); if (!m_run.load(std::memory_order_relaxed) || m_has_read_request) return false; @@ -115,7 +115,7 @@ namespace epee bool wait_read() { - std::unique_lock lock(m_request_mutex); + boost::unique_lock lock(m_request_mutex); while (m_run.load(std::memory_order_relaxed) && !m_has_read_request) { m_request_cv.wait(lock); @@ -188,7 +188,7 @@ namespace epee } else { - std::unique_lock lock(m_response_mutex); + boost::unique_lock lock(m_response_mutex); if (m_run.load(std::memory_order_relaxed)) { m_line = std::move(line); @@ -220,10 +220,10 @@ namespace epee bool m_has_read_request; t_state m_read_status; - std::mutex m_request_mutex; - std::mutex m_response_mutex; - std::condition_variable m_request_cv; - std::condition_variable m_response_cv; + boost::mutex m_request_mutex; + boost::mutex m_response_mutex; + boost::condition_variable m_request_cv; + boost::condition_variable m_response_cv; }; diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h index f3dd7291c..80f3f6db0 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.h +++ b/contrib/epee/include/net/abstract_tcp_server2.h @@ -153,8 +153,8 @@ namespace net_utils // for calculate speed (last 60 sec) network_throttle m_throttle_speed_in; network_throttle m_throttle_speed_out; - std::mutex m_throttle_speed_in_mutex; - std::mutex m_throttle_speed_out_mutex; + boost::mutex m_throttle_speed_in_mutex; + boost::mutex m_throttle_speed_out_mutex; public: void setRpcStation(); @@ -307,7 +307,7 @@ namespace net_utils /// The next connection to be accepted connection_ptr new_connection_; - std::mutex connections_mutex; + boost::mutex connections_mutex; std::deque> connections_; }; // class <>boosted_tcp_server diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl index 4fb6fa75d..698e1947a 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.inl +++ b/contrib/epee/include/net/abstract_tcp_server2.inl @@ -41,7 +41,7 @@ #include #include #include // TODO -#include // TODO +#include // TODO #include "misc_language.h" #include "pragma_comp_defs.h" @@ -294,7 +294,7 @@ PRAGMA_WARNING_DISABLE_VS(4355) if (delay > 0) { long int ms = (long int)(delay * 100); epee::net_utils::data_logger::get_instance().add_data("sleep_down", ms); - std::this_thread::sleep_for(std::chrono::milliseconds(ms)); + boost::this_thread::sleep_for(boost::chrono::milliseconds(ms)); } } while(delay > 0); } // any form of sleeping diff --git a/contrib/epee/include/syncobj.h b/contrib/epee/include/syncobj.h index 0833b4114..8912fc018 100644 --- a/contrib/epee/include/syncobj.h +++ b/contrib/epee/include/syncobj.h @@ -30,11 +30,11 @@ #ifndef __WINH_OBJ_H__ #define __WINH_OBJ_H__ +#include #include #include #include -#include -#include +#include namespace epee { @@ -224,10 +224,10 @@ namespace epee #define SHARED_CRITICAL_REGION_BEGIN(x) { shared_guard critical_region_var(x) #define EXCLUSIVE_CRITICAL_REGION_BEGIN(x) { exclusive_guard critical_region_var(x) -#define CRITICAL_REGION_LOCAL(x) {std::this_thread::sleep_for(std::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep()));} epee::critical_region_t critical_region_var(x) -#define CRITICAL_REGION_BEGIN(x) { std::this_thread::sleep_for(std::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep())); epee::critical_region_t critical_region_var(x) -#define CRITICAL_REGION_LOCAL1(x) {std::this_thread::sleep_for(std::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep()));} epee::critical_region_t critical_region_var1(x) -#define CRITICAL_REGION_BEGIN1(x) { std::this_thread::sleep_for(std::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep())); epee::critical_region_t critical_region_var1(x) +#define CRITICAL_REGION_LOCAL(x) {boost::this_thread::sleep_for(boost::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep()));} epee::critical_region_t critical_region_var(x) +#define CRITICAL_REGION_BEGIN(x) { boost::this_thread::sleep_for(boost::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep())); epee::critical_region_t critical_region_var(x) +#define CRITICAL_REGION_LOCAL1(x) {boost::this_thread::sleep_for(boost::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep()));} epee::critical_region_t critical_region_var1(x) +#define CRITICAL_REGION_BEGIN1(x) { boost::this_thread::sleep_for(boost::chrono::milliseconds(epee::debug::g_test_dbg_lock_sleep())); epee::critical_region_t critical_region_var1(x) #define CRITICAL_REGION_END() } diff --git a/contrib/otshell_utils/lib_common1.hpp b/contrib/otshell_utils/lib_common1.hpp index 456e63fbb..2cb466beb 100644 --- a/contrib/otshell_utils/lib_common1.hpp +++ b/contrib/otshell_utils/lib_common1.hpp @@ -19,9 +19,11 @@ #include #include -#include #include -#include +#include +#include +#include +#include // list of thigs from libraries that we pull into namespace nOT::nNewcli @@ -45,8 +47,7 @@ using std::shared_ptr; \ using std::weak_ptr; \ using std::enable_shared_from_this; \ - using std::mutex; \ - using std::lock_guard; \ + using boost::lock_guard; \ #endif diff --git a/contrib/otshell_utils/utils.cpp b/contrib/otshell_utils/utils.cpp index e1d7d9a14..53cb44dca 100644 --- a/contrib/otshell_utils/utils.cpp +++ b/contrib/otshell_utils/utils.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include "utils.hpp" @@ -128,7 +129,7 @@ std::string get_current_time() { cNullstream g_nullstream; // extern a stream that does nothing (eats/discards data) -std::recursive_mutex gLoggerGuard; // extern +boost::recursive_mutex gLoggerGuard; // extern std::atomic gLoggerGuardDepth; // extern std::atomic & gLoggerGuardDepth_Get() { @@ -302,7 +303,7 @@ mPid2Number_Biggest(0) mIsBroken=false; // ok, constr. succeeded, so string is not broken now // this is here, because it could be using logging itself to log creation of first thread/PID etc - Thread2Number( std::this_thread::get_id() ); // convert current id to short number, useful to reserve a number so that main thread is usually called 1 + Thread2Number( boost::this_thread::get_id() ); // convert current id to short number, useful to reserve a number so that main thread is usually called 1 Pid2Number( getpid() ); // add this proces ID as first one } @@ -347,7 +348,7 @@ std::ostream & cLogger::write_stream(int level, const std::string & channel ) { output << windows_stream(level); #endif output << icon(level) << ' '; - std::thread::id this_id = std::this_thread::get_id(); + boost::thread::id this_id = boost::this_thread::get_id(); output << "{" << Thread2Number(this_id) << "}"; auto nicePid = Pid2Number(getpid()); if (nicePid>0) output << " {p" << nicePid << "}"; @@ -516,7 +517,7 @@ std::string cLogger::endline() const { #endif } -int cLogger::Thread2Number(const std::thread::id id) { +int cLogger::Thread2Number(const boost::thread::id id) { auto found = mThread2Number.find( id ); if (found == mThread2Number.end()) { // new one mThread2Number_Biggest++; diff --git a/contrib/otshell_utils/utils.hpp b/contrib/otshell_utils/utils.hpp index 297f13ac0..98508b565 100644 --- a/contrib/otshell_utils/utils.hpp +++ b/contrib/otshell_utils/utils.hpp @@ -29,7 +29,7 @@ // #define opt_debug_debug #ifdef opt_debug_debug - #define _dbg_dbg(X) do { std::cerr<<"_dbg_dbg: " << OT_CODE_STAMP << " {thread=" << std::this_thread::get_id()<<"} " \ + #define _dbg_dbg(X) do { std::cerr<<"_dbg_dbg: " << OT_CODE_STAMP << " {thread=" << boost::this_thread::get_id()<<"} " \ << " {pid="< & gLoggerGuardDepth_Get(); // getter for the global singleton of counter (it guarantees initializing it to 0). This counter shows the current recursion (re-entrant) level of debug macros. @@ -91,7 +91,7 @@ std::atomic & gLoggerGuardDepth_Get(); // getter for the global singleton o _dbg_dbg("WRITE DEBUG: LEVEL="< mutex_guard( nOT::nUtils::gLoggerGuard ); \ + boost::lock_guard mutex_guard( nOT::nUtils::gLoggerGuard ); \ part=1; \ try { \ ++nOT::nUtils::gLoggerGuardDepth_Get(); \ @@ -111,7 +111,7 @@ std::atomic & gLoggerGuardDepth_Get(); // getter for the global singleton o _dbg_dbg("WRITE DEBUG: LEVEL="< mutex_guard( nOT::nUtils::gLoggerGuard ); \ + boost::lock_guard mutex_guard( nOT::nUtils::gLoggerGuard ); \ part=1; \ try { \ ++nOT::nUtils::gLoggerGuardDepth_Get(); \ @@ -253,9 +253,9 @@ class cLogger { void OpenNewChannel_(const std::string & channel); ///< internal function, will throw in case of problems std::string GetLogBaseDir() const; - std::map< std::thread::id , int > mThread2Number; ///< change long thread IDs into a short nice number to show + std::map< boost::thread::id , int > mThread2Number; ///< change long thread IDs into a short nice number to show int mThread2Number_Biggest; ///< current biggest value held there (biggest key) - works as growing-only counter basically - int Thread2Number(const std::thread::id id); ///< convert the system's thread id into a nice short our id; make one if new thread + int Thread2Number(const boost::thread::id id); ///< convert the system's thread id into a nice short our id; make one if new thread std::map< t_anypid , int > mPid2Number; ///< change long proces PID into a short nice number to show int mPid2Number_Biggest; ///< current biggest value held there (biggest key) - works as growing-only counter basically diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp index bfdb22a10..1fef9e619 100644 --- a/src/blockchain_db/berkeleydb/db_bdb.cpp +++ b/src/blockchain_db/berkeleydb/db_bdb.cpp @@ -135,7 +135,7 @@ const unsigned int DB_BUFFER_LENGTH = 32 * MB; const unsigned int DB_DEF_CACHESIZE = 256 * MB; #if defined(BDB_BULK_CAN_THREAD) -const unsigned int DB_BUFFER_COUNT = std::thread::hardware_concurrency(); +const unsigned int DB_BUFFER_COUNT = boost::thread::hardware_concurrency(); #else const unsigned int DB_BUFFER_COUNT = 1; #endif diff --git a/src/blockchain_db/berkeleydb/db_bdb.h b/src/blockchain_db/berkeleydb/db_bdb.h index bf9665cae..d7cbd24e7 100644 --- a/src/blockchain_db/berkeleydb/db_bdb.h +++ b/src/blockchain_db/berkeleydb/db_bdb.h @@ -130,7 +130,7 @@ public: T acquire_buffer() { - std::unique_lock lock(m_lock); + boost::unique_lock lock(m_lock); m_cv.wait(lock, [&]{ return m_count > 0; }); --m_count; @@ -154,7 +154,7 @@ public: void release_buffer(T buffer) { - std::unique_lock lock(m_lock); + boost::unique_lock lock(m_lock); assert(buffer != nullptr); auto it = m_buffer_map.find(buffer); @@ -196,10 +196,10 @@ private: std::vector m_buffers; std::unordered_map m_buffer_map; - std::condition_variable m_cv; + boost::condition_variable m_cv; std::vector m_open_slot; size_t m_count; - std::mutex m_lock; + boost::mutex m_lock; size_t m_buffer_count; }; diff --git a/src/common/util.h b/src/common/util.h index de0244c7f..7554b1df7 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -150,8 +150,8 @@ namespace tools /*! \brief calles m_handler */ static void handle_signal(int type) { - static std::mutex m_mutex; - std::unique_lock lock(m_mutex); + static boost::mutex m_mutex; + boost::unique_lock lock(m_mutex); m_handler(type); } diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp index fa7b1b580..e47aab0f7 100644 --- a/src/crypto/crypto.cpp +++ b/src/crypto/crypto.cpp @@ -34,7 +34,8 @@ #include #include #include -#include +#include +#include #include "common/varint.h" #include "warnings.h" @@ -52,8 +53,6 @@ namespace crypto { using std::abort; using std::int32_t; using std::int64_t; - using std::lock_guard; - using std::mutex; using std::size_t; using std::uint32_t; using std::uint64_t; @@ -63,7 +62,7 @@ namespace crypto { #include "random.h" } - mutex random_lock; + boost::mutex random_lock; static inline unsigned char *operator &(ec_point &point) { return &reinterpret_cast(point); @@ -100,7 +99,7 @@ namespace crypto { * */ secret_key crypto_ops::generate_keys(public_key &pub, secret_key &sec, const secret_key& recovery_key, bool recover) { - lock_guard lock(random_lock); + boost::lock_guard lock(random_lock); ge_p3 point; secret_key rng; @@ -199,7 +198,7 @@ namespace crypto { }; void crypto_ops::generate_signature(const hash &prefix_hash, const public_key &pub, const secret_key &sec, signature &sig) { - lock_guard lock(random_lock); + boost::lock_guard lock(random_lock); ge_p3 tmp3; ec_scalar k; s_comm buf; @@ -280,7 +279,7 @@ POP_WARNINGS const public_key *const *pubs, size_t pubs_count, const secret_key &sec, size_t sec_index, signature *sig) { - lock_guard lock(random_lock); + boost::lock_guard lock(random_lock); size_t i; ge_p3 image_unp; ge_dsmp image_pre; diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h index 360b571f3..883aa521a 100644 --- a/src/crypto/crypto.h +++ b/src/crypto/crypto.h @@ -31,7 +31,8 @@ #pragma once #include -#include +#include +#include #include #include "common/pod-class.h" @@ -44,7 +45,7 @@ namespace crypto { #include "random.h" } - extern std::mutex random_lock; + extern boost::mutex random_lock; #pragma pack(push, 1) POD_CLASS ec_point { @@ -121,7 +122,7 @@ namespace crypto { template typename std::enable_if::value, T>::type rand() { typename std::remove_cv::type res; - std::lock_guard lock(random_lock); + boost::lock_guard lock(random_lock); generate_random_bytes(sizeof(T), &res); return res; } diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 2aa8ecec4..f540697dc 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -2105,7 +2105,7 @@ bool Blockchain::check_tx_inputs(const transaction& tx, uint64_t* pmax_used_bloc std::vector < uint64_t > results; results.resize(tx.vin.size(), 0); - int threads = std::thread::hardware_concurrency(); + int threads = boost::thread::hardware_concurrency(); boost::asio::io_service ioservice; boost::thread_group threadpool; @@ -2965,7 +2965,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list 1 && threads > 1 && m_max_prepare_blocks_threads > 1) { @@ -3165,7 +3165,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::list> transactions(amounts.size()); - threads = std::thread::hardware_concurrency(); + threads = boost::thread::hardware_concurrency(); if (!m_db->can_thread_bulk_indices()) threads = 1; diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.h b/src/cryptonote_protocol/cryptonote_protocol_handler.h index c2d428025..1c92958c9 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.h +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.h @@ -134,7 +134,7 @@ namespace cryptonote bool m_one_request = true; // static std::ofstream m_logreq; - std::mutex m_buffer_mutex; + boost::mutex m_buffer_mutex; double get_avg_block_size(); boost::circular_buffer m_avg_buffer = boost::circular_buffer(10); diff --git a/src/daemonizer/windows_service.cpp b/src/daemonizer/windows_service.cpp index 88f05a305..f8cc0c6c7 100644 --- a/src/daemonizer/windows_service.cpp +++ b/src/daemonizer/windows_service.cpp @@ -99,8 +99,8 @@ namespace { // to allow the user to read any output. void pause_to_display_admin_window_messages() { - std::chrono::milliseconds how_long{1500}; - std::this_thread::sleep_for(how_long); + boost::chrono::milliseconds how_long{1500}; + boost::this_thread::sleep_for(how_long); } } diff --git a/src/daemonizer/windows_service_runner.h b/src/daemonizer/windows_service_runner.h index 2d21509ec..f4258a215 100644 --- a/src/daemonizer/windows_service_runner.h +++ b/src/daemonizer/windows_service_runner.h @@ -56,7 +56,7 @@ namespace windows { private: SERVICE_STATUS_HANDLE m_status_handle{nullptr}; SERVICE_STATUS m_status{}; - std::mutex m_lock{}; + boost::mutex m_lock{}; std::string m_name; T_handler m_handler; diff --git a/src/p2p/data_logger.cpp b/src/p2p/data_logger.cpp index 7fc85e3bc..ca0726c5f 100644 --- a/src/p2p/data_logger.cpp +++ b/src/p2p/data_logger.cpp @@ -40,7 +40,7 @@ namespace epee namespace net_utils { data_logger &data_logger::get_instance() { - std::call_once(m_singleton, + boost::call_once(m_singleton, [] { _info_c("dbg/data","Creating singleton of data_logger"); if (m_state != data_logger_state::state_before_init) { _erro_c("dbg/data","Internal error in singleton"); throw std::runtime_error("data_logger singleton"); } @@ -61,7 +61,7 @@ namespace net_utils data_logger::data_logger() { _note_c("dbg/data","Starting data logger (for graphs data)"); if (m_state != data_logger_state::state_during_init) { _erro_c("dbg/data","Singleton ctor state"); throw std::runtime_error("data_logger ctor state"); } - std::lock_guard lock(mMutex); // lock + boost::lock_guard lock(mMutex); // lock // prepare all the files for given data channels: mFilesMap["peers"] = data_logger::fileData("log/dr-monero/peers.data"); @@ -89,11 +89,11 @@ namespace net_utils std::shared_ptr logger_thread(new boost::thread([&]() { _info_c("dbg/data","Inside thread for data logger"); while (m_state == data_logger_state::state_during_init) { // wait for creation to be done (in other thread, in singleton) before actually running - std::this_thread::sleep_for(std::chrono::seconds(1)); + boost::this_thread::sleep_for(boost::chrono::seconds(1)); } _info_c("dbg/data","Inside thread for data logger - going into main loop"); while (m_state == data_logger_state::state_ready_to_use) { // run as long as we are not closing the single object - std::this_thread::sleep_for(std::chrono::seconds(1)); + boost::this_thread::sleep_for(boost::chrono::seconds(1)); saveToFile(); // save all the pending data } _info_c("dbg/data","Inside thread for data logger - done the main loop"); @@ -106,12 +106,12 @@ namespace net_utils data_logger::~data_logger() { _note_c("dbg/data","Destructor of the data logger"); { - std::lock_guard lock(mMutex); + boost::lock_guard lock(mMutex); m_state = data_logger_state::state_dying; } _info_c("dbg/data","State was set to dying"); while(m_thread_maybe_running) { // wait for the thread to exit - std::this_thread::sleep_for(std::chrono::seconds(1)); + boost::this_thread::sleep_for(boost::chrono::seconds(1)); _info_c("dbg/data","Waiting for background thread to exit"); } _info_c("dbg/data","Thread exited"); @@ -123,7 +123,7 @@ namespace net_utils } void data_logger::add_data(std::string filename, unsigned int data) { - std::lock_guard lock(mMutex); + boost::lock_guard lock(mMutex); if (m_state != data_logger_state::state_ready_to_use) { _info_c("dbg/data","Data logger is not ready, returning."); return; } if (mFilesMap.find(filename) == mFilesMap.end()) { // no such file/counter @@ -151,7 +151,7 @@ namespace net_utils void data_logger::saveToFile() { _dbg2_c("dbg/data","saving to files"); - std::lock_guard lock(mMutex); + boost::lock_guard lock(mMutex); if (m_state != data_logger_state::state_ready_to_use) { _info_c("dbg/data","Data logger is not ready, returning."); return; } nOT::nUtils::cFilesystemUtils::CreateDirTree("log/dr-monero/net/"); for (auto &element : mFilesMap) @@ -194,7 +194,7 @@ namespace net_utils data_logger_state data_logger::m_state(data_logger_state::state_before_init); ///< (static) state of the singleton object std::atomic data_logger::m_save_graph(false); // (static) std::atomic data_logger::m_thread_maybe_running(false); // (static) -std::once_flag data_logger::m_singleton; // (static) +boost::once_flag data_logger::m_singleton; // (static) std::unique_ptr data_logger::m_obj; // (static) } // namespace diff --git a/src/p2p/data_logger.hpp b/src/p2p/data_logger.hpp index affc97f5f..148afc0ab 100644 --- a/src/p2p/data_logger.hpp +++ b/src/p2p/data_logger.hpp @@ -33,8 +33,9 @@ #include #include #include -#include -#include +#include +#include +#include #include namespace epee @@ -71,7 +72,7 @@ enum class data_logger_state { state_before_init, state_during_init, state_ready static bool is_dying(); private: - static std::once_flag m_singleton; ///< to guarantee singleton creates the object exactly once + static boost::once_flag m_singleton; ///< to guarantee singleton creates the object exactly once static data_logger_state m_state; ///< state of the singleton object static std::atomic m_thread_maybe_running; ///< is the background thread (more or less) running, or is it fully finished static std::unique_ptr m_obj; ///< the singleton object. Only use it via get_instance(). Can be killed by kill_instance() @@ -94,7 +95,7 @@ enum class data_logger_state { state_before_init, state_during_init, state_ready }; std::map mFilesMap; - std::mutex mMutex; + boost::mutex mMutex; void saveToFile(); ///< write data to the target files. do not use this directly }; diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 56717ec66..6278db891 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -585,7 +585,7 @@ namespace nodetool break; epee::net_utils::data_logger::get_instance().add_data("peers", number_of_peers); - std::this_thread::sleep_for(std::chrono::seconds(1)); + boost::this_thread::sleep_for(boost::chrono::seconds(1)); } // main loop of thread _note("Thread monitor number of peers - done"); })); // lambda diff --git a/src/p2p/network_throttle-detail.cpp b/src/p2p/network_throttle-detail.cpp index 54c82dd8d..ed3c8e7b4 100644 --- a/src/p2p/network_throttle-detail.cpp +++ b/src/p2p/network_throttle-detail.cpp @@ -243,7 +243,7 @@ network_time_seconds network_throttle::get_sleep_time_after_tick(size_t packet_s void network_throttle::logger_handle_net(const std::string &filename, double time, size_t size) { if (! epee::net_utils::data_logger::m_save_graph) return; - std::mutex mutex; + boost::mutex mutex; mutex.lock(); { std::fstream file; file.open(filename.c_str(), std::ios::app | std::ios::out ); diff --git a/src/p2p/network_throttle.cpp b/src/p2p/network_throttle.cpp index 42f54964b..30538bb3c 100644 --- a/src/p2p/network_throttle.cpp +++ b/src/p2p/network_throttle.cpp @@ -67,9 +67,9 @@ namespace net_utils // ================================================================================================ // static: -std::mutex network_throttle_manager::m_lock_get_global_throttle_in; -std::mutex network_throttle_manager::m_lock_get_global_throttle_inreq; -std::mutex network_throttle_manager::m_lock_get_global_throttle_out; +boost::mutex network_throttle_manager::m_lock_get_global_throttle_in; +boost::mutex network_throttle_manager::m_lock_get_global_throttle_inreq; +boost::mutex network_throttle_manager::m_lock_get_global_throttle_out; int network_throttle_manager::xxx; @@ -77,27 +77,27 @@ int network_throttle_manager::xxx; // ================================================================================================ // methods: i_network_throttle & network_throttle_manager::get_global_throttle_in() { - std::call_once(m_once_get_global_throttle_in, [] { m_obj_get_global_throttle_in.reset(new network_throttle("in/all","<<< global-IN",10)); } ); + boost::call_once(m_once_get_global_throttle_in, [] { m_obj_get_global_throttle_in.reset(new network_throttle("in/all","<<< global-IN",10)); } ); return * m_obj_get_global_throttle_in; } -std::once_flag network_throttle_manager::m_once_get_global_throttle_in; +boost::once_flag network_throttle_manager::m_once_get_global_throttle_in; std::unique_ptr network_throttle_manager::m_obj_get_global_throttle_in; i_network_throttle & network_throttle_manager::get_global_throttle_inreq() { - std::call_once(m_once_get_global_throttle_inreq, [] { m_obj_get_global_throttle_inreq.reset(new network_throttle("inreq/all", "<== global-IN-REQ",10)); } ); + boost::call_once(m_once_get_global_throttle_inreq, [] { m_obj_get_global_throttle_inreq.reset(new network_throttle("inreq/all", "<== global-IN-REQ",10)); } ); return * m_obj_get_global_throttle_inreq; } -std::once_flag network_throttle_manager::m_once_get_global_throttle_inreq; +boost::once_flag network_throttle_manager::m_once_get_global_throttle_inreq; std::unique_ptr network_throttle_manager::m_obj_get_global_throttle_inreq; i_network_throttle & network_throttle_manager::get_global_throttle_out() { - std::call_once(m_once_get_global_throttle_out, [] { m_obj_get_global_throttle_out.reset(new network_throttle("out/all", ">>> global-OUT",10)); } ); + boost::call_once(m_once_get_global_throttle_out, [] { m_obj_get_global_throttle_out.reset(new network_throttle("out/all", ">>> global-OUT",10)); } ); return * m_obj_get_global_throttle_out; } -std::once_flag network_throttle_manager::m_once_get_global_throttle_out; +boost::once_flag network_throttle_manager::m_once_get_global_throttle_out; std::unique_ptr network_throttle_manager::m_obj_get_global_throttle_out; diff --git a/src/p2p/network_throttle.hpp b/src/p2p/network_throttle.hpp index 6135ed72b..b954c5b3a 100644 --- a/src/p2p/network_throttle.hpp +++ b/src/p2p/network_throttle.hpp @@ -113,16 +113,16 @@ class network_throttle_manager { //protected: public: // XXX // [[note1]] - static std::once_flag m_once_get_global_throttle_in; - static std::once_flag m_once_get_global_throttle_inreq; // [[note2]] - static std::once_flag m_once_get_global_throttle_out; + static boost::once_flag m_once_get_global_throttle_in; + static boost::once_flag m_once_get_global_throttle_inreq; // [[note2]] + static boost::once_flag m_once_get_global_throttle_out; static std::unique_ptr m_obj_get_global_throttle_in; static std::unique_ptr m_obj_get_global_throttle_inreq; static std::unique_ptr m_obj_get_global_throttle_out; - static std::mutex m_lock_get_global_throttle_in; - static std::mutex m_lock_get_global_throttle_inreq; - static std::mutex m_lock_get_global_throttle_out; + static boost::mutex m_lock_get_global_throttle_in; + static boost::mutex m_lock_get_global_throttle_inreq; + static boost::mutex m_lock_get_global_throttle_out; friend class cryptonote::cryptonote_protocol_handler_base; // FRIEND - to directly access global throttle-s. !! REMEMBER TO USE LOCKS! friend class connection_basic; // FRIEND - to directly access global throttle-s. !! REMEMBER TO USE LOCKS! diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 65508b9d5..3e5cdfcb6 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -445,7 +445,7 @@ bool simple_wallet::set_auto_refresh(const std::vector &args/* = st if (auto_refresh && !m_auto_refresh_run.load(std::memory_order_relaxed)) { m_auto_refresh_run.store(true, std::memory_order_relaxed); - m_auto_refresh_thread = std::thread([&]{wallet_refresh_thread();}); + m_auto_refresh_thread = boost::thread([&]{wallet_refresh_thread();}); } else if (!auto_refresh && m_auto_refresh_run.load(std::memory_order_relaxed)) { @@ -1256,7 +1256,7 @@ bool simple_wallet::close_wallet() m_auto_refresh_run.store(false, std::memory_order_relaxed); m_wallet->stop(); { - std::unique_lock lock(m_auto_refresh_mutex); + boost::unique_lock lock(m_auto_refresh_mutex); m_auto_refresh_cond.notify_one(); } m_auto_refresh_thread.join(); @@ -1341,7 +1341,7 @@ bool simple_wallet::start_mining(const std::vector& args) req.miner_address = m_wallet->get_account().get_public_address_str(m_wallet->testnet()); bool ok = true; - size_t max_mining_threads_count = (std::max)(std::thread::hardware_concurrency(), static_cast(2)); + size_t max_mining_threads_count = (std::max)(boost::thread::hardware_concurrency(), static_cast(2)); if (0 == args.size()) { req.threads_count = 1; @@ -1458,7 +1458,7 @@ bool simple_wallet::refresh_main(uint64_t start_height, bool reset) m_auto_refresh_run.store(false, std::memory_order_relaxed); // stop any background refresh, and take over m_wallet->stop(); - std::unique_lock lock(m_auto_refresh_mutex); + boost::unique_lock lock(m_auto_refresh_mutex); m_auto_refresh_cond.notify_one(); if (reset) @@ -2434,7 +2434,7 @@ void simple_wallet::wallet_refresh_thread() { while (true) { - std::unique_lock lock(m_auto_refresh_mutex); + boost::unique_lock lock(m_auto_refresh_mutex); if (!m_auto_refresh_run.load(std::memory_order_relaxed)) break; m_auto_refresh_refreshing = true; @@ -2447,7 +2447,7 @@ void simple_wallet::wallet_refresh_thread() m_auto_refresh_refreshing = false; if (!m_auto_refresh_run.load(std::memory_order_relaxed)) break; - m_auto_refresh_cond.wait_for(lock, chrono::seconds(90)); + m_auto_refresh_cond.wait_for(lock, boost::chrono::seconds(90)); } } //---------------------------------------------------------------------------------------------------- @@ -2457,7 +2457,7 @@ bool simple_wallet::run() m_auto_refresh_run = m_wallet->auto_refresh(); if (m_auto_refresh_run) { - m_auto_refresh_thread = std::thread([&]{wallet_refresh_thread();}); + m_auto_refresh_thread = boost::thread([&]{wallet_refresh_thread();}); } else { diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index 5dac60447..d1617dbf4 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -242,9 +242,9 @@ namespace cryptonote std::atomic m_auto_refresh_run; bool m_auto_refresh_refreshing; - std::thread m_auto_refresh_thread; - std::mutex m_auto_refresh_mutex; - std::condition_variable m_auto_refresh_cond; + boost::thread m_auto_refresh_thread; + boost::mutex m_auto_refresh_mutex; + boost::condition_variable m_auto_refresh_cond; std::atomic m_in_manual_refresh; }; } diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index a86f2ffdf..389286ceb 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -204,7 +204,7 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_ tx_pub_key = pub_key_field.pub_key; bool r = true; - int threads = std::thread::hardware_concurrency(); + int threads = boost::thread::hardware_concurrency(); if (miner_tx && m_refresh_type == RefreshNoCoinbase) { // assume coinbase isn't for us @@ -574,7 +574,7 @@ void wallet2::process_blocks(uint64_t start_height, const std::list 1) { std::vector round_block_hashes(threads); @@ -771,7 +771,7 @@ void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& re size_t try_count = 0; crypto::hash last_tx_hash_id = m_transfers.size() ? get_transaction_hash(m_transfers.back().m_tx) : null_hash; std::list short_chain_history; - std::thread pull_thread; + boost::thread pull_thread; uint64_t blocks_start_height; std::list blocks; @@ -788,7 +788,7 @@ void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& re uint64_t next_blocks_start_height; std::list next_blocks; bool error = false; - pull_thread = std::thread([&]{pull_next_blocks(start_height, next_blocks_start_height, short_chain_history, blocks, next_blocks, error);}); + pull_thread = boost::thread([&]{pull_next_blocks(start_height, next_blocks_start_height, short_chain_history, blocks, next_blocks, error);}); process_blocks(blocks_start_height, blocks, added_blocks); blocks_fetched += added_blocks; @@ -1312,7 +1312,7 @@ bool wallet2::prepare_file_names(const std::string& file_path) //---------------------------------------------------------------------------------------------------- bool wallet2::check_connection() { - std::lock_guard lock(m_daemon_rpc_mutex); + boost::lock_guard lock(m_daemon_rpc_mutex); if(m_http_client.is_connected()) return true; diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index ceeef492e..c79da2e15 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -407,7 +407,7 @@ namespace tools std::atomic m_run; - std::mutex m_daemon_rpc_mutex; + boost::mutex m_daemon_rpc_mutex; i_wallet2_callback* m_callback; bool m_testnet; diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h index 10d27651f..80482c1ba 100644 --- a/src/wallet/wallet_errors.h +++ b/src/wallet/wallet_errors.h @@ -31,6 +31,7 @@ #pragma once #include +#include #include #include