Re: Restart pg_usleep when interrupted

From: Sami Imseih <samimseih(at)gmail(dot)com>
To: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: Nathan Bossart <nathandbossart(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Restart pg_usleep when interrupted
Date: 2024-07-29 23:15:49
Message-ID: 33287B8A-3CA0-494F-87D3-C9D85C6468FE@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Jul 26, 2024, at 3:27 AM, Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com> wrote:
>
> Hi,
>
> On Thu, Jul 25, 2024 at 05:27:15PM -0500, Sami Imseih wrote:
>> I am attaching v3 of the patch which addresses the comments made
>> earlier by Bertrand about the comment in the patch [1].
>
> Thanks!
>
> Looking at it:
>
> 1 ===
>
> + struct instr_time start_time;
>
> I think we can get rid of the "struct" keyword here.
>
> 2 ===
>
> + struct instr_time current_time;
> + struct instr_time elapsed_time;
>
> Same as above.

Will fix those 2.

>
> 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.

What do you think?

Regards,

Sami

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2024-07-29 23:16:18 Re: Remove last traces of HPPA support
Previous Message Jacob Champion 2024-07-29 23:15:33 Re: [PoC] Federated Authn/z with OAUTHBEARER