mirror of
https://github.com/wangyu-/udp2raw.git
synced 2025-01-19 06:19:31 +08:00
get_current_time_us() never goes back now
This commit is contained in:
parent
168ae1e2ae
commit
7d481d26b9
28
common.cpp
28
common.cpp
@ -430,13 +430,31 @@ int get_sock_errno()
|
||||
#endif
|
||||
|
||||
|
||||
u64_t get_current_time_us()
|
||||
{
|
||||
static u64_t value_fix=0;
|
||||
static u64_t largest_value=0;
|
||||
|
||||
u64_t raw_value=(u64_t)(ev_time()*1000*1000);
|
||||
|
||||
u64_t fixed_value=raw_value+value_fix;
|
||||
|
||||
if(fixed_value< largest_value)
|
||||
{
|
||||
value_fix+= largest_value- fixed_value;
|
||||
}
|
||||
else
|
||||
{
|
||||
largest_value=fixed_value;
|
||||
}
|
||||
|
||||
//printf("<%lld,%lld,%lld>\n",raw_value,value_fix,raw_value + value_fix);
|
||||
return raw_value + value_fix; //new fixed value
|
||||
}
|
||||
|
||||
u64_t get_current_time()
|
||||
{
|
||||
timespec tmp_time;
|
||||
clock_gettime(CLOCK_MONOTONIC, &tmp_time);
|
||||
return ((u64_t)tmp_time.tv_sec)*1000llu+((u64_t)tmp_time.tv_nsec)/(1000*1000llu);
|
||||
|
||||
//return (u64_t)(ev_time()*1000); //todo change to this later
|
||||
return get_current_time_us()/1000;
|
||||
}
|
||||
|
||||
u64_t pack_u64(u32_t a,u32_t b)
|
||||
|
Loading…
x
Reference in New Issue
Block a user