MINOR: clock: provide a function to automatically adjust now_offset

Right now there's no way to enforce a specific value of now_ms upon
startup in order to compensate for the time it takes to load a config,
specifically when dealing with the health check startup. For this we'd
need to force the now_offset value to compensate for the last known
value of the current date. This patch exposes a function to do exactly
this.
This commit is contained in:
Willy Tarreau 2023-05-16 19:01:55 +02:00
parent 8e978a094d
commit 5345490b8e
2 changed files with 6 additions and 0 deletions

View File

@ -48,6 +48,7 @@ char *timeofday_as_iso_us(int pad);
uint clock_report_idle(void);
void clock_leaving_poll(int timeout, int interrupted);
void clock_entering_poll(void);
void clock_adjust_now_offset(void);
static inline void clock_update_date(int max_wait, int interrupted)
{

View File

@ -304,6 +304,11 @@ void clock_init_process_date(void)
clock_update_date(0, 1);
}
void clock_adjust_now_offset(void)
{
HA_ATOMIC_STORE(&now_offset, now_ns - tv_to_ns(&date));
}
/* must be called once per thread to initialize their thread-local variables.
* Note that other threads might also be initializing and running in parallel.
*/