Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9f17ffd

Browse files
committed
Measure WaitLatch's timeout parameter in milliseconds, not microseconds.
The original definition had the problem that timeouts exceeding about 2100seconds couldn't be specified on 32-bit machines. Milliseconds seem likesufficient resolution, and finer grain than that would be fantasy anywayon many platforms.Back-patch to 9.1 so that this aspect of the latch API won't change between9.1 and later releases.Peter Geoghegan
1 parent4e15a4d commit9f17ffd

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10210,7 +10210,9 @@ XLogPageRead(XLogRecPtr *RecPtr, int emode, bool fetching_ckpt,
1021010210
/*
1021110211
* Wait for more WAL to arrive, or timeout to be reached
1021210212
*/
10213-
WaitLatch(&XLogCtl->recoveryWakeupLatch,WL_LATCH_SET |WL_TIMEOUT,5000000L);
10213+
WaitLatch(&XLogCtl->recoveryWakeupLatch,
10214+
WL_LATCH_SET |WL_TIMEOUT,
10215+
5000L);
1021410216
ResetLatch(&XLogCtl->recoveryWakeupLatch);
1021510217
}
1021610218
else

‎src/backend/port/unix_latch.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ DisownLatch(volatile Latch *latch)
137137
* to wait for. If the latch is already set (and WL_LATCH_SET is given), the
138138
* function returns immediately.
139139
*
140-
* The 'timeout' is given inmicroseconds. It must be >= 0 if WL_TIMEOUT flag
140+
* The 'timeout' is given inmilliseconds. It must be >= 0 if WL_TIMEOUT flag
141141
* is given. On some platforms, signals cause the timeout to be restarted,
142142
* so beware that the function can sleep for several times longer than the
143143
* specified timeout.
@@ -156,6 +156,7 @@ DisownLatch(volatile Latch *latch)
156156
* have been satisfied. That should be rare in practice, but the caller
157157
* should not use the return value for anything critical, re-checking the
158158
* situation with PostmasterIsAlive() or read() on a socket as necessary.
159+
* The latch and timeout flag bits can be trusted, however.
159160
*/
160161
int
161162
WaitLatch(volatileLatch*latch,intwakeEvents,longtimeout)
@@ -191,8 +192,8 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
191192
if (wakeEvents&WL_TIMEOUT)
192193
{
193194
Assert(timeout >=0);
194-
tv.tv_sec=timeout /1000000L;
195-
tv.tv_usec=timeout %1000000L;
195+
tv.tv_sec=timeout /1000L;
196+
tv.tv_usec=(timeout %1000L)*1000L;
196197
tvp=&tv;
197198
}
198199

‎src/backend/port/win32_latch.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
9999
intnumevents;
100100
intresult=0;
101101
intpmdeath_eventno=0;
102-
longtimeout_ms;
103102

104103
/* Ignore WL_SOCKET_* events if no valid socket is given */
105104
if (sock==PGINVALID_SOCKET)
@@ -110,14 +109,11 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
110109
if ((wakeEvents&WL_LATCH_SET)&&latch->owner_pid!=MyProcPid)
111110
elog(ERROR,"cannot wait on a latch owned by another process");
112111

113-
/* Convert timeout tomilliseconds for WaitForMultipleObjects() */
112+
/* Convert timeout toform used by WaitForMultipleObjects() */
114113
if (wakeEvents&WL_TIMEOUT)
115-
{
116114
Assert(timeout >=0);
117-
timeout_ms=timeout /1000;
118-
}
119115
else
120-
timeout_ms=INFINITE;
116+
timeout=INFINITE;
121117

122118
/* Construct an array of event handles for WaitforMultipleObjects() */
123119
latchevent=latch->event;
@@ -165,7 +161,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
165161
break;
166162
}
167163

168-
rc=WaitForMultipleObjects(numevents,events, FALSE,timeout_ms);
164+
rc=WaitForMultipleObjects(numevents,events, FALSE,timeout);
169165

170166
if (rc==WAIT_FAILED)
171167
elog(ERROR,"WaitForMultipleObjects() failed: error code %d", (int)GetLastError());

‎src/backend/postmaster/pgarch.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,11 @@ pgarch_MainLoop(void)
406406
timeout=PGARCH_AUTOWAKE_INTERVAL- (curtime-last_copy_time);
407407
if (timeout>0)
408408
{
409-
intrc;
409+
intrc;
410+
410411
rc=WaitLatch(&mainloop_latch,
411412
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
412-
timeout*1000000L);
413+
timeout*1000L);
413414
if (rc&WL_TIMEOUT)
414415
wakened= true;
415416
}

‎src/backend/replication/syncrep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ SyncRepWaitForLSN(XLogRecPtr XactCommitLSN)
251251
* cancel/die signal or postmaster death regularly while waiting. Note
252252
* that timeout here does not necessarily release from loop.
253253
*/
254-
WaitLatch(&MyProc->waitLatch,WL_LATCH_SET |WL_TIMEOUT,60000000L);
254+
WaitLatch(&MyProc->waitLatch,WL_LATCH_SET |WL_TIMEOUT,60000L);
255255
}
256256

257257
/*

‎src/backend/replication/walsender.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ WalSndLoop(void)
812812
if (pq_is_send_pending())
813813
wakeEvents |=WL_SOCKET_WRITEABLE;
814814
WaitLatchOrSocket(&MyWalSnd->latch,wakeEvents,
815-
MyProcPort->sock,sleeptime*1000L);
815+
MyProcPort->sock,sleeptime);
816816

817817
/* Check for replication timeout */
818818
if (replication_timeout>0&&

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp