Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit eb267ef

Browse files
committed
Use sleep by Arseny
1 parent e00018d commit eb267ef

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

contrib/mmts/multimaster.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,15 +460,18 @@ timestamp_t MtmGetCurrentTime(void)
460460

461461
void MtmSleep(timestamp_t interval)
462462
{
463-
struct timespec ts;
464-
struct timespec rem;
465-
ts.tv_sec = interval/USECS_PER_SEC;
466-
ts.tv_nsec = interval%USECS_PER_SEC*1000;
463+
timestamp_t waketm = MtmGetCurrentTime() + interval;
464+
for (;;)
465+
{
466+
timestamp_t sleepfor = waketm - MtmGetCurrentTime();
467467

468-
while (nanosleep(&ts, &rem) < 0) {
469-
Assert(errno == EINTR);
470-
CHECK_FOR_INTERRUPTS();
471-
ts = rem;
468+
pg_usleep(sleepfor);
469+
if (MtmGetCurrentTime() < waketm)
470+
{
471+
Assert(errno == EINTR);
472+
continue;
473+
}
474+
break;
472475
}
473476
}
474477

src/backend/access/transam/global_snapshot.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,19 @@ dtm_get_current_time()
152152
static void
153153
dtm_sleep(timestamp_t interval)
154154
{
155-
struct timespec ts;
156-
struct timespec rem;
157-
158-
ts.tv_sec = 0;
159-
ts.tv_nsec = interval * 1000;
160-
161-
while (nanosleep(&ts, &rem) < 0)
155+
timestamp_t waketm = dtm_get_current_time() + interval;
156+
for (;;)
162157
{
163-
totalSleepInterrupts += 1;
164-
Assert(errno == EINTR);
165-
ts = rem;
158+
timestamp_t sleepfor = waketm - dtm_get_current_time();
159+
160+
pg_usleep(sleepfor);
161+
if (dtm_get_current_time() < waketm)
162+
{
163+
totalSleepInterrupts += 1;
164+
Assert(errno == EINTR);
165+
continue;
166+
}
167+
break;
166168
}
167169
}
168170

0 commit comments

Comments
 (0)