From aaf50099f2362deb431ce85d546899fcd8b7b330 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 21 Aug 2022 15:30:13 -0700 Subject: [PATCH] Stop using a static vector for timers This is thread unsafe. Just use a captured local variable instead. --- src/timer.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/timer.cpp b/src/timer.cpp index 0341d8157..73cddfa02 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -194,11 +194,7 @@ wcstring timer_snapshot_t::print_delta(const timer_snapshot_t &t1, const timer_s return output; }; -static std::vector active_timers; - -static void pop_timer() { - auto t1 = active_timers.back(); - active_timers.pop_back(); +static void timer_finished(const timer_snapshot_t &t1) { auto t2 = timer_snapshot_t::take(); // Well, this is awkward. By defining `time` as a decorator and not a built-in, there's @@ -209,6 +205,7 @@ static void pop_timer() { cleanup_t push_timer(bool enabled) { if (!enabled) return {[] {}}; - active_timers.emplace_back(timer_snapshot_t::take()); - return {[] { pop_timer(); }}; + + auto t1 = timer_snapshot_t::take(); + return {[=] { timer_finished(t1); }}; }