Hi,

On Mon, Jul 29, 2024 at 06:15:49PM -0500, Sami Imseih wrote:
> > On Jul 26, 2024, at 3:27 AM, Bertrand Drouvot 
> > <bertranddrouvot...@gmail.com> wrote:
> > 3 ===
> > 
> > I gave more thoughts and I think it can be simplified a bit to reduce the
> > number of operations in the while loop.
> > 
> > What about relying on a "absolute" time that way:
> > 
> >     instr_time absolute;
> >    absolute.ticks = start_time.ticks + msec * 1000000;
> > 
> > and then in the while loop:
> > 
> >    while (nanosleep(&delay, &remain) == -1 && errno == EINTR)
> >    {
> >        instr_time current_time;
> >        INSTR_TIME_SET_CURRENT(current_time);
> > 
> >        if (current_time.ticks > absolute.ticks)
> >        {
> >            break;
> 
> While I agree this code is cleaner, myy hesitation there is we don’t 
> have any other place in which we access .ticks directly and the 
> common practice is to use the intsr_time.h APIs.

yeah, we already have a few macros that access the .ticks, so maybe we could add
2 new ones, say:

1. INSTR_TIME_ADD_MS(t1, msec)
2. INSTR_TIME_IS_GREATER(t1, t2)

I think the less operations is done in the while loop the better.

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


Reply via email to