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

Commit59f71a0

Browse files
committed
Add a default local latch for use in signal handlers.
To do so, move InitializeLatchSupport() into the new common processinitialization functions, and add a new global variable MyLatch.MyLatch is usable as soon InitPostmasterChild() has been called(i.e. very early during startup). Initially it points to a processlocal latch that exists in all processes. InitProcess/InitAuxiliaryProcessthen replaces that local latch with PGPROC->procLatch. During shutdownthe reverse happens.This is primarily advantageous for two reasons: For one it simplifiesdealing with the shared process latch, especially in signal handlers,because instead of having to check for MyProc, MyLatch can be usedunconditionally. For another, a later patch that makes FEs/BEcommunication use latches, now can rely on the existence of a latch,even before having gone through InitProcess.Discussion: 20140927191243.GD5423@alap3.anarazel.de
1 parent85a2a89 commit59f71a0

File tree

23 files changed

+136
-134
lines changed

23 files changed

+136
-134
lines changed

‎src/backend/postmaster/autovacuum.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,11 +589,11 @@ AutoVacLauncherMain(int argc, char *argv[])
589589
* Wait until naptime expires or we get some type of signal (all the
590590
* signal handlers will wake us by calling SetLatch).
591591
*/
592-
rc=WaitLatch(&MyProc->procLatch,
592+
rc=WaitLatch(MyLatch,
593593
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
594594
(nap.tv_sec*1000L)+ (nap.tv_usec /1000L));
595595

596-
ResetLatch(&MyProc->procLatch);
596+
ResetLatch(MyLatch);
597597

598598
DisableCatchupInterrupt();
599599

@@ -1341,8 +1341,7 @@ avl_sighup_handler(SIGNAL_ARGS)
13411341
intsave_errno=errno;
13421342

13431343
got_SIGHUP= true;
1344-
if (MyProc)
1345-
SetLatch(&MyProc->procLatch);
1344+
SetLatch(MyLatch);
13461345

13471346
errno=save_errno;
13481347
}
@@ -1354,8 +1353,7 @@ avl_sigusr2_handler(SIGNAL_ARGS)
13541353
intsave_errno=errno;
13551354

13561355
got_SIGUSR2= true;
1357-
if (MyProc)
1358-
SetLatch(&MyProc->procLatch);
1356+
SetLatch(MyLatch);
13591357

13601358
errno=save_errno;
13611359
}
@@ -1367,8 +1365,7 @@ avl_sigterm_handler(SIGNAL_ARGS)
13671365
intsave_errno=errno;
13681366

13691367
got_SIGTERM= true;
1370-
if (MyProc)
1371-
SetLatch(&MyProc->procLatch);
1368+
SetLatch(MyLatch);
13721369

13731370
errno=save_errno;
13741371
}

‎src/backend/postmaster/bgworker.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ WaitForBackgroundWorkerStartup(BackgroundWorkerHandle *handle, pid_t *pidp)
942942
if (status!=BGWH_NOT_YET_STARTED)
943943
break;
944944

945-
rc=WaitLatch(&MyProc->procLatch,
945+
rc=WaitLatch(MyLatch,
946946
WL_LATCH_SET |WL_POSTMASTER_DEATH,0);
947947

948948
if (rc&WL_POSTMASTER_DEATH)
@@ -951,7 +951,7 @@ WaitForBackgroundWorkerStartup(BackgroundWorkerHandle *handle, pid_t *pidp)
951951
break;
952952
}
953953

954-
ResetLatch(&MyProc->procLatch);
954+
ResetLatch(MyLatch);
955955
}
956956
}
957957
PG_CATCH();

‎src/backend/postmaster/bgwriter.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ BackgroundWriterMain(void)
248248
intrc;
249249

250250
/* Clear any already-pending wakeups */
251-
ResetLatch(&MyProc->procLatch);
251+
ResetLatch(MyLatch);
252252

