Use nanosleep() for pg_usleep() on Unix/Linux?

From: Paul Guo <paulguo(at)gmail(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Use nanosleep() for pg_usleep() on Unix/Linux?
Date: 2016-09-11 09:56:33
Message-ID: CABQrizfxpBLZT5mZeE0js5oCh1tqEWvcGF3vMRCv5P-RwUY5dQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I happened to read the pg_usleep() code recently. I'm wondering
if we could implement it using the posix function nanosleep(),
instead of by select().

nanosleep() is designed with higher time resolution, besides it provide
remaining time if is interrupted by signal so that pg_usleep() could
be implemented more accurately.

The code for pg_usleep() could be similar like this:

while(nanosleep(&req,&req)==-1 && errno == EINTR)

continue;

or combine with clock_gettime() to control the sleep time more accurately.

Regards,

Paul

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Craig Ringer 2016-09-11 11:42:36 Re: Override compile time log levels of specific messages/modules
Previous Message Mark Kirkwood 2016-09-11 09:31:08 Re: Write Ahead Logging for Hash Indexes