Bläddra i källkod

LibCore+Userland: Don't auto-start new Core::Timers

This was unintuitive, and only useful in a few cases. In the majority,
users had to immediately call `stop()`, and several who did want the
timer started would call `start()` on it immediately anyway. Case in
point: There are only two places I had to add a manual `start()`.
Sam Atkins 2 år sedan
förälder
incheckning
6edc0cf5ab

+ 0 - 1
Userland/Applications/SoundPlayer/PlaybackManager.cpp

@@ -16,7 +16,6 @@ PlaybackManager::PlaybackManager(NonnullRefPtr<Audio::ConnectionToServer> connec
             return;
         next_buffer();
     });
-    m_timer->stop();
     m_device_sample_rate = connection->get_sample_rate();
 }
 

+ 1 - 0
Userland/Applications/SystemMonitor/NetworkStatisticsWidget.cpp

@@ -132,6 +132,7 @@ NetworkStatisticsWidget::NetworkStatisticsWidget()
             1000, [this] {
                 update_models();
             });
+        m_update_timer->start();
 
         update_models();
     };

+ 1 - 0
Userland/Applications/SystemMonitor/ProcessMemoryMapWidget.cpp

@@ -110,6 +110,7 @@ ProcessMemoryMapWidget::ProcessMemoryMapWidget()
 
     m_table_view->set_key_column_and_sort_order(0, GUI::SortOrder::Ascending);
     m_timer = add<Core::Timer>(1000, [this] { refresh(); });
+    m_timer->start();
 }
 
 void ProcessMemoryMapWidget::set_pid(pid_t pid)

+ 3 - 1
Userland/Applications/SystemMonitor/ThreadStackWidget.cpp

@@ -82,8 +82,10 @@ ThreadStackWidget::ThreadStackWidget()
 void ThreadStackWidget::show_event(GUI::ShowEvent&)
 {
     refresh();
-    if (!m_timer)
+    if (!m_timer) {
         m_timer = add<Core::Timer>(1000, [this] { refresh(); });
+        m_timer->start();
+    }
 }
 
 void ThreadStackWidget::hide_event(GUI::HideEvent&)

+ 1 - 0
Userland/Applications/SystemMonitor/main.cpp

@@ -328,6 +328,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
     };
     update_stats();
     auto& refresh_timer = window->add<Core::Timer>(frequency * 1000, move(update_stats));
+    refresh_timer.start();
 
     auto selected_id = [&](ProcessModel::Column column) -> pid_t {
         if (process_table_view.selection().is_empty())

+ 1 - 0
Userland/DevTools/Profiler/main.cpp

@@ -329,6 +329,7 @@ static bool prompt_to_stop_profiling(pid_t pid, DeprecatedString const& process_
     auto update_timer = Core::Timer::construct(100, [&] {
         timer_label.set_text(DeprecatedString::formatted("{:.1} seconds", static_cast<float>(clock.elapsed()) / 1000.0f));
     });
+    update_timer->start();
 
     auto& stop_button = widget->add<GUI::Button>("Stop");
     stop_button.set_fixed_size(140, 22);

+ 1 - 1
Userland/Libraries/LibCore/Timer.cpp

@@ -17,8 +17,8 @@ Timer::Timer(Object* parent)
 Timer::Timer(int interval_ms, Function<void()>&& timeout_handler, Object* parent)
     : Object(parent)
     , on_timeout(move(timeout_handler))
+    , m_interval_ms(interval_ms)
 {
-    start(interval_ms);
 }
 
 void Timer::start()

+ 1 - 4
Userland/Libraries/LibCore/Timer.h

@@ -18,15 +18,12 @@ class Timer final : public Object {
 public:
     static ErrorOr<NonnullRefPtr<Timer>> create_repeating(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr)
     {
-        auto timer = TRY(adopt_nonnull_ref_or_enomem(new Timer(interval_ms, move(timeout_handler), parent)));
-        timer->stop();
-        return timer;
+        return adopt_nonnull_ref_or_enomem(new Timer(interval_ms, move(timeout_handler), parent));
     }
     static ErrorOr<NonnullRefPtr<Timer>> create_single_shot(int interval_ms, Function<void()>&& timeout_handler, Object* parent = nullptr)
     {
         auto timer = TRY(adopt_nonnull_ref_or_enomem(new Timer(interval_ms, move(timeout_handler), parent)));
         timer->set_single_shot(true);
-        timer->stop();
         return timer;
     }
 

+ 1 - 0
Userland/Services/Taskbar/ClockWidget.cpp

@@ -35,6 +35,7 @@ ClockWidget::ClockWidget()
             set_tooltip(Core::DateTime::now().to_deprecated_string("%Y-%m-%d"sv));
         }
     });
+    m_timer->start();
 
     m_calendar_window = add<GUI::Window>(window());
     m_calendar_window->set_window_type(GUI::WindowType::Popup);

+ 2 - 1
Userland/Services/WindowServer/Compositor.cpp

@@ -48,7 +48,6 @@ Compositor::Compositor()
         1000 / 60, [this] {
             notify_display_links();
         });
-    m_display_link_notify_timer->stop();
 
     m_compose_timer = Core::Timer::create_single_shot(
         1000 / 60,
@@ -57,6 +56,7 @@ Compositor::Compositor()
         },
         this)
                           .release_value_but_fixme_should_propagate_errors();
+    m_compose_timer->start();
 
     m_immediate_compose_timer = Core::Timer::create_single_shot(
         0,
@@ -65,6 +65,7 @@ Compositor::Compositor()
         },
         this)
                                     .release_value_but_fixme_should_propagate_errors();
+    m_compose_timer->start();
 
     init_bitmaps();
 }