From dd221ac66a7cdb2f7cf3ebc2a44084a6b0ead171 Mon Sep 17 00:00:00 2001 From: Jari Sundell Date: Tue, 15 Apr 2025 19:39:40 +0200 Subject: [PATCH] Replaced Thread::next_timeout_usec(). --- src/core/view.h | 1 + src/input/bindings.cc | 36 ------------------------------- src/input/input_event.cc | 36 ------------------------------- src/input/input_event.h | 36 ------------------------------- src/input/manager.cc | 38 +-------------------------------- src/input/manager.h | 36 ------------------------------- src/main.cc | 3 +-- src/rpc/scgi.cc | 2 ++ src/thread_base.cc | 23 ++++++++++---------- src/thread_base.h | 6 ++---- src/ui/element_download_list.cc | 2 +- 11 files changed, 19 insertions(+), 200 deletions(-) diff --git a/src/core/view.h b/src/core/view.h index 1fe6f2be..f6ae590b 100644 --- a/src/core/view.h +++ b/src/core/view.h @@ -14,6 +14,7 @@ #define RTORRENT_CORE_VIEW_DOWNLOADS_H #include +#include #include #include diff --git a/src/input/bindings.cc b/src/input/bindings.cc index f02cb8f5..3939eb50 100644 --- a/src/input/bindings.cc +++ b/src/input/bindings.cc @@ -1,39 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - #include "config.h" #include diff --git a/src/input/input_event.cc b/src/input/input_event.cc index 72159d62..1b6ebcf1 100644 --- a/src/input/input_event.cc +++ b/src/input/input_event.cc @@ -1,39 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - #include "config.h" #include "input_event.h" diff --git a/src/input/input_event.h b/src/input/input_event.h index c82150c6..935ad7ae 100644 --- a/src/input/input_event.h +++ b/src/input/input_event.h @@ -1,39 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - #ifndef RTORRENT_INPUT_INPUT_EVENT_H #define RTORRENT_INPUT_INPUT_EVENT_H diff --git a/src/input/manager.cc b/src/input/manager.cc index d94d4d89..4e64251a 100644 --- a/src/input/manager.cc +++ b/src/input/manager.cc @@ -1,39 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - #include "config.h" #include @@ -64,7 +28,7 @@ Manager::pressed(int key) { if (m_textInput != NULL) m_textInput->pressed(key); else - std::find_if(rbegin(), rend(), [&key](Bindings* bind) { return bind->pressed(key); }); + [[maybe_unused]] auto result = std::find_if(rbegin(), rend(), [&key](Bindings* bind) { return bind->pressed(key); }); } } diff --git a/src/input/manager.h b/src/input/manager.h index fd5710a0..b6f40b27 100644 --- a/src/input/manager.h +++ b/src/input/manager.h @@ -1,39 +1,3 @@ -// rTorrent - BitTorrent client -// Copyright (C) 2005-2011, Jari Sundell -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// -// In addition, as a special exception, the copyright holders give -// permission to link the code of portions of this program with the -// OpenSSL library under certain conditions as described in each -// individual source file, and distribute linked combinations -// including the two. -// -// You must obey the GNU General Public License in all respects for -// all of the code used other than OpenSSL. If you modify file(s) -// with this exception, you may extend this exception to your version -// of the file(s), but you are not obligated to do so. If you do not -// wish to do so, delete this exception statement from your version. -// If you delete this exception statement from all source files in the -// program, then also delete it here. -// -// Contact: Jari Sundell -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - #ifndef RTORRENT_INPUT_MANAGER_H #define RTORRENT_INPUT_MANAGER_H diff --git a/src/main.cc b/src/main.cc index ea2a5126..133325d7 100644 --- a/src/main.cc +++ b/src/main.cc @@ -191,8 +191,7 @@ main(int argc, char** argv) { torrent::Poll::slot_create_poll() = std::bind(&core::create_poll); torrent::initialize(); - torrent::main_thread()->slot_do_work() = std::bind(&client_perform); - torrent::main_thread()->slot_next_timeout() = std::bind(&client_next_timeout); + torrent::set_main_thread_slots(std::bind(&client_perform), std::bind(&client_next_timeout)); worker_thread = new ThreadWorker(); worker_thread->init_thread(); diff --git a/src/rpc/scgi.cc b/src/rpc/scgi.cc index 0d0f80e3..79c50071 100644 --- a/src/rpc/scgi.cc +++ b/src/rpc/scgi.cc @@ -86,6 +86,8 @@ SCgi::open(void* sa, unsigned int length) { } } +// TODO: Verify this is run in correct thread, also only ever call poll methods from thread_self. + void SCgi::activate() { worker_thread->poll()->open(this); diff --git a/src/thread_base.cc b/src/thread_base.cc index e3d1cb38..9d56d24e 100644 --- a/src/thread_base.cc +++ b/src/thread_base.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -32,25 +33,23 @@ ThreadBase::queue_stop_thread() { priority_queue_insert(&m_taskScheduler, &m_taskShutdown, cachedTime); } -int64_t -ThreadBase::next_timeout_usec() { +std::chrono::microseconds +ThreadBase::next_timeout() { if (m_taskScheduler.empty()) - return rak::timer::from_seconds(600).usec(); - else if (m_taskScheduler.top()->time() <= cachedTime) - return 0; - else - return (m_taskScheduler.top()->time() - cachedTime).usec(); + return std::chrono::microseconds(10min); - // TODO: Thread-specific cachedTime. + cachedTime = rak::timer::current(); - // if (!taskScheduler.empty()) - // return std::max(taskScheduler.top()->time() - cachedTime, rak::timer()).usec(); - // else - // return rak::timer::from_seconds(600).usec(); + if (m_taskScheduler.top()->time() <= cachedTime) + return std::chrono::microseconds(0); + + return std::chrono::microseconds((m_taskScheduler.top()->time() - cachedTime).usec()); } void ThreadBase::call_events() { + cachedTime = rak::timer::current(); + rak::priority_queue_perform(&m_taskScheduler, cachedTime); process_callbacks(); diff --git a/src/thread_base.h b/src/thread_base.h index fbbd882c..b092d36e 100644 --- a/src/thread_base.h +++ b/src/thread_base.h @@ -32,10 +32,8 @@ public: // void queue_item(thread_base_func newFunc); protected: - int64_t next_timeout_usec(); - - // void call_queued_items(); - virtual void call_events(); + void call_events() override; + std::chrono::microseconds next_timeout() override; // TODO: Add thread name. diff --git a/src/ui/element_download_list.cc b/src/ui/element_download_list.cc index 5c92984c..74b875ce 100644 --- a/src/ui/element_download_list.cc +++ b/src/ui/element_download_list.cc @@ -70,7 +70,7 @@ ElementDownloadList::ElementDownloadList() : } void -ElementDownloadList::activate(display::Frame* frame, bool focus) { +ElementDownloadList::activate(display::Frame* frame, [[maybe_unused]] bool focus) { if (is_active()) throw torrent::internal_error("ui::ElementDownloadList::activate(...) is_active().");