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
mr12.3.1
Richard Fuchs 2 years ago
parent 096a1f31a5
commit eeae1d1343

@ -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);
}

@ -32,6 +32,7 @@
#include "../AmThread.h"
#include <sys/types.h>
#include <time.h>
#include <deque>
#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);

Loading…
Cancel
Save