From ceb30464d3839e2ed1c7921733a9a861b71f44d4 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 13 Jan 2022 14:10:53 +0100 Subject: [PATCH 01/13] added missing command line argument for deeplinks under windows/linux --- utils/Zano.sh | 2 +- utils/setup_64.iss | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/Zano.sh b/utils/Zano.sh index e0eac8cc..6e4d22d8 100755 --- a/utils/Zano.sh +++ b/utils/Zano.sh @@ -29,7 +29,7 @@ create_desktop_icon() echo GenericName=Zano | tee -a $target_file_name > /dev/null echo Comment=Privacy blockchain | tee -a $target_file_name > /dev/null echo Icon=$script_dir/html/files/desktop_linux_icon.png | tee -a $target_file_name > /dev/null - echo Exec=$script_dir/Zano.sh %u | tee -a $target_file_name > /dev/null + echo Exec=$script_dir/Zano.sh --deeplink-params=%u | tee -a $target_file_name > /dev/null echo Terminal=true | tee -a $target_file_name > /dev/null echo Type=Application | tee -a $target_file_name > /dev/null echo "Categories=Qt;Utility;" | tee -a $target_file_name > /dev/null diff --git a/utils/setup_64.iss b/utils/setup_64.iss index adee27a8..364a9767 100644 --- a/utils/setup_64.iss +++ b/utils/setup_64.iss @@ -53,7 +53,7 @@ Root: HKCR; Subkey: "ZanoWalletDataFile\DefaultIcon"; ValueType: string; ValueNa Root: HKCR; Subkey: "ZanoWalletDataKyesFile\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\Zano.exe,0" Root: HKCR; Subkey: "Zano"; ValueType: string; ValueName: "URL Protocol"; ValueData: "" -Root: HKCR; Subkey: "Zano\shell\open\command"; ValueType: string; ValueName: ""; ValueData: "{app}\Zano.exe %1" +Root: HKCR; Subkey: "Zano\shell\open\command"; ValueType: string; ValueName: ""; ValueData: "{app}\Zano.exe --deeplink-params=%1" [Files] From cd644cc8513f0a347c776d1740b80d1f7304ae86 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 13 Jan 2022 18:56:49 +0100 Subject: [PATCH 02/13] added preventive removal of ipc channel --- src/gui/qt-daemon/application/mainwindow.cpp | 19 +++++++++++++++++-- src/gui/qt-daemon/application/mainwindow.h | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 0c0ce687..445acb10 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -744,11 +744,25 @@ void qt_log_message_handler(QtMsgType type, const QMessageLogContext &context, c } } +bool MainWindow::remove_ipc() +{ + try { + boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME); + } + catch (...) + { + } + return true; +} bool MainWindow::init_ipc_server() { + //in case previous instance wasn't close graceful, ipc channel will remain open and new creation will fail, so we + //trying to close it anyway before open, to make sure there are no dead channels. If there are another running instance, it wom't + //let channel to close, so it will fail later on creating channel + remove_ipc(); #define GUI_IPC_BUFFER_SIZE 10000 try { //Create a message queue. @@ -775,18 +789,19 @@ bool MainWindow::init_ipc_server() handle_ipc_event(buff);//todo process token } } - boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME); + remove_ipc(); LOG_PRINT_L0("IPC Handling thread finished"); } catch (const std::exception& ex) { + remove_ipc(); boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME); LOG_ERROR("Failed to receive IPC que: " << ex.what()); } catch (...) { - boost::interprocess::message_queue::remove(GUI_IPC_MESSAGE_CHANNEL_NAME); + remove_ipc(); LOG_ERROR("Failed to receive IPC que: unknown exception"); } }); diff --git a/src/gui/qt-daemon/application/mainwindow.h b/src/gui/qt-daemon/application/mainwindow.h index 974b0bea..4f7af71d 100644 --- a/src/gui/qt-daemon/application/mainwindow.h +++ b/src/gui/qt-daemon/application/mainwindow.h @@ -240,6 +240,7 @@ private: bool load_app_config(); bool init_window(); bool init_ipc_server(); + bool remove_ipc(); std::string get_wallet_log_prefix(size_t wallet_id) const { return m_backend.get_wallet_log_prefix(wallet_id); } From 50392b9e312ec187784439c652995056d34f3f7e Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 18 Jan 2022 18:19:18 +0100 Subject: [PATCH 03/13] fixed bug with crashing message box --- src/gui/qt-daemon/application/mainwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 445acb10..5c00dbfc 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -825,8 +825,8 @@ bool MainWindow::init_ipc_server() bool MainWindow::handle_ipc_event(const std::string& arguments) { - std::string zzz = "Received IPC: " + arguments; - message_box(zzz.c_str()); + std::string zzz = "Received IPC: " + arguments.c_str(); + std::cout << zzz;//message_box(zzz.c_str()); handle_deeplink_click(arguments.c_str()); From b7a42895a1f55aebb17dc9429c9426aeeb6130ae Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 18 Jan 2022 18:48:36 +0100 Subject: [PATCH 04/13] fixed fixing fix --- src/gui/qt-daemon/application/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index 5c00dbfc..d760c2d1 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -825,7 +825,7 @@ bool MainWindow::init_ipc_server() bool MainWindow::handle_ipc_event(const std::string& arguments) { - std::string zzz = "Received IPC: " + arguments.c_str(); + std::string zzz = std::string("Received IPC: ") + arguments.c_str(); std::cout << zzz;//message_box(zzz.c_str()); handle_deeplink_click(arguments.c_str()); From 9ef3c81f659688643ff6d9fbdb181f4331eec01c Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 26 Jan 2022 15:24:31 +0100 Subject: [PATCH 05/13] moved ui to latest commit --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 93802cb8..412a89eb 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 93802cb8fe1c79daf320aa4b72ba454d27da31d7 +Subproject commit 412a89eb100e3fa81c0e45e3a4f6270992eded38 From d423f465a1a2f44890161aae1bcd9f7989043fa0 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 27 Jan 2022 15:30:50 +0100 Subject: [PATCH 06/13] Fixed WRONG_PASSWORD error in UI --- src/gui/qt-daemon/application/mainwindow.cpp | 1 + src/gui/qt-daemon/layout | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/application/mainwindow.cpp b/src/gui/qt-daemon/application/mainwindow.cpp index d760c2d1..df242aff 100644 --- a/src/gui/qt-daemon/application/mainwindow.cpp +++ b/src/gui/qt-daemon/application/mainwindow.cpp @@ -786,6 +786,7 @@ bool MainWindow::init_ipc_server() bool data_received = pmq->timed_receive((void*)buff.data(), GUI_IPC_BUFFER_SIZE, recvd_size, priority, boost::posix_time::ptime(boost::posix_time::microsec_clock::universal_time()) + boost::posix_time::milliseconds(1000)); if (data_received && recvd_size != 0) { + buff.resize(recvd_size, '*'); handle_ipc_event(buff);//todo process token } } diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 412a89eb..02e277cb 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 412a89eb100e3fa81c0e45e3a4f6270992eded38 +Subproject commit 02e277cbda5c9b40f8bb445fb2f6b87a3a780431 From 6bfa257cfccba132dee8353e9905563341c23582 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 31 Jan 2022 15:10:05 +0100 Subject: [PATCH 07/13] Moved UI to latest commit --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 02e277cb..b42ef6a6 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 02e277cbda5c9b40f8bb445fb2f6b87a3a780431 +Subproject commit b42ef6a638616872c00f27780937e8a01a4d3539 From ad4b652e93030de85eea07126cb7443c34710649 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 2 Feb 2022 14:48:35 +0100 Subject: [PATCH 08/13] moved UI to latest commit with fixes --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index b42ef6a6..fdc3e748 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit b42ef6a638616872c00f27780937e8a01a4d3539 +Subproject commit fdc3e748d4e0014e5652031c7603ec00b45803fa From be318d6ed4f4db048a2c58c41c66a78789e17f27 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 4 Feb 2022 22:15:59 +0100 Subject: [PATCH 09/13] threads pool: inital code + unit tests dummy --- src/common/threads_pool.h | 102 +++++++++++++++++++ tests/performance_tests/main.cpp | 30 +++--- tests/performance_tests/threads_pool_tests.h | 15 +++ 3 files changed, 134 insertions(+), 13 deletions(-) create mode 100644 src/common/threads_pool.h create mode 100644 tests/performance_tests/threads_pool_tests.h diff --git a/src/common/threads_pool.h b/src/common/threads_pool.h new file mode 100644 index 00000000..b30e7b57 --- /dev/null +++ b/src/common/threads_pool.h @@ -0,0 +1,102 @@ +// Copyright (c) 2014-2019 Zano Project +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once + +#include +#include +#include + +namespace utils +{ + + struct call_executor_base + { + virtual void execute()=0; + }; + + template + struct call_executor_t : public call_executor_base + { + call_executor_t(t_executor_func f) :m_func(f) + {} + t_executor_func m_func; + virtual void execute() + { + m_func(); + } + }; + + template + std::shared_ptr build_call_executor(t_executor_func func) + { + std::shared_ptr res = new call_executor_t(func); + return res; + } + + class threads_pool + { + void init() + { + m_is_stop = false; + int num_threads = std::thread::hardware_concurrency(); + + for (int i = 0; i < num_threads; i++) + { + m_threads.push_back(std::thread(worker_func)); + } + } + + threads_pool(): m_is_stop(false), m_threads_counter(0) + {} + + template + bool add_job(t_executor_func func) + { + { + std::unique_lock lock(m_queue_mutex); + m_jobs_que.push_back(build_call_executor(func)); + } + m_condition.notify_one(); + return true; + } + + private: + void worker_func() + { + LOG_PRINT_L0("Worker thread is started"); + while (true) + { + std::shared_ptr job; + { + std::unique_lock lock(m_queue_mutex); + + m_condition.wait(lock, [this]() + { + return !m_jobs_que.empty() || m_is_stop; + }); + if (m_is_stop) + { + LOG_PRINT_L0("Worker thread is finished"); + return; + } + + job = m_jobs_que.front(); + m_jobs_que.pop_front(); + } + + job->execute(); + } + } + + + + std::list> m_jobs_que; + std::condition_variable m_condition; + std::mutex m_queue_mutex; + std::vector m_threads; + atomic m_is_stop; + std::atomic m_threads_counter; + }; +} \ No newline at end of file diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index c3f0a77a..e8d7a2ed 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -23,6 +23,8 @@ #include "print_struct_to_json.h" #include "free_space_check.h" #include "htlc_hash_tests.h" +#include "threads_pool_tests.h" + int main(int argc, char** argv) { @@ -33,21 +35,23 @@ int main(int argc, char** argv) epee::log_space::log_singletone::get_default_log_file().c_str(), epee::log_space::log_singletone::get_default_log_folder().c_str()); - - std::string buf1 = tools::get_varint_data(CURRENCY_PUBLIC_ADDRESS_BASE58_PREFIX); - std::string buf2 = tools::get_varint_data(CURRENCY_PUBLIC_INTEG_ADDRESS_BASE58_PREFIX); - std::string buf3 = tools::get_varint_data(CURRENCY_PUBLIC_INTEG_ADDRESS_V2_BASE58_PREFIX); - std::string buf4 = tools::get_varint_data(CURRENCY_PUBLIC_AUDITABLE_ADDRESS_BASE58_PREFIX); - std::string buf5 = tools::get_varint_data(CURRENCY_PUBLIC_AUDITABLE_INTEG_ADDRESS_BASE58_PREFIX); - std::cout << "Buf1: " << epee::string_tools::buff_to_hex_nodelimer(buf1) << ENDL; - std::cout << "Buf2: " << epee::string_tools::buff_to_hex_nodelimer(buf2) << ENDL; - std::cout << "Buf3: " << epee::string_tools::buff_to_hex_nodelimer(buf3) << ENDL; - std::cout << "Buf4: " << epee::string_tools::buff_to_hex_nodelimer(buf4) << ENDL; - std::cout << "Buf5: " << epee::string_tools::buff_to_hex_nodelimer(buf5) << ENDL; + thread_pool_tests(); - - do_htlc_hash_tests(); +// std::string buf1 = tools::get_varint_data(CURRENCY_PUBLIC_ADDRESS_BASE58_PREFIX); +// std::string buf2 = tools::get_varint_data(CURRENCY_PUBLIC_INTEG_ADDRESS_BASE58_PREFIX); +// std::string buf3 = tools::get_varint_data(CURRENCY_PUBLIC_INTEG_ADDRESS_V2_BASE58_PREFIX); +// std::string buf4 = tools::get_varint_data(CURRENCY_PUBLIC_AUDITABLE_ADDRESS_BASE58_PREFIX); +// std::string buf5 = tools::get_varint_data(CURRENCY_PUBLIC_AUDITABLE_INTEG_ADDRESS_BASE58_PREFIX); +// +// std::cout << "Buf1: " << epee::string_tools::buff_to_hex_nodelimer(buf1) << ENDL; +// std::cout << "Buf2: " << epee::string_tools::buff_to_hex_nodelimer(buf2) << ENDL; +// std::cout << "Buf3: " << epee::string_tools::buff_to_hex_nodelimer(buf3) << ENDL; +// std::cout << "Buf4: " << epee::string_tools::buff_to_hex_nodelimer(buf4) << ENDL; +// std::cout << "Buf5: " << epee::string_tools::buff_to_hex_nodelimer(buf5) << ENDL; +// +// + //do_htlc_hash_tests(); //run_serialization_performance_test(); //return 1; //run_core_market_performance_tests(100000); diff --git a/tests/performance_tests/threads_pool_tests.h b/tests/performance_tests/threads_pool_tests.h new file mode 100644 index 00000000..2494dae8 --- /dev/null +++ b/tests/performance_tests/threads_pool_tests.h @@ -0,0 +1,15 @@ +// Copyright (c) 2019 The Zano developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once + +#include +#include "include_base_utils.h" +#include "threads_pool.h" + + +inline +void thread_pool_tests() +{ +} \ No newline at end of file From e2bb37e5cb941d2f8700cf2f62f890e7b3916860 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 8 Feb 2022 13:59:09 +0100 Subject: [PATCH 10/13] added tests for threads pool --- src/common/threads_pool.h | 23 +++++++++++++++----- tests/performance_tests/threads_pool_tests.h | 19 +++++++++++++++- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/common/threads_pool.h b/src/common/threads_pool.h index b30e7b57..b1d4aebc 100644 --- a/src/common/threads_pool.h +++ b/src/common/threads_pool.h @@ -16,7 +16,7 @@ namespace utils virtual void execute()=0; }; - template + template struct call_executor_t : public call_executor_base { call_executor_t(t_executor_func f) :m_func(f) @@ -28,15 +28,16 @@ namespace utils } }; - template + template std::shared_ptr build_call_executor(t_executor_func func) { - std::shared_ptr res = new call_executor_t(func); + std::shared_ptr res(static_cast(new call_executor_t(func))); return res; } class threads_pool { + public: void init() { m_is_stop = false; @@ -44,14 +45,14 @@ namespace utils for (int i = 0; i < num_threads; i++) { - m_threads.push_back(std::thread(worker_func)); + m_threads.push_back(std::thread([this](){this->worker_func(); })); } } threads_pool(): m_is_stop(false), m_threads_counter(0) {} - template + template bool add_job(t_executor_func func) { { @@ -62,6 +63,16 @@ namespace utils return true; } + ~threads_pool() + { + m_is_stop = true; + m_condition.notify_all(); + for (auto& th : m_threads) + { + th.join(); + } + } + private: void worker_func() { @@ -96,7 +107,7 @@ namespace utils std::condition_variable m_condition; std::mutex m_queue_mutex; std::vector m_threads; - atomic m_is_stop; + std::atomic m_is_stop; std::atomic m_threads_counter; }; } \ No newline at end of file diff --git a/tests/performance_tests/threads_pool_tests.h b/tests/performance_tests/threads_pool_tests.h index 2494dae8..a1bf2042 100644 --- a/tests/performance_tests/threads_pool_tests.h +++ b/tests/performance_tests/threads_pool_tests.h @@ -6,10 +6,27 @@ #include #include "include_base_utils.h" -#include "threads_pool.h" +#include "common/threads_pool.h" inline void thread_pool_tests() { + { + utils::threads_pool pool; + pool.init(); + std::atomic count_jobs_finished = 0; + size_t i = 0; + for (; i != 10; i++) + { + pool.add_job([&, i]() {LOG_PRINT_L0("Job " << i << " started"); epee::misc_utils::sleep_no_w(10000); ++count_jobs_finished; LOG_PRINT_L0("Job " << i << " finished"); }); + } + while (count_jobs_finished != i) + { + epee::misc_utils::sleep_no_w(500); + } + LOG_PRINT_L0("All jobs finished"); + } + LOG_PRINT_L0("Scope left"); + } \ No newline at end of file From 761b75ad728f0bd1c9a0bad4954defc3fd7d4815 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 8 Feb 2022 14:51:22 +0100 Subject: [PATCH 11/13] added batch jobs to threads pool --- src/common/threads_pool.h | 40 +++++++++++++++++++- tests/performance_tests/threads_pool_tests.h | 27 ++++++++++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/common/threads_pool.h b/src/common/threads_pool.h index b1d4aebc..235e48ec 100644 --- a/src/common/threads_pool.h +++ b/src/common/threads_pool.h @@ -37,7 +37,15 @@ namespace utils class threads_pool { - public: + public: + typedef std::list> jobs_container; + + template + static void add_job_to_container(jobs_container& cntr, t_executor_func func) + { + cntr.push_back(std::shared_ptr(static_cast(new call_executor_t(func)))); + } + void init() { m_is_stop = false; @@ -63,6 +71,34 @@ namespace utils return true; } + void add_batch_and_wait(const jobs_container& cntr) + { + std::condition_variable batch_condition; + std::mutex batch_mutex; + + + std::atomic cnt = 0; + for (const auto& jb : cntr) + { + call_executor_base* pjob = jb.get(); + add_job([&, pjob]() { + pjob->execute(); + { + std::lock_guard lock(batch_mutex); + cnt++; + } + batch_condition.notify_one(); + }); + } + + std::unique_lock lock(batch_mutex); + batch_condition.wait(lock, [&]() + { + return cnt == cntr.size(); + }); + LOG_PRINT_L0("All jobs finiahed"); + } + ~threads_pool() { m_is_stop = true; @@ -103,7 +139,7 @@ namespace utils - std::list> m_jobs_que; + jobs_container m_jobs_que; std::condition_variable m_condition; std::mutex m_queue_mutex; std::vector m_threads; diff --git a/tests/performance_tests/threads_pool_tests.h b/tests/performance_tests/threads_pool_tests.h index a1bf2042..6999ac30 100644 --- a/tests/performance_tests/threads_pool_tests.h +++ b/tests/performance_tests/threads_pool_tests.h @@ -10,7 +10,7 @@ inline -void thread_pool_tests() +void thread_pool_tests_simple() { { utils::threads_pool pool; @@ -28,5 +28,30 @@ void thread_pool_tests() LOG_PRINT_L0("All jobs finished"); } LOG_PRINT_L0("Scope left"); +} +inline +void thread_pool_tests() +{ + { + utils::threads_pool pool; + pool.init(); + std::atomic count_jobs_finished = 0; + + utils::threads_pool::jobs_container jobs; + size_t i = 0; + for (; i != 10; i++) + { + utils::threads_pool::add_job_to_container(jobs, [&, i]() {LOG_PRINT_L0("Job " << i << " started"); epee::misc_utils::sleep_no_w(10000); ++count_jobs_finished; LOG_PRINT_L0("Job " << i << " finished"); }); + } + + pool.add_batch_and_wait(jobs); + if (count_jobs_finished != i) + { + LOG_ERROR("Test failed"); + return; + } + LOG_PRINT_L0("All jobs finished"); + } + LOG_PRINT_L0("Scope left"); } \ No newline at end of file From 5d808ad39ee250ccaaac60aa6cc4d79d6ab860f7 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 8 Feb 2022 14:55:35 +0100 Subject: [PATCH 12/13] added option for manual specifying number of threads --- src/common/threads_pool.h | 74 +++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/src/common/threads_pool.h b/src/common/threads_pool.h index 235e48ec..4e4e3905 100644 --- a/src/common/threads_pool.h +++ b/src/common/threads_pool.h @@ -13,7 +13,7 @@ namespace utils struct call_executor_base { - virtual void execute()=0; + virtual void execute() = 0; }; template @@ -28,7 +28,7 @@ namespace utils } }; - template + template std::shared_ptr build_call_executor(t_executor_func func) { std::shared_ptr res(static_cast(new call_executor_t(func))); @@ -40,26 +40,30 @@ namespace utils public: typedef std::list> jobs_container; - template - static void add_job_to_container(jobs_container& cntr, t_executor_func func) + template + static void add_job_to_container(jobs_container& cntr, t_executor_func func) { cntr.push_back(std::shared_ptr(static_cast(new call_executor_t(func)))); } void init() { - m_is_stop = false; int num_threads = std::thread::hardware_concurrency(); - + this->init(num_threads); + } + void init(unsigned int num_threads) + { + m_is_stop = false; + for (int i = 0; i < num_threads; i++) { - m_threads.push_back(std::thread([this](){this->worker_func(); })); + m_threads.push_back(std::thread([this]() {this->worker_func(); })); } } - threads_pool(): m_is_stop(false), m_threads_counter(0) + threads_pool() : m_is_stop(false), m_threads_counter(0) {} - + template bool add_job(t_executor_func func) { @@ -109,41 +113,41 @@ namespace utils } } - private: - void worker_func() + private: + void worker_func() + { + LOG_PRINT_L0("Worker thread is started"); + while (true) { - LOG_PRINT_L0("Worker thread is started"); - while (true) + std::shared_ptr job; { - std::shared_ptr job; - { - std::unique_lock lock(m_queue_mutex); + std::unique_lock lock(m_queue_mutex); - m_condition.wait(lock, [this]() - { - return !m_jobs_que.empty() || m_is_stop; - }); - if (m_is_stop) - { - LOG_PRINT_L0("Worker thread is finished"); - return; - } - - job = m_jobs_que.front(); - m_jobs_que.pop_front(); + m_condition.wait(lock, [this]() + { + return !m_jobs_que.empty() || m_is_stop; + }); + if (m_is_stop) + { + LOG_PRINT_L0("Worker thread is finished"); + return; } - job->execute(); + job = m_jobs_que.front(); + m_jobs_que.pop_front(); } + + job->execute(); } + } - jobs_container m_jobs_que; - std::condition_variable m_condition; - std::mutex m_queue_mutex; - std::vector m_threads; - std::atomic m_is_stop; - std::atomic m_threads_counter; + jobs_container m_jobs_que; + std::condition_variable m_condition; + std::mutex m_queue_mutex; + std::vector m_threads; + std::atomic m_is_stop; + std::atomic m_threads_counter; }; } \ No newline at end of file From 8b4c24cdf93c3253f405d9ded496b96161d9c676 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 9 Feb 2022 15:27:59 +0100 Subject: [PATCH 13/13] moved to latest UI: fixes in deeplinks, tabs refactoring --- src/gui/qt-daemon/layout | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index fdc3e748..22bed634 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit fdc3e748d4e0014e5652031c7603ec00b45803fa +Subproject commit 22bed634e5f3c1da0b4d4b1262d57a2445dba08b