From eeae1d13437166b437e459c99ddbb6ee1b339c50 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 8 Mar 2024 08:52:21 -0500 Subject: [PATCH] MT#40962 refactor wheeltimer::unix_clock Change it into a wrapper that directly calls time() to eliminate the need of the timer thread to continuously set unix_clock to the current time. With vDSO the call to time() is sufficiently cheap. Move constructor to header and remove default empty destructor. Change-Id: Ib812a993da9340b9ded4fd97c81d762d9452c3ea --- core/sip/wheeltimer.cpp | 15 --------------- core/sip/wheeltimer.h | 17 ++++++++++------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/core/sip/wheeltimer.cpp b/core/sip/wheeltimer.cpp index 95ad2f9c..a8ef4202 100644 --- a/core/sip/wheeltimer.cpp +++ b/core/sip/wheeltimer.cpp @@ -42,18 +42,6 @@ timer::~timer() // DBG("timer::~timer(this=%p)\n",this); } -_wheeltimer::_wheeltimer() - : wall_clock(0) -{ - struct timeval now; - gettimeofday(&now,NULL); - unix_clock.set(now.tv_sec); -} - -_wheeltimer::~_wheeltimer() -{ -} - void _wheeltimer::insert_timer(timer* t) { //add new timer to user request list @@ -103,9 +91,6 @@ void _wheeltimer::run() //printf("missed one tick\n"); //} - gettimeofday(&now,NULL); - unix_clock.set(now.tv_sec); - turn_wheel(); timeradd(&tick,&next_tick,&next_tick); } diff --git a/core/sip/wheeltimer.h b/core/sip/wheeltimer.h index 0b236e9c..4d6d04cf 100644 --- a/core/sip/wheeltimer.h +++ b/core/sip/wheeltimer.h @@ -32,6 +32,7 @@ #include "../AmThread.h" #include +#include #include #include "atomic_types.h" @@ -113,17 +114,19 @@ protected: void run(); void on_stop(){} - _wheeltimer(); - ~_wheeltimer(); + _wheeltimer() + : wall_clock(0) {} public: //clock reference volatile u_int32_t wall_clock; // 32 bits -#ifdef __LP64__ - atomic_int64 unix_clock; // 64 bits -#else - atomic_int unix_clock; // 32 bits -#endif + struct _uc { + int64_t get() + { + return time(NULL); + } + }; + _uc unix_clock; void insert_timer(timer* t); void remove_timer(timer* t);