From 7899bef457e56f6d4934a312f532ef6021feddf5 Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 11 May 2020 22:21:45 -0400 Subject: [PATCH] replace sync_loop_func() with lambda --- src/wallet/monero_wallet_core.cpp | 40 ++++++++++++++----------------- src/wallet/monero_wallet_core.h | 1 - 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/wallet/monero_wallet_core.cpp b/src/wallet/monero_wallet_core.cpp index 6caf60b..b2f8787 100644 --- a/src/wallet/monero_wallet_core.cpp +++ b/src/wallet/monero_wallet_core.cpp @@ -3308,31 +3308,27 @@ namespace monero { // start sync loop thread m_syncing_thread = boost::thread([this]() { - this->sync_loop_func(); + + // sync while enabled + while (m_syncing_enabled) { + try { + lock_and_sync(); + } catch (...) { + cout << "monero_wallet_core failed to background synchronize" << endl; + } + + // only wait if syncing still enabled + if (m_syncing_enabled) { + boost::mutex::scoped_lock lock(m_syncing_mutex); + boost::posix_time::milliseconds wait_for_ms(m_syncing_interval.load()); + m_sync_cv.timed_wait(lock, wait_for_ms); + } + } + + m_sync_loop_running = false; }); } - void monero_wallet_core::sync_loop_func() { - - // sync while enabled - while (m_syncing_enabled) { - try { - lock_and_sync(); - } catch (...) { - cout << "monero_wallet_core failed to background synchronize" << endl; - } - - // only wait if syncing still enabled - if (m_syncing_enabled) { - boost::mutex::scoped_lock lock(m_syncing_mutex); - boost::posix_time::milliseconds wait_for_ms(m_syncing_interval.load()); - m_sync_cv.timed_wait(lock, wait_for_ms); - } - } - - m_sync_loop_running = false; - } - monero_sync_result monero_wallet_core::lock_and_sync(boost::optional start_height) { bool rescan = m_rescan_on_sync.exchange(false); boost::lock_guard guarg(m_sync_mutex); // synchronize sync() and syncAsync() diff --git a/src/wallet/monero_wallet_core.h b/src/wallet/monero_wallet_core.h index aedfc6b..066cf95 100644 --- a/src/wallet/monero_wallet_core.h +++ b/src/wallet/monero_wallet_core.h @@ -316,7 +316,6 @@ namespace monero { boost::thread m_syncing_thread; // thread for auto sync loop boost::mutex m_syncing_mutex; // synchronize auto sync loop void run_sync_loop(); // run the sync loop in a thread - void sync_loop_func(); // function to run thread with syncing loop monero_sync_result lock_and_sync(boost::optional start_height = boost::none); // internal function to synchronize request to sync and rescan monero_sync_result sync_aux(boost::optional start_height = boost::none); // internal function to immediately block, sync, and report progress };