From f106c25c5d3b2a21db5c21c174942dbb896716ca Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 19 Feb 2025 08:43:02 -0400 Subject: [PATCH] MT#62181 wheeltimer: use lock guards Change-Id: I504d5fd4d08180b624c34eef211a7c4f0abc1fa5 --- core/sip/wheeltimer.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/sip/wheeltimer.cpp b/core/sip/wheeltimer.cpp index 7ee9ab8b..92c47e99 100644 --- a/core/sip/wheeltimer.cpp +++ b/core/sip/wheeltimer.cpp @@ -48,13 +48,12 @@ timer::~timer() void _wheeltimer::insert_timer(timer* t) { //add new timer to user request list - reqs_m.lock(); + std::lock_guard lock(reqs_m); reqs_backlog.push_back(timer_req(t,true)); // Wake up worker thread: This triggers turn_wheel() based on how many ticks have passed, // and in turn brings wall_clock up to date. Finally the events queue is processed, which // adds the timer to the wheel based on the now-updated wall_clock. reqs_cond.set(true); - reqs_m.unlock(); } void _wheeltimer::remove_timer(timer* t) @@ -64,7 +63,7 @@ void _wheeltimer::remove_timer(timer* t) } //add timer to remove to user request list - reqs_m.lock(); + std::lock_guard lock(reqs_m); reqs_backlog.push_back(timer_req(t,false)); // Wake up worker thread: This is needed because the events queue is processed after // expired timers are fired, and because the worker thread would otherwise continue to @@ -72,7 +71,6 @@ void _wheeltimer::remove_timer(timer* t) // IOW we want to make sure events are processed before timers are fired, in case the // timer we want to remove now is one of the timers that would be fired next. reqs_cond.set(true); - reqs_m.unlock(); } void _wheeltimer::run() @@ -164,10 +162,10 @@ void _wheeltimer::turn_wheel() void _wheeltimer::process_events() { // Swap the lists for timer insertion/deletion requests and reset wake condition - reqs_m.lock(); + std::unique_lock lock(reqs_m); reqs_cond.set(false); reqs_process.swap(reqs_backlog); - reqs_m.unlock(); + lock.unlock(); while(!reqs_process.empty()) { timer_req rq = reqs_process.front();