| From: | Nathan Bossart <nathandbossart(at)gmail(dot)com> | 
|---|---|
| To: | Sami Imseih <samimseih(at)gmail(dot)com> | 
| Cc: | Bertrand Drouvot <bertranddrouvot(dot)pg(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-11 19:56:44 | 
| Message-ID: | ZpA4_Pw14FCP6025@nathan | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
On Thu, Jul 11, 2024 at 01:10:25PM -0500, Sami Imseih wrote:
>> I'm curious why we wouldn't just subtract "elapsed_time" from "delay" at
>> the bottom of the while loop to avoid needing this extra check.  
> 
> Can you elaborate further? I am not sure how this will work since delay is a timespec 
> and elapsed time is an instr_time. 
> 
> Also, in every iteration of the loop, the delay must be set to the remaining time. The
> purpose of the elapsed_time is to make sure that we don´t surpass requested time
> delay as an additional safeguard.
I'm imagining something like this:
    struct timespec delay;
    TimestampTz end_time;
end_time = TimestampTzPlusMilliseconds(GetCurrentTimestamp(), msec);
    do
    {
        long        secs;
        int         microsecs;
        TimestampDifference(GetCurrentTimestamp(), end_time,
                            &secs, µsecs);
        delay.tv_sec = secs;
        delay.tv_nsec = microsecs * 1000;
} while (nanosleep(&delay, NULL) == -1 && errno == EINTR);
-- 
nathan
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Robert Haas | 2024-07-11 20:09:31 | Re: Parent/child context relation in pg_get_backend_memory_contexts() | 
| Previous Message | Sami Imseih | 2024-07-11 18:10:25 | Re: Restart pg_usleep when interrupted |