253253
if (got_SIGHUP)
254254
{
@@ -336,7 +336,7 @@ BackgroundWriterMain(void)
336336
* down with latch events that are likely to happen frequently during
337337
* normal operation.
338338
*/
339-
rc=WaitLatch(&MyProc->procLatch,
339+
rc=WaitLatch(MyLatch,
340340
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
341341
BgWriterDelay/* ms */ );
342342

@@ -363,7 +363,7 @@ BackgroundWriterMain(void)
363363
/* Ask for notification at next buffer allocation */
364364
StrategyNotifyBgWriter(MyProc->pgprocno);
365365
/* Sleep ... */
366-
rc=WaitLatch(&MyProc->procLatch,
366+
rc=WaitLatch(MyLatch,
367367
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
368368
BgWriterDelay*HIBERNATE_FACTOR);
369369
/* Reset the notification request in case we timed out */
@@ -426,8 +426,7 @@ BgSigHupHandler(SIGNAL_ARGS)
426426
intsave_errno=errno;
427427

428428
got_SIGHUP= true;
429-
if (MyProc)
430-
SetLatch(&MyProc->procLatch);
429+
SetLatch(MyLatch);
431430

432431
errno=save_errno;
433432
}
@@ -439,8 +438,7 @@ ReqShutdownHandler(SIGNAL_ARGS)
439438
intsave_errno=errno;
440439

441440
shutdown_requested= true;
442-
if (MyProc)
443-
SetLatch(&MyProc->procLatch);
441+
SetLatch(MyLatch);
444442

445443
errno=save_errno;
446444
}

‎src/backend/postmaster/checkpointer.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ CheckpointerMain(void)
360360
intrc;
361361

362362
/* Clear any already-pending wakeups */
363-
ResetLatch(&MyProc->procLatch);
363+
ResetLatch(MyLatch);
364364

365365
/*
366366
* Process any requests or signals received recently.
@@ -559,7 +559,7 @@ CheckpointerMain(void)
559559
cur_timeout=Min(cur_timeout,XLogArchiveTimeout-elapsed_secs);
560560
}
561561

562-
rc=WaitLatch(&MyProc->procLatch,
562+
rc=WaitLatch(MyLatch,
563563
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
564564
cur_timeout*1000L/* convert to ms */ );
565565

@@ -832,8 +832,7 @@ ChkptSigHupHandler(SIGNAL_ARGS)
832832
intsave_errno=errno;
833833

834834
got_SIGHUP= true;
835-
if (MyProc)
836-
SetLatch(&MyProc->procLatch);
835+
SetLatch(MyLatch);
837836

838837
errno=save_errno;
839838
}
@@ -845,8 +844,7 @@ ReqCheckpointHandler(SIGNAL_ARGS)
845844
intsave_errno=errno;
846845

847846
checkpoint_requested= true;
848-
if (MyProc)
849-
SetLatch(&MyProc->procLatch);
847+
SetLatch(MyLatch);
850848

851849
errno=save_errno;
852850
}
@@ -869,8 +867,7 @@ ReqShutdownHandler(SIGNAL_ARGS)
869867
intsave_errno=errno;
870868

871869
shutdown_requested= true;
872-
if (MyProc)
873-
SetLatch(&MyProc->procLatch);
870+
SetLatch(MyLatch);
874871

875872
errno=save_errno;
876873
}

‎src/backend/postmaster/pgarch.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,6 @@ static volatile sig_atomic_t got_SIGTERM = false;
7878
staticvolatilesig_atomic_twakened= false;
7979
staticvolatilesig_atomic_tready_to_stop= false;
8080

81-
/*
82-
* Latch used by signal handlers to wake up the sleep in the main loop.
83-
*/
84-
staticLatchmainloop_latch;
85-
8681
/* ----------
8782
* Local function forward declarations
8883
* ----------
@@ -220,10 +215,6 @@ pgarch_forkexec(void)
220215
NON_EXEC_STATICvoid
221216
PgArchiverMain(intargc,char*argv[])
222217
{
223-
InitializeLatchSupport();/* needed for latch waits */
224-
225-
InitLatch(&mainloop_latch);/* initialize latch used in main loop */
226-
227218
/*
228219
* Ignore all signals usually bound to some action in the postmaster,
229220
* except for SIGHUP, SIGTERM, SIGUSR1, SIGUSR2, and SIGQUIT.
@@ -269,7 +260,7 @@ ArchSigHupHandler(SIGNAL_ARGS)
269260

270261
/* set flag to re-read config file at next convenient time */
271262
got_SIGHUP= true;
272-
SetLatch(&mainloop_latch);
263+
SetLatch(MyLatch);
273264

