diff --git a/src/v/ssx/include/ssx/task_local_ptr.h b/src/v/ssx/include/ssx/task_local_ptr.h index 6411f867723a8..6069b9d2564ee 100644 --- a/src/v/ssx/include/ssx/task_local_ptr.h +++ b/src/v/ssx/include/ssx/task_local_ptr.h @@ -35,23 +35,18 @@ class task_local_ptr_invalidated : public std::runtime_error { /// will trigger 'task_local_invalidated' exception. template class task_local { - static const seastar::task* get_current_task() { - auto task = seastar::engine().current_task(); - if (task == nullptr) { - task = seastar::thread_impl::get()->waiting_task(); - } - vassert(task != nullptr, "No current task"); - return task; + static uint64_t get_current_task_cnt() { + return seastar::engine().get_sched_stats().tasks_processed; } public: explicit task_local(const T& val) : _val(val) - , _task(get_current_task()) {} + , _task_cnt(get_current_task_cnt()) {} explicit task_local(T&& val) : _val(val) - , _task(get_current_task()) {} + , _task_cnt(get_current_task_cnt()) {} task_local() = delete; ~task_local() = default; @@ -91,7 +86,7 @@ class task_local { /// Check if the time slice is the same. Invalidate /// the pointer if its not. void check_time_slice() const { - if (get_current_task() != _task) { + if (get_current_task_cnt() != _task_cnt) { // Opt-out from all checks if we don't have a valid pointer to // the current task. _val = std::nullopt; @@ -105,8 +100,7 @@ class task_local { } mutable std::optional _val; - // Non-owning ptr - const seastar::task* _task; + uint64_t _task_cnt; }; template