From 14edd686533f1b5e6a49e0a697cccadd0d8614e2 Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Mon, 1 Jun 2026 15:40:22 +0200 Subject: [PATCH] Removed SignalBitfield and replaced it with callbacks. --- src/display/window_log.cc | 18 +++++++++++------- src/display/window_log.h | 2 ++ src/main.cc | 10 ---------- src/ui/element_log_complete.cc | 12 ++++++++---- src/ui/element_log_complete.h | 2 ++ 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/display/window_log.cc b/src/display/window_log.cc index 65e9f11a..e48865f4 100644 --- a/src/display/window_log.cc +++ b/src/display/window_log.cc @@ -2,6 +2,7 @@ #include #include +#include #include #include "canvas.h" @@ -14,13 +15,14 @@ WindowLog::WindowLog(torrent::log_buffer* l) : Window(new Canvas, 0, 0, 0, extent_full, extent_static), m_log(l) { - m_task_update.slot() = std::bind(&WindowLog::receive_update, this); + m_task_update.slot() = [this]() { receive_update(); }; - unsigned int signal_index = torrent::main_thread::thread()->signal_bitfield()->add_signal(std::bind(&WindowLog::receive_update, this)); + m_log->lock_and_set_update_slot([this]() { + if (m_log_updating.exchange(true) == true) + return; - m_log->lock_and_set_update_slot([signal_index]() { - torrent::main_thread::thread()->send_event_signal(signal_index, false); - }); + torrent::main_thread::callback([this]() { receive_update(); }); + }); } WindowLog::~WindowLog() { @@ -52,11 +54,13 @@ WindowLog::redraw() { // gets updated. void WindowLog::receive_update() { + m_log_updating = false; + if (!is_active()) return; - iterator itr = find_older(); - extent_type height = std::min(std::distance(itr, (iterator)m_log->end()), (std::iterator_traits::difference_type)10); + auto itr = find_older(); + auto height = std::min(std::distance(itr, (iterator)m_log->end()), (std::iterator_traits::difference_type)10); if (height != m_max_height) { m_min_height = height != 0 ? 1 : 0; diff --git a/src/display/window_log.h b/src/display/window_log.h index 5e5dfed6..bb00c9c7 100644 --- a/src/display/window_log.h +++ b/src/display/window_log.h @@ -24,6 +24,8 @@ private: torrent::log_buffer* m_log; torrent::utils::SchedulerEntry m_task_update; + + align_cacheline std::atomic m_log_updating{}; }; } diff --git a/src/main.cc b/src/main.cc index 2af6234f..bd49033b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -141,16 +141,6 @@ main(int argc, char** argv) { SignalHandler::set_sigaction_handler(SIGBUS, &handle_sigbus); - // SIGUSR1 is used for interrupting polling, forcing the target - // thread to process new non-socket events. - // - // LibTorrent uses sockets for this purpose on Solaris and other - // platforms that do not properly pass signals to the target - // threads. Use '--enable-interrupt-socket' when configuring - // LibTorrent to enable this workaround. - if (torrent::system::Thread::should_handle_sigusr1()) - SignalHandler::set_handler(SIGUSR1, []() {}); - torrent::log_add_group_output(torrent::LOG_NOTICE, "important"); torrent::log_add_group_output(torrent::LOG_DHT_ERROR, "important"); diff --git a/src/ui/element_log_complete.cc b/src/ui/element_log_complete.cc index 5e2ea351..8eb30491 100644 --- a/src/ui/element_log_complete.cc +++ b/src/ui/element_log_complete.cc @@ -2,6 +2,7 @@ #include #include +#include #include #include "display/frame.h" @@ -17,11 +18,12 @@ namespace ui { ElementLogComplete::ElementLogComplete(torrent::log_buffer* l) : m_log(l) { - unsigned int signal_index = torrent::main_thread::thread()->signal_bitfield()->add_signal(std::bind(&ElementLogComplete::received_update, this)); + m_log->lock_and_set_update_slot([this]() { + if (m_log_updating.exchange(true) == true) + return; - m_log->lock_and_set_update_slot([signal_index]() { - torrent::main_thread::thread()->send_event_signal(signal_index, false); - }); + torrent::main_thread::callback([this]() { received_update(); }); + }); } void @@ -59,6 +61,8 @@ ElementLogComplete::window() { void ElementLogComplete::received_update() { + m_log_updating = false; + if (m_window != NULL) m_window->mark_dirty(); } diff --git a/src/ui/element_log_complete.h b/src/ui/element_log_complete.h index 40c2f6d0..ea9cdaad 100644 --- a/src/ui/element_log_complete.h +++ b/src/ui/element_log_complete.h @@ -30,6 +30,8 @@ private: WLogComplete* m_window{}; torrent::log_buffer* m_log; + + align_cacheline std::atomic m_log_updating{}; }; }