274265
errno=save_errno;
275266
}
@@ -287,7 +278,7 @@ ArchSigTermHandler(SIGNAL_ARGS)
287278
* archive commands.
288279
*/
289280
got_SIGTERM= true;
290-
SetLatch(&mainloop_latch);
281+
SetLatch(MyLatch);
291282

292283
errno=save_errno;
293284
}
@@ -300,7 +291,7 @@ pgarch_waken(SIGNAL_ARGS)
300291

301292
/* set flag that there is work to be done */
302293
wakened= true;
303-
SetLatch(&mainloop_latch);
294+
SetLatch(MyLatch);
304295

305296
errno=save_errno;
306297
}
@@ -313,7 +304,7 @@ pgarch_waken_stop(SIGNAL_ARGS)
313304

314305
/* set flag to do a final cycle and shut down afterwards */
315306
ready_to_stop= true;
316-
SetLatch(&mainloop_latch);
307+
SetLatch(MyLatch);
317308

318309
errno=save_errno;
319310
}
@@ -344,7 +335,7 @@ pgarch_MainLoop(void)
344335
*/
345336
do
346337
{
347-
ResetLatch(&mainloop_latch);
338+
ResetLatch(MyLatch);
348339

349340
/* When we get SIGUSR2, we do one more archive cycle, then exit */
350341
time_to_stop=ready_to_stop;
@@ -397,7 +388,7 @@ pgarch_MainLoop(void)
397388
{
398389
intrc;
399390

400-
rc=WaitLatch(&mainloop_latch,
391+
rc=WaitLatch(MyLatch,
401392
WL_LATCH_SET |WL_TIMEOUT |WL_POSTMASTER_DEATH,
402393
timeout*1000L);
403394
if (rc&WL_TIMEOUT)

‎src/backend/postmaster/pgstat.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ PgStat_MsgBgWriter BgWriterStats;
130130
*/
131131
NON_EXEC_STATICpgsocketpgStatSock=PGINVALID_SOCKET;
132132

133-
staticLatchpgStatLatch;
134-
135133
staticstructsockaddr_storagepgStatAddr;
136134

137135
statictime_tlast_pgstat_start_time;
@@ -3151,15 +3149,10 @@ PgstatCollectorMain(int argc, char *argv[])
31513149
PgStat_Msgmsg;
31523150
intwr;
31533151

3154-
InitializeLatchSupport();/* needed for latch waits */
3155-
3156-
/* Initialize private latch for use by signal handlers */
3157-
InitLatch(&pgStatLatch);
3158-
31593152
/*
31603153
* Ignore all signals usually bound to some action in the postmaster,
31613154
* except SIGHUP and SIGQUIT. Note we don't need a SIGUSR1 handler to
3162-
* support latch operations, becausepgStatLatch is local not shared.
3155+
* support latch operations, becausewe only use a local latch.
31633156
*/
31643157
pqsignal(SIGHUP,pgstat_sighup_handler);
31653158
pqsignal(SIGINT,SIG_IGN);
@@ -3205,7 +3198,7 @@ PgstatCollectorMain(int argc, char *argv[])
32053198
for (;;)
32063199
{
32073200
/* Clear any already-pending wakeups */
3208-
ResetLatch(&pgStatLatch);
3201+
ResetLatch(MyLatch);
32093202

32103203
/*
32113204
* Quit if we get SIGQUIT from the postmaster.
@@ -3363,7 +3356,7 @@ PgstatCollectorMain(int argc, char *argv[])
33633356

33643357
/* Sleep until there's something to do */
33653358
#ifndefWIN32
3366-
wr=WaitLatchOrSocket(&pgStatLatch,
3359+
wr=WaitLatchOrSocket(MyLatch,
33673360
WL_LATCH_SET |WL_POSTMASTER_DEATH |WL_SOCKET_READABLE,
33683361
pgStatSock,
33693362
-1L);
@@ -3379,7 +3372,7 @@ PgstatCollectorMain(int argc, char *argv[])
33793372
* to not provoke "pgstat wait timeout" complaints from
33803373
* backend_read_statsfile.
33813374
*/
3382-
wr=WaitLatchOrSocket(&pgStatLatch,
3375+
wr=WaitLatchOrSocket(MyLatch,
33833376
WL_LATCH_SET |WL_POSTMASTER_DEATH |WL_SOCKET_READABLE |WL_TIMEOUT,
33843377
pgStatSock,
33853378
2*1000L/* msec */ );
@@ -3409,7 +3402,7 @@ pgstat_exit(SIGNAL_ARGS)
34093402
intsave_errno=errno;
34103403

34113404
need_exit= true;
3412-
SetLatch(&pgStatLatch);
3405+
SetLatch(MyLatch);
34133406

34143407
errno=save_errno;
34153408
}
@@ -3421,7 +3414,7 @@ pgstat_sighup_handler(SIGNAL_ARGS)
34213414
intsave_errno=errno;
34223415

34233416
got_SIGHUP= true;
3424-
SetLatch(&pgStatLatch);
3417+
SetLatch(MyLatch);
34253418

34263419
errno=save_errno;
34273420
}

‎src/backend/postmaster/syslogger.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ static FILE *csvlogFile = NULL;
8585
NON_EXEC_STATICpg_time_tfirst_syslogger_file_time=0;
8686
staticchar*last_file_name=NULL;
8787
staticchar*last_csv_file_name=NULL;
88-
staticLatchsysLoggerLatch;
8988

9089
/*
9190
* Buffers for saving partial messages from different backends.
@@ -231,12 +230,6 @@ SysLoggerMain(int argc, char *argv[])
231230
syslogPipe[1]=0;
232231
#endif
233232

234-
InitializeLatchSupport();/* needed for latch waits */
235-
236-
237-
/* Initialize private latch for use by signal handlers */
238-
InitLatch(&sysLoggerLatch);
239-
240233
/*
241234
* Properly accept or ignore signals the postmaster might send us
242235
*
@@ -302,7 +295,7 @@ SysLoggerMain(int argc, char *argv[])
302295
#endif
303296

304297
/* Clear any already-pending wakeups */
305-
ResetLatch(&sysLoggerLatch);
298+
ResetLatch(MyLatch);
306299

307300
/*
308301
* Process any requests or signals received recently.
@@ -428,7 +421,7 @@ SysLoggerMain(int argc, char *argv[])
428421
* Sleep until there's something to do
429422
*/
430423
#ifndefWIN32
431-
rc=WaitLatchOrSocket(&sysLoggerLatch,
424+
rc=WaitLatchOrSocket(MyLatch,
432425
WL_LATCH_SET |WL_SOCKET_READABLE |cur_flags,
433426
syslogPipe[0],
434427
cur_timeout);
@@ -480,7 +473,7 @@ SysLoggerMain(int argc, char *argv[])
480473
*/
481474
LeaveCriticalSection(&sysloggerSection);
482475

483-
(void)WaitLatch(&sysLoggerLatch,
476+
(void)WaitLatch(MyLatch,
484477
WL_LATCH_SET |cur_flags,
485478
cur_timeout);
486479

@@ -1061,7 +1054,7 @@ pipeThread(void *arg)
10611054
{
10621055
if (ftell(syslogFile) >=Log_RotationSize*1024L||
10631056
(csvlogFile!=NULL&&ftell(csvlogFile) >=Log_RotationSize*1024L))
1064-
SetLatch(&sysLoggerLatch);
1057+
SetLatch(MyLatch);
10651058
}
10661059
LeaveCriticalSection(&sysloggerSection);
10671060
}
@@ -1073,7 +1066,7 @@ pipeThread(void *arg)
10731066
flush_pipe_input(logbuffer,&bytes_in_logbuffer);
10741067

10751068
/* set the latch to waken the main thread, which will quit */
1076-
SetLatch(&sysLoggerLatch);
1069+
SetLatch(MyLatch);
10771070

10781071
LeaveCriticalSection(&sysloggerSection);
10791072
_endthread();
@@ -1353,7 +1346,7 @@ sigHupHandler(SIGNAL_ARGS)
13531346
intsave_errno=errno;
13541347

13551348
got_SIGHUP= true;
1356-
SetLatch(&sysLoggerLatch);
1349+
SetLatch(MyLatch);
13571350

13581351
errno=save_errno;
13591352
}
@@ -1365,7 +1358,7 @@ sigUsr1Handler(SIGNAL_ARGS)
13651358
intsave_errno=errno;
13661359

13671360
rotation_requested= true;
1368-
SetLatch(&sysLoggerLatch);
1361+
SetLatch(MyLatch);
13691362

13701363
errno=save_errno;
13711364
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp